/*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
|
$.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,
|
keyevent : "keydown",
|
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,
|
inpclass = $(this).jqGrid('getStyleUI',$t.p.styleUI+".inlinedit",'inputClass', true);
|
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, oper:'edit'});
|
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 inline-edit-cell");
|
if( $.inArray(cm[i].edittype, ['text','textarea','password','select']) > -1) {
|
$(elc).addClass( inpclass );
|
}
|
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( o.keyevent ,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 = {}, $t = this[0];
|
|
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.getRegional($t,'defaults.savetext')
|
}, $.jgrid.inlineEdit, o );
|
// End compatible
|
|
var success = false, nm, tmp={}, tmp2={}, tmp3= {}, editable, fr, cv, ind, nullIfEmpty=false,
|
error = $.trim( $($t).jqGrid('getStyleUI', $t.p.styleUI+'.common', 'error', true) );
|
if (!$t.grid ) { return success; }
|
ind = $($t).jqGrid("getInd",rowid,true);
|
if(ind === false) {return success;}
|
var errors = $.jgrid.getRegional(this, 'errors'),
|
edit =$.jgrid.getRegional(this, 'edit'),
|
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(errors.errcap,"function 'custom_value' "+edit.msg.nodefined,edit.bClose, {styleUI : $t.p.styleUI }); }
|
else { $.jgrid.info_dialog(errors.errcap,e.message,edit.bClose, {styleUI : $t.p.styleUI }); }
|
}
|
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';
|
nullIfEmpty = true;
|
}
|
}
|
}
|
});
|
if (cv[0] === false){
|
try {
|
var tr = $($t).jqGrid('getGridRowById', rowid), positions = $.jgrid.findPos(tr);
|
$.jgrid.info_dialog(errors.errcap,cv[1],edit.bClose,{left:positions[0],top:positions[1]+$(tr).outerHeight(), styleUI : $t.p.styleUI });
|
} 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, tmp3];}
|
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);
|
});
|
}
|
if(nullIfEmpty) {
|
$.each(tmp,function( n ){
|
if(tmp[n] === 'null' ) {
|
tmp[n] = '';
|
}
|
});
|
}
|
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(errors.errcap,'<div class="'+error+'">'+ rT +'</div>', edit.bClose, {buttonalign:'right', styleUI : $t.p.styleUI });
|
} 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) {
|
var $t = this[0],
|
regional = $.jgrid.getRegional($t, 'nav'),
|
icons = $.jgrid.styleUI[$t.p.styleUI].inlinedit;
|
o = $.extend(true,{
|
edit: true,
|
editicon: icons.icon_edit_nav,
|
add: true,
|
addicon:icons.icon_add_nav,
|
save: true,
|
saveicon: icons.icon_save_nav,
|
cancel: true,
|
cancelicon: icons.icon_cancel_nav,
|
addParams : {addRowParams: {extraparam: {}}},
|
editParams : {},
|
restoreAfterSelect : true
|
}, regional, o ||{});
|
return this.each(function(){
|
if (!this.grid || this.p.inlineNav) { return; }
|
var gID = $.jgrid.jqID($t.p.id),
|
disabled = $.trim( $($t).jqGrid('getStyleUI', $t.p.styleUI+'.common', 'disabled', true) );
|
// check to see if navgrid is started, if not call it with all false parameters.
|
if(!$t.p.navGrid) {
|
$($t).jqGrid('navGrid',elem, {refresh:false, edit: false, add: false, del: false, search: false, view: false});
|
}
|
if(!$($t).data('inlineNav')) {
|
$($t).data('inlineNav',o);
|
}
|
if($t.p.force_regional) {
|
o = $.extend(o, regional);
|
}
|
|
$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",
|
internal : true,
|
onClickButton : function () {
|
$($t).jqGrid('addRow', o.addParams);
|
if(!o.addParams.useFormatter) {
|
$("#"+gID+"_ilsave").removeClass( disabled );
|
$("#"+gID+"_ilcancel").removeClass( disabled );
|
$("#"+gID+"_iladd").addClass( disabled );
|
$("#"+gID+"_iledit").addClass( disabled );
|
}
|
}
|
});
|
}
|
if(o.edit) {
|
$($t).jqGrid('navButtonAdd', elem,{
|
caption : o.edittext,
|
title : o.edittitle,
|
buttonicon : o.editicon,
|
id : $t.p.id+"_iledit",
|
internal : true,
|
onClickButton : function () {
|
var sr = $($t).jqGrid('getGridParam','selrow');
|
if(sr) {
|
$($t).jqGrid('editRow', sr, o.editParams);
|
$("#"+gID+"_ilsave").removeClass( disabled );
|
$("#"+gID+"_ilcancel").removeClass( disabled );
|
$("#"+gID+"_iladd").addClass( disabled );
|
$("#"+gID+"_iledit").addClass( disabled );
|
} else {
|
$.jgrid.viewModal("#alertmod_"+gID, {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",
|
internal : true,
|
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_"+gID, {gbox:"#gbox_"+gID,jqm:true});$("#jqg_alrt").focus();
|
}
|
}
|
});
|
$("#"+gID+"_ilsave").addClass( 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",
|
internal : true,
|
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( disabled );
|
}
|
if(o.restoreAfterSelect === true) {
|
$($t).bind("jqGridBeforeSelectRow.inlineNav", function( event, id ) {
|
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');
|
}
|
});
|
}
|
|
});
|
},
|
showAddEditButtons : function() {
|
return this.each(function(){
|
if (!this.grid ) { return; }
|
var gID = $.jgrid.jqID(this.p.id),
|
disabled = $.trim( $(this).jqGrid('getStyleUI', this.p.styleUI+'.common', 'disabled', true) );
|
$("#"+gID+"_ilsave").addClass( disabled );
|
$("#"+gID+"_ilcancel").addClass( disabled );
|
$("#"+gID+"_iladd").removeClass( disabled );
|
$("#"+gID+"_iledit").removeClass( disabled );
|
});
|
}
|
//end inline edit
|
});
|
//module end
|
}));
|