123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652 |
- /*jshint eqeqeq:false, eqnull:true, devel:true */
- /*global jQuery */
- (function($){
- /**
- * jqGrid extension for manipulating Grid Data
- * Tony Tomov tony@trirand.com
- * http://trirand.com/blog/
- * Dual licensed under the MIT and GPL licenses:
- * http://www.opensource.org/licenses/mit-license.php
- * http://www.gnu.org/licenses/gpl-2.0.html
- **/
- "use strict";
- $.jgrid.inlineEdit = $.jgrid.inlineEdit || {};
- $.jgrid.extend({
- //Editing
- editRow : function(rowid,keys,oneditfunc,successfunc, url, extraparam, aftersavefunc,errorfunc, afterrestorefunc) {
- // Compatible mode old versions
- var o={}, args = $.makeArray(arguments).slice(1);
- if( $.type(args[0]) === "object" ) {
- o = args[0];
- } else {
- if (keys !== undefined) { o.keys = keys; }
- if ($.isFunction(oneditfunc)) { o.oneditfunc = oneditfunc; }
- if ($.isFunction(successfunc)) { o.successfunc = successfunc; }
- if (url !== undefined) { o.url = url; }
- if (extraparam !== undefined) { o.extraparam = extraparam; }
- if ($.isFunction(aftersavefunc)) { o.aftersavefunc = aftersavefunc; }
- if ($.isFunction(errorfunc)) { o.errorfunc = errorfunc; }
- if ($.isFunction(afterrestorefunc)) { o.afterrestorefunc = afterrestorefunc; }
- // last two not as param, but as object (sorry)
- //if (restoreAfterError !== undefined) { o.restoreAfterError = restoreAfterError; }
- //if (mtype !== undefined) { o.mtype = mtype || "POST"; }
- }
- o = $.extend(true, {
- keys : false,
- oneditfunc: null,
- successfunc: null,
- url: null,
- extraparam: {},
- aftersavefunc: null,
- errorfunc: null,
- afterrestorefunc: null,
- restoreAfterError: true,
- mtype: "POST",
- focusField : true
- }, $.jgrid.inlineEdit, o );
- // End compatible
- return this.each(function(){
- var $t = this, nm, tmp, editable, cnt=0, focus=null, svr={}, ind,cm, bfer;
- if (!$t.grid ) { return; }
- ind = $($t).jqGrid("getInd",rowid,true);
- if( ind === false ) {return;}
- bfer = $.isFunction( o.beforeEditRow ) ? o.beforeEditRow.call($t,o, rowid) : undefined;
- if( bfer === undefined ) {
- bfer = true;
- }
- if(!bfer) { return; }
- editable = $(ind).attr("editable") || "0";
- if (editable === "0" && !$(ind).hasClass("not-editable-row")) {
- cm = $t.p.colModel;
- $('td[role="gridcell"]',ind).each( function(i) {
- nm = cm[i].name;
- var treeg = $t.p.treeGrid===true && nm === $t.p.ExpandColumn;
- if(treeg) { tmp = $("span:first",this).html();}
- else {
- try {
- tmp = $.unformat.call($t,this,{rowId:rowid, colModel:cm[i]},i);
- } catch (_) {
- tmp = ( cm[i].edittype && cm[i].edittype === 'textarea' ) ? $(this).text() : $(this).html();
- }
- }
- if ( nm !== 'cb' && nm !== 'subgrid' && nm !== 'rn') {
- if($t.p.autoencode) { tmp = $.jgrid.htmlDecode(tmp); }
- svr[nm]=tmp;
- if(cm[i].editable===true) {
- if(focus===null) { focus = i; }
- if (treeg) { $("span:first",this).html(""); }
- else { $(this).html(""); }
- var opt = $.extend({},cm[i].editoptions || {},{id:rowid+"_"+nm,name:nm,rowId:rowid});
- if(!cm[i].edittype) { cm[i].edittype = "text"; }
- if(tmp === " " || tmp === " " || (tmp.length===1 && tmp.charCodeAt(0)===160) ) {tmp='';}
- var elc = $.jgrid.createEl.call($t,cm[i].edittype,opt,tmp,true,$.extend({},$.jgrid.ajaxOptions,$t.p.ajaxSelectOptions || {}));
- $(elc).addClass("editable");
- if(treeg) { $("span:first",this).append(elc); }
- else { $(this).append(elc); }
- $.jgrid.bindEv.call($t, elc, opt);
- //Again IE
- if(cm[i].edittype === "select" && cm[i].editoptions!==undefined && cm[i].editoptions.multiple===true && cm[i].editoptions.dataUrl===undefined && $.jgrid.msie) {
- $(elc).width($(elc).width());
- }
- cnt++;
- }
- }
- });
- if(cnt > 0) {
- svr.id = rowid; $t.p.savedRow.push(svr);
- $(ind).attr("editable","1");
- if(o.focusField ) {
- if(typeof o.focusField === 'number' && parseInt(o.focusField,10) <= cm.length) {
- focus = o.focusField;
- }
- setTimeout(function(){
- var fe = $("td:eq("+focus+") :input:visible",ind).not(":disabled");
- if(fe.length > 0) {
- fe.focus();
- }
- },0);
- }
- if(o.keys===true) {
- $(ind).bind("keydown",function(e) {
- if (e.keyCode === 27) {
- $($t).jqGrid("restoreRow",rowid, o.afterrestorefunc);
- if($t.p._inlinenav) {
- try {
- $($t).jqGrid('showAddEditButtons');
- } catch (eer1) {}
- }
- return false;
- }
- if (e.keyCode === 13) {
- var ta = e.target;
- if(ta.tagName === 'TEXTAREA') { return true; }
- if( $($t).jqGrid("saveRow", rowid, o ) ) {
- if($t.p._inlinenav) {
- try {
- $($t).jqGrid('showAddEditButtons');
- } catch (eer2) {}
- }
- }
- return false;
- }
- });
- }
- $($t).triggerHandler("jqGridInlineEditRow", [rowid, o]);
- if( $.isFunction(o.oneditfunc)) { o.oneditfunc.call($t, rowid); }
- }
- }
- });
- },
- saveRow : function(rowid, successfunc, url, extraparam, aftersavefunc,errorfunc, afterrestorefunc) {
- // Compatible mode old versions
- var args = $.makeArray(arguments).slice(1), o = {};
- if( $.type(args[0]) === "object" ) {
- o = args[0];
- } else {
- if ($.isFunction(successfunc)) { o.successfunc = successfunc; }
- if (url !== undefined) { o.url = url; }
- if (extraparam !== undefined) { o.extraparam = extraparam; }
- if ($.isFunction(aftersavefunc)) { o.aftersavefunc = aftersavefunc; }
- if ($.isFunction(errorfunc)) { o.errorfunc = errorfunc; }
- if ($.isFunction(afterrestorefunc)) { o.afterrestorefunc = afterrestorefunc; }
- }
- o = $.extend(true, {
- successfunc: null,
- url: null,
- extraparam: {},
- aftersavefunc: null,
- errorfunc: null,
- afterrestorefunc: null,
- restoreAfterError: true,
- mtype: "POST",
- saveui : "enable",
- savetext : $.jgrid.defaults.savetext || "Saving..."
- }, $.jgrid.inlineEdit, o );
- // End compatible
- var success = false;
- var $t = this[0], nm, tmp={}, tmp2={}, tmp3= {}, editable, fr, cv, ind;
- if (!$t.grid ) { return success; }
- ind = $($t).jqGrid("getInd",rowid,true);
- if(ind === false) {return success;}
- var bfsr = $.isFunction( o.beforeSaveRow ) ? o.beforeSaveRow.call($t,o, rowid) : undefined;
- if( bfsr === undefined ) {
- bfsr = true;
- }
- if(!bfsr) { return; }
- editable = $(ind).attr("editable");
- o.url = o.url || $t.p.editurl;
- if (editable==="1") {
- var cm;
- $('td[role="gridcell"]',ind).each(function(i) {
- cm = $t.p.colModel[i];
- nm = cm.name;
- if ( nm !== 'cb' && nm !== 'subgrid' && cm.editable===true && nm !== 'rn' && !$(this).hasClass('not-editable-cell')) {
- switch (cm.edittype) {
- case "checkbox":
- var cbv = ["Yes","No"];
- if(cm.editoptions ) {
- cbv = cm.editoptions.value.split(":");
- }
- tmp[nm]= $("input",this).is(":checked") ? cbv[0] : cbv[1];
- break;
- case 'text':
- case 'password':
- case 'textarea':
- case "button" :
- tmp[nm]=$("input, textarea",this).val();
- break;
- case 'select':
- if(!cm.editoptions.multiple) {
- tmp[nm] = $("select option:selected",this).val();
- tmp2[nm] = $("select option:selected", this).text();
- } else {
- var sel = $("select",this), selectedText = [];
- tmp[nm] = $(sel).val();
- if(tmp[nm]) { tmp[nm]= tmp[nm].join(","); } else { tmp[nm] =""; }
- $("select option:selected",this).each(
- function(i,selected){
- selectedText[i] = $(selected).text();
- }
- );
- tmp2[nm] = selectedText.join(",");
- }
- if(cm.formatter && cm.formatter === 'select') { tmp2={}; }
- break;
- case 'custom' :
- try {
- if(cm.editoptions && $.isFunction(cm.editoptions.custom_value)) {
- tmp[nm] = cm.editoptions.custom_value.call($t, $(".customelement",this),'get');
- if (tmp[nm] === undefined) { throw "e2"; }
- } else { throw "e1"; }
- } catch (e) {
- if (e==="e1") { $.jgrid.info_dialog($.jgrid.errors.errcap,"function 'custom_value' "+$.jgrid.edit.msg.nodefined,$.jgrid.edit.bClose); }
- if (e==="e2") { $.jgrid.info_dialog($.jgrid.errors.errcap,"function 'custom_value' "+$.jgrid.edit.msg.novalue,$.jgrid.edit.bClose); }
- else { $.jgrid.info_dialog($.jgrid.errors.errcap,e.message,$.jgrid.edit.bClose); }
- }
- break;
- }
- cv = $.jgrid.checkValues.call($t,tmp[nm],i);
- if(cv[0] === false) {
- return false;
- }
- if($t.p.autoencode) { tmp[nm] = $.jgrid.htmlEncode(tmp[nm]); }
- if(o.url !== 'clientArray' && cm.editoptions && cm.editoptions.NullIfEmpty === true) {
- if(tmp[nm] === "") {
- tmp3[nm] = 'null';
- }
- }
- }
- });
- if (cv[0] === false){
- try {
- var tr = $($t).jqGrid('getGridRowById', rowid), positions = $.jgrid.findPos(tr);
- $.jgrid.info_dialog($.jgrid.errors.errcap,cv[1],$.jgrid.edit.bClose,{left:positions[0],top:positions[1]+$(tr).outerHeight()});
- } catch (e) {
- alert(cv[1]);
- }
- return success;
- }
- var idname, opers = $t.p.prmNames, oldRowId = rowid;
- if ($t.p.keyName === false) {
- idname = opers.id;
- } else {
- idname = $t.p.keyName;
- }
- if(tmp) {
- tmp[opers.oper] = opers.editoper;
- if (tmp[idname] === undefined || tmp[idname]==="") {
- tmp[idname] = rowid;
- } else if (ind.id !== $t.p.idPrefix + tmp[idname]) {
- // rename rowid
- var oldid = $.jgrid.stripPref($t.p.idPrefix, rowid);
- if ($t.p._index[oldid] !== undefined) {
- $t.p._index[tmp[idname]] = $t.p._index[oldid];
- delete $t.p._index[oldid];
- }
- rowid = $t.p.idPrefix + tmp[idname];
- $(ind).attr("id", rowid);
- if ($t.p.selrow === oldRowId) {
- $t.p.selrow = rowid;
- }
- if ($.isArray($t.p.selarrrow)) {
- var i = $.inArray(oldRowId, $t.p.selarrrow);
- if (i>=0) {
- $t.p.selarrrow[i] = rowid;
- }
- }
- if ($t.p.multiselect) {
- var newCboxId = "jqg_" + $t.p.id + "_" + rowid;
- $("input.cbox",ind)
- .attr("id", newCboxId)
- .attr("name", newCboxId);
- }
- // TODO: to test the case of frozen columns
- }
- if($t.p.inlineData === undefined) { $t.p.inlineData ={}; }
- tmp = $.extend({},tmp,$t.p.inlineData,o.extraparam);
- }
- if (o.url === 'clientArray') {
- tmp = $.extend({},tmp, tmp2);
- if($t.p.autoencode) {
- $.each(tmp,function(n,v){
- tmp[n] = $.jgrid.htmlDecode(v);
- });
- }
- var k, resp = $($t).jqGrid("setRowData",rowid,tmp);
- $(ind).attr("editable","0");
- for(k=0;k<$t.p.savedRow.length;k++) {
- if( String($t.p.savedRow[k].id) === String(oldRowId)) {fr = k; break;}
- }
- if(fr >= 0) { $t.p.savedRow.splice(fr,1); }
- $($t).triggerHandler("jqGridInlineAfterSaveRow", [rowid, resp, tmp, o]);
- if( $.isFunction(o.aftersavefunc) ) { o.aftersavefunc.call($t, rowid, resp, tmp, o); }
- success = true;
- $(ind).removeClass("jqgrid-new-row").unbind("keydown");
- } else {
- $($t).jqGrid("progressBar", {method:"show", loadtype : o.saveui, htmlcontent: o.savetext });
- tmp3 = $.extend({},tmp,tmp3);
- tmp3[idname] = $.jgrid.stripPref($t.p.idPrefix, tmp3[idname]);
- $.ajax($.extend({
- url:o.url,
- data: $.isFunction($t.p.serializeRowData) ? $t.p.serializeRowData.call($t, tmp3) : tmp3,
- type: o.mtype,
- async : false, //?!?
- complete: function(res,stat){
- $($t).jqGrid("progressBar", {method:"hide", loadtype : o.saveui, htmlcontent: o.savetext});
- if (stat === "success"){
- var ret = true, sucret, k;
- sucret = $($t).triggerHandler("jqGridInlineSuccessSaveRow", [res, rowid, o]);
- if (!$.isArray(sucret)) {sucret = [true, tmp];}
- if (sucret[0] && $.isFunction(o.successfunc)) {sucret = o.successfunc.call($t, res);}
- if($.isArray(sucret)) {
- // expect array - status, data, rowid
- ret = sucret[0];
- tmp = sucret[1] || tmp;
- } else {
- ret = sucret;
- }
- if (ret===true) {
- if($t.p.autoencode) {
- $.each(tmp,function(n,v){
- tmp[n] = $.jgrid.htmlDecode(v);
- });
- }
- tmp = $.extend({},tmp, tmp2);
- $($t).jqGrid("setRowData",rowid,tmp);
- $(ind).attr("editable","0");
- for(k=0;k<$t.p.savedRow.length;k++) {
- if( String($t.p.savedRow[k].id) === String(rowid)) {fr = k; break;}
- }
- if(fr >= 0) { $t.p.savedRow.splice(fr,1); }
- $($t).triggerHandler("jqGridInlineAfterSaveRow", [rowid, res, tmp, o]);
- if( $.isFunction(o.aftersavefunc) ) { o.aftersavefunc.call($t, rowid, res, tmp, o); }
- success = true;
- $(ind).removeClass("jqgrid-new-row").unbind("keydown");
- } else {
- $($t).triggerHandler("jqGridInlineErrorSaveRow", [rowid, res, stat, null, o]);
- if($.isFunction(o.errorfunc) ) {
- o.errorfunc.call($t, rowid, res, stat, null);
- }
- if(o.restoreAfterError === true) {
- $($t).jqGrid("restoreRow",rowid, o.afterrestorefunc);
- }
- }
- }
- },
- error:function(res,stat,err){
- $("#lui_"+$.jgrid.jqID($t.p.id)).hide();
- $($t).triggerHandler("jqGridInlineErrorSaveRow", [rowid, res, stat, err, o]);
- if($.isFunction(o.errorfunc) ) {
- o.errorfunc.call($t, rowid, res, stat, err);
- } else {
- var rT = res.responseText || res.statusText;
- try {
- $.jgrid.info_dialog($.jgrid.errors.errcap,'<div class="ui-state-error">'+ rT +'</div>', $.jgrid.edit.bClose,{buttonalign:'right'});
- } catch(e) {
- alert(rT);
- }
- }
- if(o.restoreAfterError === true) {
- $($t).jqGrid("restoreRow",rowid, o.afterrestorefunc);
- }
- }
- }, $.jgrid.ajaxOptions, $t.p.ajaxRowOptions || {}));
- }
- }
- return success;
- },
- restoreRow : function(rowid, afterrestorefunc) {
- // Compatible mode old versions
- var args = $.makeArray(arguments).slice(1), o={};
- if( $.type(args[0]) === "object" ) {
- o = args[0];
- } else {
- if ($.isFunction(afterrestorefunc)) { o.afterrestorefunc = afterrestorefunc; }
- }
- o = $.extend(true, {}, $.jgrid.inlineEdit, o );
- // End compatible
- return this.each(function(){
- var $t= this, fr=-1, ind, ares={}, k;
- if (!$t.grid ) { return; }
- ind = $($t).jqGrid("getInd",rowid,true);
- if(ind === false) {return;}
- var bfcr = $.isFunction( o.beforeCancelRow ) ? o.beforeCancelRow.call($t, o, rowid) : undefined;
- if( bfcr === undefined ) {
- bfcr = true;
- }
- if(!bfcr) { return; }
- for(k=0;k<$t.p.savedRow.length;k++) {
- if( String($t.p.savedRow[k].id) === String(rowid)) {fr = k; break;}
- }
- if(fr >= 0) {
- if($.isFunction($.fn.datepicker)) {
- try {
- $("input.hasDatepicker","#"+$.jgrid.jqID(ind.id)).datepicker('hide');
- } catch (e) {}
- }
- $.each($t.p.colModel, function(){
- if(this.editable === true && $t.p.savedRow[fr].hasOwnProperty(this.name)) {
- ares[this.name] = $t.p.savedRow[fr][this.name];
- }
- });
- $($t).jqGrid("setRowData",rowid,ares);
- $(ind).attr("editable","0").unbind("keydown");
- $t.p.savedRow.splice(fr,1);
- if($("#"+$.jgrid.jqID(rowid), "#"+$.jgrid.jqID($t.p.id)).hasClass("jqgrid-new-row")){
- setTimeout(function(){
- $($t).jqGrid("delRowData",rowid);
- $($t).jqGrid('showAddEditButtons');
- },0);
- }
- }
- $($t).triggerHandler("jqGridInlineAfterRestoreRow", [rowid]);
- if ($.isFunction(o.afterrestorefunc))
- {
- o.afterrestorefunc.call($t, rowid);
- }
- });
- },
- addRow : function ( p ) {
- p = $.extend(true, {
- rowID : null,
- initdata : {},
- position :"first",
- useDefValues : true,
- useFormatter : false,
- addRowParams : {extraparam:{}}
- },p || {});
- return this.each(function(){
- if (!this.grid ) { return; }
- var $t = this;
- var bfar = $.isFunction( p.beforeAddRow ) ? p.beforeAddRow.call($t,p.addRowParams) : undefined;
- if( bfar === undefined ) {
- bfar = true;
- }
- if(!bfar) { return; }
- p.rowID = $.isFunction(p.rowID) ? p.rowID.call($t, p) : ( (p.rowID != null) ? p.rowID : $.jgrid.randId());
- if(p.useDefValues === true) {
- $($t.p.colModel).each(function(){
- if( this.editoptions && this.editoptions.defaultValue ) {
- var opt = this.editoptions.defaultValue,
- tmp = $.isFunction(opt) ? opt.call($t) : opt;
- p.initdata[this.name] = tmp;
- }
- });
- }
- $($t).jqGrid('addRowData', p.rowID, p.initdata, p.position);
- p.rowID = $t.p.idPrefix + p.rowID;
- $("#"+$.jgrid.jqID(p.rowID), "#"+$.jgrid.jqID($t.p.id)).addClass("jqgrid-new-row");
- if(p.useFormatter) {
- $("#"+$.jgrid.jqID(p.rowID)+" .ui-inline-edit", "#"+$.jgrid.jqID($t.p.id)).click();
- } else {
- var opers = $t.p.prmNames,
- oper = opers.oper;
- p.addRowParams.extraparam[oper] = opers.addoper;
- $($t).jqGrid('editRow', p.rowID, p.addRowParams);
- $($t).jqGrid('setSelection', p.rowID);
- }
- });
- },
- inlineNav : function (elem, o) {
- o = $.extend(true,{
- edit: true,
- editicon: "ui-icon-pencil",
- add: true,
- addicon:"ui-icon-plus",
- save: true,
- saveicon:"ui-icon-disk",
- cancel: true,
- cancelicon:"ui-icon-cancel",
- addParams : {addRowParams: {extraparam: {}}},
- editParams : {},
- restoreAfterSelect : true
- }, $.jgrid.nav, o ||{});
- return this.each(function(){
- if (!this.grid ) { return; }
- var $t = this, onSelect, gID = $.jgrid.jqID($t.p.id);
- $t.p._inlinenav = true;
- // detect the formatactions column
- if(o.addParams.useFormatter === true) {
- var cm = $t.p.colModel,i;
- for (i = 0; i<cm.length; i++) {
- if(cm[i].formatter && cm[i].formatter === "actions" ) {
- if(cm[i].formatoptions) {
- var defaults = {
- keys:false,
- onEdit : null,
- onSuccess: null,
- afterSave:null,
- onError: null,
- afterRestore: null,
- extraparam: {},
- url: null
- },
- ap = $.extend( defaults, cm[i].formatoptions );
- o.addParams.addRowParams = {
- "keys" : ap.keys,
- "oneditfunc" : ap.onEdit,
- "successfunc" : ap.onSuccess,
- "url" : ap.url,
- "extraparam" : ap.extraparam,
- "aftersavefunc" : ap.afterSave,
- "errorfunc": ap.onError,
- "afterrestorefunc" : ap.afterRestore
- };
- }
- break;
- }
- }
- }
- if(o.add) {
- $($t).jqGrid('navButtonAdd', elem,{
- caption : o.addtext,
- title : o.addtitle,
- buttonicon : o.addicon,
- id : $t.p.id+"_iladd",
- onClickButton : function () {
- $($t).jqGrid('addRow', o.addParams);
- if(!o.addParams.useFormatter) {
- $("#"+gID+"_ilsave").removeClass('ui-state-disabled');
- $("#"+gID+"_ilcancel").removeClass('ui-state-disabled');
- $("#"+gID+"_iladd").addClass('ui-state-disabled');
- $("#"+gID+"_iledit").addClass('ui-state-disabled');
- }
- }
- });
- }
- if(o.edit) {
- $($t).jqGrid('navButtonAdd', elem,{
- caption : o.edittext,
- title : o.edittitle,
- buttonicon : o.editicon,
- id : $t.p.id+"_iledit",
- onClickButton : function () {
- var sr = $($t).jqGrid('getGridParam','selrow');
- if(sr) {
- $($t).jqGrid('editRow', sr, o.editParams);
- $("#"+gID+"_ilsave").removeClass('ui-state-disabled');
- $("#"+gID+"_ilcancel").removeClass('ui-state-disabled');
- $("#"+gID+"_iladd").addClass('ui-state-disabled');
- $("#"+gID+"_iledit").addClass('ui-state-disabled');
- } else {
- $.jgrid.viewModal("#alertmod",{gbox:"#gbox_"+gID,jqm:true});$("#jqg_alrt").focus();
- }
- }
- });
- }
- if(o.save) {
- $($t).jqGrid('navButtonAdd', elem,{
- caption : o.savetext || '',
- title : o.savetitle || 'Save row',
- buttonicon : o.saveicon,
- id : $t.p.id+"_ilsave",
- onClickButton : function () {
- var sr = $t.p.savedRow[0].id;
- if(sr) {
- var opers = $t.p.prmNames,
- oper = opers.oper, tmpParams = o.editParams;
- if($("#"+$.jgrid.jqID(sr), "#"+gID ).hasClass("jqgrid-new-row")) {
- o.addParams.addRowParams.extraparam[oper] = opers.addoper;
- tmpParams = o.addParams.addRowParams;
- } else {
- if(!o.editParams.extraparam) {
- o.editParams.extraparam = {};
- }
- o.editParams.extraparam[oper] = opers.editoper;
- }
- if( $($t).jqGrid('saveRow', sr, tmpParams) ) {
- $($t).jqGrid('showAddEditButtons');
- }
- } else {
- $.jgrid.viewModal("#alertmod",{gbox:"#gbox_"+gID,jqm:true});$("#jqg_alrt").focus();
- }
- }
- });
- $("#"+gID+"_ilsave").addClass('ui-state-disabled');
- }
- if(o.cancel) {
- $($t).jqGrid('navButtonAdd', elem,{
- caption : o.canceltext || '',
- title : o.canceltitle || 'Cancel row editing',
- buttonicon : o.cancelicon,
- id : $t.p.id+"_ilcancel",
- onClickButton : function () {
- var sr = $t.p.savedRow[0].id, cancelPrm = o.editParams;
- if(sr) {
- if($("#"+$.jgrid.jqID(sr), "#"+gID ).hasClass("jqgrid-new-row")) {
- cancelPrm = o.addParams.addRowParams;
- }
- $($t).jqGrid('restoreRow', sr, cancelPrm);
- $($t).jqGrid('showAddEditButtons');
- } else {
- $.jgrid.viewModal("#alertmod",{gbox:"#gbox_"+gID,jqm:true});$("#jqg_alrt").focus();
- }
- }
- });
- $("#"+gID+"_ilcancel").addClass('ui-state-disabled');
- }
- if(o.restoreAfterSelect === true) {
- if($.isFunction($t.p.beforeSelectRow)) {
- onSelect = $t.p.beforeSelectRow;
- } else {
- onSelect = false;
- }
- $t.p.beforeSelectRow = function(id, stat) {
- var ret = true;
- if($t.p.savedRow.length > 0 && $t.p._inlinenav===true && ( id !== $t.p.selrow && $t.p.selrow !==null) ) {
- if($t.p.selrow === o.addParams.rowID ) {
- $($t).jqGrid('delRowData', $t.p.selrow);
- } else {
- $($t).jqGrid('restoreRow', $t.p.selrow, o.editParams);
- }
- $($t).jqGrid('showAddEditButtons');
- }
- if(onSelect) {
- ret = onSelect.call($t, id, stat);
- }
- return ret;
- };
- }
- });
- },
- showAddEditButtons : function() {
- return this.each(function(){
- if (!this.grid ) { return; }
- var gID = $.jgrid.jqID(this.p.id);
- $("#"+gID+"_ilsave").addClass('ui-state-disabled');
- $("#"+gID+"_ilcancel").addClass('ui-state-disabled');
- $("#"+gID+"_iladd").removeClass('ui-state-disabled');
- $("#"+gID+"_iledit").removeClass('ui-state-disabled');
- });
- }
- //end inline edit
- });
- })(jQuery);
|