/*jshint eqeqeq:false, eqnull:true, devel:true */ /*global jQuery, define */ (function( factory ) { "use strict"; if ( typeof define === "function" && define.amd ) { // AMD. Register as an anonymous module. define([ "jquery", "./grid.base", "./grid.common" ], factory ); } else { // Browser globals factory( jQuery ); } }(function( $ ) { "use strict"; //module begin var rp_ge = {}; $.jgrid.extend({ editGridRow : function(rowid, p){ var regional = $.jgrid.getRegional(this[0], 'edit'), currstyle = this[0].p.styleUI, styles = $.jgrid.styleUI[currstyle].formedit, commonstyle = $.jgrid.styleUI[currstyle].common; p = $.extend(true, { top : 0, left: 0, width: '500', datawidth: 'auto', height: 'auto', dataheight: 'auto', modal: false, overlay : 30, drag: true, resize: true, url: null, mtype : "POST", clearAfterAdd :true, closeAfterEdit : false, reloadAfterSubmit : true, onInitializeForm: null, beforeInitData: null, beforeShowForm: null, afterShowForm: null, beforeSubmit: null, afterSubmit: null, onclickSubmit: null, afterComplete: null, onclickPgButtons : null, afterclickPgButtons: null, editData : {}, recreateForm : false, jqModal : true, closeOnEscape : false, addedrow : "first", topinfo : '', bottominfo: '', saveicon : [], closeicon : [], savekey: [false,13], navkeys: [false,38,40], checkOnSubmit : false, checkOnUpdate : false, processing : false, onClose : null, ajaxEditOptions : {}, serializeEditData : null, viewPagerButtons : true, overlayClass : commonstyle.overlay, removemodal : true, form: 'edit', template : null, focusField : true, editselected : false, html5Check : false, buttons : [] }, regional, p || {}); rp_ge[$(this)[0].p.id] = p; return this.each(function(){ var $t = this; if (!$t.grid || !rowid) {return;} $t.p.savedData = {}; var gID = $t.p.id, frmgr = "FrmGrid_"+gID, frmtborg = "TblGrid_"+gID, frmtb = "#"+$.jgrid.jqID(frmtborg), frmtb2, IDs = {themodal:'editmod'+gID,modalhead:'edithd'+gID,modalcontent:'editcnt'+gID, scrollelm : frmgr}, showFrm = true, maxCols = 1, maxRows=0, postdata, diff, frmoper, templ = typeof rp_ge[$t.p.id].template === "string" && rp_ge[$t.p.id].template.length > 0, errors =$.jgrid.getRegional(this, 'errors'); rp_ge[$t.p.id].styleUI = $t.p.styleUI || 'jQueryUI'; if($.jgrid.isMobile()) { rp_ge[$t.p.id].resize = false; } if (rowid === "new") { rowid = "_empty"; frmoper = "add"; p.caption=rp_ge[$t.p.id].addCaption; } else { p.caption=rp_ge[$t.p.id].editCaption; frmoper = "edit"; } if(!p.recreateForm) { if( $($t).data("formProp") ) { $.extend(rp_ge[$(this)[0].p.id], $($t).data("formProp")); } } var closeovrl = true; if(p.checkOnUpdate && p.jqModal && !p.modal) { closeovrl = false; } function getFormData(){ var a2 ={}, i; $(frmtb).find(".FormElement").each(function() { var celm = $(".customelement", this); if (celm.length) { var elem = celm[0], nm = $(elem).attr('name'); $.each($t.p.colModel, function(){ if(this.name === nm && this.editoptions && $.jgrid.isFunction(this.editoptions.custom_value)) { try { let cvr = this.editoptions.custom_value.call($t, $("#"+$.jgrid.jqID(nm),frmtb),'get'); if( cvr === "#ignoreme#") { } else if (crv === undefined) { throw "e1"; } else { postdata[nm] = cvr; } } catch (e) { if (e==="e1") {$.jgrid.info_dialog(errors.errcap,"function 'custom_value' "+rp_ge[$(this)[0]].p.msg.novalue,rp_ge[$(this)[0]].p.bClose, {styleUI : rp_ge[$(this)[0]].p.styleUI });} else {$.jgrid.info_dialog(errors.errcap,e.message,rp_ge[$(this)[0]].p.bClose, {styleUI : rp_ge[$(this)[0]].p.styleUI });} } return true; } }); } else { switch ($(this).get(0).type) { case "checkbox": if($(this).is(":checked")) { postdata[this.name]= $(this).val(); } else { var ofv = $(this).attr("offval"); postdata[this.name]= ofv; } break; case "select-one": postdata[this.name]= $(this).val(); break; case "select-multiple": postdata[this.name]= $(this).val(); postdata[this.name] = postdata[this.name] ? postdata[this.name].join(",") : ""; break; case "radio" : if(a2.hasOwnProperty(this.name)) { return true; } else { a2[this.name] = ($(this).attr("offval") === undefined) ? "off" : $(this).attr("offval"); } break; default: postdata[this.name] = $(this).val(); } if($t.p.autoencode) { postdata[this.name] = $.jgrid.htmlEncode(postdata[this.name]); } } }); for(i in a2 ) { if( a2.hasOwnProperty(i)) { var val = $('input[name="'+i+'"]:checked',frmtb).val(); postdata[i] = (val !== undefined) ? val : a2[i]; if($t.p.autoencode) { postdata[i] = $.jgrid.htmlEncode(postdata[i]); } } } return true; } function createData(rowid,obj,tb,maxcols){ var nm, hc,trdata, cnt=0,tmp, dc,elc, retpos=[], ind=false, tdtmpl = "", tmpl="", i, ffld; //*2 for (i =1; i<=maxcols;i++) { tmpl += tdtmpl; } if(rowid !== '_empty') { ind = $(obj).jqGrid("getInd",rowid); } $(obj.p.colModel).each( function(i) { nm = this.name; // hidden fields are included in the form if(this.editrules && this.editrules.edithidden === true) { hc = false; } else { hc = this.hidden === true ? true : false; } dc = hc ? "style='display:none'" : ""; if ( nm !== 'cb' && nm !== 'subgrid' && this.editable===true && nm !== 'rn' && nm!=='sc') { if(ind === false) { tmp = ""; } else { if(nm === obj.p.ExpandColumn && obj.p.treeGrid === true) { tmp = $("td[role='gridcell']",obj.rows[ind]).eq( i ).text(); } else { try { tmp = $.unformat.call(obj, $("td[role='gridcell']",obj.rows[ind]).eq( i ),{rowId:rowid, colModel:this},i); } catch (_) { tmp = (this.edittype && this.edittype === "textarea") ? $("td[role='gridcell']",obj.rows[ind]).eq( i ).text() : $("td[role='gridcell']",obj.rows[ind]).eq( i ).html(); } if(!tmp || tmp === " " || tmp === " " || (tmp.length===1 && tmp.charCodeAt(0)===160) ) {tmp='';} } } var opt = $.extend({}, this.editoptions || {} ,{id:nm,name:nm, rowId: rowid, oper:frmoper, module : 'form', checkUpdate : rp_ge[$t.p.id].checkOnSubmit || rp_ge[$t.p.id].checkOnUpdate}), frmopt = $.extend({}, {elmprefix:'',elmsuffix:'',rowabove:false,rowcontent:''}, this.formoptions || {}), rp = parseInt(frmopt.rowpos,10) || cnt+1, cp = parseInt((parseInt(frmopt.colpos,10) || 1)*2,10); if(rowid === "_empty" && opt.defaultValue ) { tmp = $.jgrid.isFunction(opt.defaultValue) ? opt.defaultValue.call($t) : opt.defaultValue; } if(!this.edittype) { this.edittype = "text"; } if($t.p.autoencode) { tmp = $.jgrid.htmlDecode(tmp); } elc = $.jgrid.createEl.call($t,this.edittype,opt,tmp,false,$.extend({},$.jgrid.ajaxOptions,obj.p.ajaxSelectOptions || {})); //if(tmp === "" && this.edittype == "checkbox") {tmp = $(elc).attr("offval");} //if(tmp === "" && this.edittype == "select") {tmp = $("option:eq(0)",elc).text();} if(this.edittype === "select") { tmp = $(elc).val(); if($(elc).get(0).type === 'select-multiple' && tmp) { tmp = tmp.join(","); } } if(this.edittype === 'checkbox') { if($(elc).is(":checked")) { tmp= $(elc).val(); } else { tmp = $(elc).attr("offval"); } } $(elc).addClass("FormElement"); if(this.edittype === 'select') { $(elc).addClass( styles.selectClass ); } else if( $.inArray(this.edittype, ['text','textarea','password', 'color', 'date', 'datetime', 'datetime-local','email','month', 'number','range', 'search', 'tel', 'time', 'url','week'] ) > -1) { $(elc).addClass( styles.inputClass ); } ffld = true; if(templ) { var ftmplfld = $(frm).find("#"+nm); if(ftmplfld.length){ ftmplfld.replaceWith( elc ); } else { ffld = false; } } else { //-------------------- trdata = $(tb).find("tr[rowpos="+rp+"]"); if(frmopt.rowabove) { var newdata = $(""+frmopt.rowcontent+""); $(tb).append(newdata); newdata[0].rp = rp; } if ( trdata.length===0 ) { if(maxcols > 1) { trdata = $("").addClass("FormData").attr("id","tr_"+nm); } else { trdata = $("").addClass("FormData").attr("id","tr_"+nm); } $(trdata).append(tmpl); $(tb).append(trdata); trdata[0].rp = rp; } $("td",trdata[0]).eq( cp-2 ).html(""); $("td",trdata[0]).eq( cp-1 ).append(frmopt.elmprefix).append(elc).append(frmopt.elmsuffix); if( maxcols > 1 && hc) { $("td",trdata[0]).eq( cp-2 ).hide(); $("td",trdata[0]).eq( cp-1 ).hide(); } //------------------------- } if( (rp_ge[$t.p.id].checkOnSubmit || rp_ge[$t.p.id].checkOnUpdate) && ffld) { $t.p.savedData[nm] = tmp; } if(this.edittype==='custom' && $.jgrid.isFunction(opt.custom_value) ) { opt.custom_value.call($t, $("#"+nm, elc),'set',tmp); } $.jgrid.bindEv.call($t, elc, opt); retpos[cnt] = i; cnt++; } }); if( cnt > 0) { var idrow; if(templ) { idrow = "