12 |
- !function(t){"use strict";"function"==typeof define&&define.amd?define(["jquery","./grid.base","./jquery.fmatter","./grid.common"],t):"object"==typeof module&&module.exports?module.exports=function(e,l){return e||(e=window),void 0===l&&(l="undefined"!=typeof window?require("jquery"):require("jquery")(e)),require("./grid.base"),require("./jquery.fmatter"),require("./grid.common"),t(l),l}:t(jQuery)}(function(D){"use strict";var F=D.jgrid,M=function(){var e=D.makeArray(arguments);return e.unshift(""),e.unshift(""),e.unshift(this.p),F.feedback.apply(this,e)},N=function(e,l){var t=this.grid.fbRows;return null!=(e=null!=t&&t[0].cells.length>l?t[e.rowIndex]:e)&&null!=e.cells?D(e.cells[l]):D()};F.extend({editCell:function(I,R,S){return this.each(function(){var e,l,t,i,r=this,a=D(r),n=r.p,o=r.rows;if(r.grid&&!0===n.cellEdit&&null!=o&&null!=o[I]&&(I=parseInt(I,10),R=parseInt(R,10),!isNaN(I)&&!isNaN(R))){var d,s=o[I],c=null!=s?s.id:null,u=D(s),f=parseInt(n.iCol,10),h=parseInt(n.iRow,10),p=D(o[h]),v=n.savedRow;if(null!=c){if(n.selrow=c,n.knv||a.jqGrid("GridNav"),0<v.length&&0<p.length){if(!0===S&&I===h&&R===f)return;a.jqGrid("saveCell",v[0].id,v[0].ic)}else setTimeout(function(){D("#"+F.jqID(n.knv)).attr("tabindex","-1").focus()},1);if("subgrid"!==(e=(i=n.colModel[R]).name)&&"cb"!==e&&"rn"!==e){t=N.call(r,s,R);var m=i.editable,C="cell";D.isFunction(m)&&(m=m.call(r,{rowid:c,iCol:R,iRow:I,cmName:e,cm:i,mode:C}));var g,b,w,j=a.jqGrid("getGuiStyles","states.select","edit-cell"),q=a.jqGrid("getGuiStyles","states.hover","selected-row");if(!0!==m||!0!==S||t.hasClass("not-editable-cell"))n.noCellSelection||(0<=f&&0<=h&&(N.call(r,p[0],f).removeClass(j),p.removeClass(q)),t.addClass(j),u.addClass(q)),l=t.html().replace(/ /gi,""),M.call(r,"onSelectCell",c,e,l,I,R);else{n.noCellSelection||(0<=f&&0<=h&&(N.call(r,p[0],f).removeClass(j),p.removeClass(q)),t.addClass(j),u.addClass(q)),i.edittype||(i.edittype="text"),d=i.edittype;try{l=D.unformat.call(r,t,{rowId:c,colModel:i},R)}catch(e){l="textarea"===d?t.text():t.html()}if(n.autoEncodeOnEdit&&(l=F.oldDecodePostedData(l)),(" "===l||" "===l||1===l.length&&160===l.charCodeAt(0))&&(l=""),D.isFunction(n.formatCell)){var G=n.formatCell.call(r,c,e,l,I,R);void 0!==G&&(l=G)}M.call(r,"beforeEditCell",c,e,l,I,R),v.push({id:I,ic:R,name:e,v:l}),n.editingInfo[c]={mode:"cellEditing",savedRow:v[v.length-1],editable:{}},n.editingInfo[c].editable[e]=m;var y=D.extend({},i.editoptions||{},{id:I+"_"+e,name:e,rowId:c,mode:C,cm:i,iCol:R}),x=F.createEl.call(r,d,y,l,!0,D.extend({},F.ajaxOptions,n.ajaxSelectOptions||{})),k=t,E=!0===n.treeGrid&&e===n.ExpandColumn;E&&(k=t.children("span.cell-wrapperleaf,span.cell-wrapper")),k.html("").append(x).attr("tabindex","0"),E&&D(x).width(t.width()-t.children("div.tree-wrap").outerWidth()),F.bindEv.call(r,x,y),n.frozenColumns&&R<a.jqGrid("getNumberOfFrozenColumns")&&(g=D(r.rows[s.rowIndex].cells[R]),b=t.height(),w=g.height(),1<=Math.abs(w-b)&&0<b&&(g.height(b),w=g.height(),1<=Math.abs(b-w)&&g.height(b+Math.round(b-w)))),setTimeout(function(){D(x).focus()},0),D("input, select, textarea",t).on("keydown",function(e){if(27===e.keyCode&&(0<D("input.hasDatepicker",t).length?D(".ui-datepicker").is(":hidden")?a.jqGrid("restoreCell",I,R):D("input.hasDatepicker",t).datepicker("hide"):a.jqGrid("restoreCell",I,R)),13===e.keyCode&&!e.shiftKey)return a.jqGrid("saveCell",I,R),!1;if(9===e.keyCode){if(r.grid.hDiv.loading)return!1;e.shiftKey?a.jqGrid("prevCell",I,R):a.jqGrid("nextCell",I,R)}e.stopPropagation()}),M.call(r,"afterEditCell",c,e,l,I,R)}n.iCol=R,n.iRow=I}}}})},saveCell:function(E,I){return this.each(function(){var i=this,r=D(i),a=i.p,t=i.grid,n=F.info_dialog,e=F.jqID;if(t&&!0===a.cellEdit){var l=r.jqGrid("getGridRes","errors"),o=l.errcap,d=r.jqGrid("getGridRes","edit").bClose,s=a.savedRow,c=1<=s.length?0:null;if(null!==c){var u,f=i.rows[E],h=null!=f?f.id:null,p=null!=f?D(f):D(),v=a.colModel[I],m=v.name,C=N.call(i,f,I),g={},b=F.getEditedValue.call(i,C,v,g);if(b!==s[c].v){void 0!==(u=r.triggerHandler("jqGridBeforeSaveCell",[h,m,b,E,I]))&&(b=u),D.isFunction(a.beforeSaveCell)&&void 0!==(u=a.beforeSaveCell.call(i,h,m,b,E,I))&&(b=u);var w=F.checkValues.call(i,b,I,void 0,void 0,{oldValue:s[c].v,newValue:b,cmName:m,rowid:h,iCol:I,iRow:E,cm:v,tr:f,td:C,mode:"cell"}),j=v.formatoptions||{};if(null==w||!0===w||!0===w[0]){var q=r.triggerHandler("jqGridBeforeSubmitCell",[h,m,b,E,I])||{};if(D.isFunction(a.beforeSubmitCell)&&((q=a.beforeSubmitCell.call(i,h,m,b,E,I))||(q={})),0<D("input.hasDatepicker",C).length&&D("input.hasDatepicker",C).datepicker("hide"),"date"===v.formatter&&!0!==j.sendFormatted&&(b=D.unformat.date.call(i,b,v)),"remote"===a.cellsubmit)if(a.cellurl){var G={};G[m]=b;var y=a.prmNames,x=y.id,k=y.oper;G[x]=F.stripPref(a.idPrefix,h),G[k]=y.editoper,G=D.extend(q,G),a.autoEncodeOnEdit&&D.each(G,function(e,l){D.isFunction(l)||(G[e]=F.oldEncodePostedData(l))}),r.jqGrid("progressBar",{method:"show",loadtype:a.loadui,htmlcontent:r.jqGrid("getGridRes","defaults.savetext")||"Saving..."}),t.hDiv.loading=!0,D.ajax(D.extend({url:D.isFunction(a.cellurl)?a.cellurl.call(i,a.cellurl,E,I,h,b,m):a.cellurl,data:F.serializeFeedback.call(i,a.serializeCellData,"jqGridSerializeCellData",G),type:"POST",complete:function(e){if(t.endReq.call(i),(e.status<300||304===e.status)&&(0!==e.status||4!==e.readyState)){var l=r.triggerHandler("jqGridAfterSubmitCell",[i,e,G.id,m,b,E,I])||[!0,""];(!0===l||!0===l[0]&&D.isFunction(a.afterSubmitCell))&&(l=a.afterSubmitCell.call(i,e,G.id,m,b,E,I)),null==l||!0===l||!0===l[0]?(r.jqGrid("setCell",h,I,b,!1,!1,!0),C.addClass("dirty-cell"),p.addClass("edited"),M.call(i,"afterSaveCell",h,m,b,E,I),s.splice(0,1),delete a.editingInfo[h]):(n.call(i,o,l[1],d),r.jqGrid("restoreCell",E,I))}},error:function(e,l,t){r.triggerHandler("jqGridErrorCell",[e,l,t]),D.isFunction(a.errorCell)?a.errorCell.call(i,e,l,t):n.call(i,o,e.status+" : "+e.statusText+"<br/>"+l,d),r.jqGrid("restoreCell",E,I)}},F.ajaxOptions,a.ajaxCellOptions||{}))}else try{n.call(i,o,l.nourl,d),r.jqGrid("restoreCell",E,I)}catch(e){}if("clientArray"===a.cellsubmit){if(r.jqGrid("setCell",h,I,"select"===v.edittype&&"select"!==v.formatter?g.text:b,!1,!1,!0),C.addClass("dirty-cell"),p.addClass("edited"),M.call(i,"afterSaveCell",h,m,b,E,I),a.frozenColumns&&I<r.jqGrid("getNumberOfFrozenColumns"))try{i.rows[f.rowIndex].cells[I].style.height=""}catch(e){}s.splice(0,1),delete a.editingInfo[h]}}else try{setTimeout(function(){var e=F.getRelativeRect.call(i,C);n.call(i,o,b+" "+w[1],d,{top:e.top,left:e.left+D(i).closest(".ui-jqgrid").offset().left})},50),r.jqGrid("restoreCell",E,I)}catch(e){}}else r.jqGrid("restoreCell",E,I)}setTimeout(function(){D("#"+e(a.knv)).attr("tabindex","-1").focus()},0)}})},restoreCell:function(s,c){return this.each(function(){var e,l,t,i=this,r=i.p,a=i.rows[s],n=a.id;if(i.grid&&!0===r.cellEdit){var o=r.savedRow,d=N.call(i,a,c);if(1<=o.length){if(D.isFunction(D.fn.datepicker))try{D("input.hasDatepicker",d).datepicker("hide")}catch(e){}if(l=r.colModel[c],!0===r.treeGrid&&null!=l&&l.name===r.ExpandColumn?d.children("span.cell-wrapperleaf,span.cell-wrapper").empty():d.empty(),d.attr("tabindex","-1"),e=o[0].v,null!=l&&(t=l.formatoptions||{},"date"===l.formatter&&!0!==t.sendFormatted&&(e=D.unformat.date.call(i,e,l)),D(i).jqGrid("setCell",n,c,e,!1,!1,!0),r.frozenColumns&&c<D(i).jqGrid("getNumberOfFrozenColumns")))try{i.rows[a.rowIndex].cells[c].style.height=""}catch(e){}M.call(i,"afterRestoreCell",n,e,s,c),o.splice(0,1),delete r.editingInfo[n]}setTimeout(function(){D("#"+r.knv).attr("tabindex","-1").focus()},0)}})},nextCell:function(d,s){return this.each(function(){var e,l,t,i=this,r=D(i),a=i.p,n=!1,o=i.rows;if(i.grid&&!0===a.cellEdit&&null!=o&&null!=o[d]){for(e=s+1;e<a.colModel.length;e++)if(l=(t=a.colModel[e]).editable,D.isFunction(l)&&(l=l.call(i,{rowid:o[d].id,iCol:e,iRow:d,cmName:t.name,cm:t,mode:"cell"})),!0===l){n=e;break}!1!==n?r.jqGrid("editCell",d,n,!0):0<a.savedRow.length&&r.jqGrid("saveCell",d,s)}})},prevCell:function(d,s){return this.each(function(){var e,l,t,i=this,r=D(i),a=i.p,n=!1,o=i.rows;if(i.grid&&!0===a.cellEdit&&null!=o&&null!=o[d]){for(e=s-1;0<=e;e--)if(l=(t=a.colModel[e]).editable,D.isFunction(l)&&(l=l.call(i,{rowid:o[d].id,iCol:e,iRow:d,cmName:t.name,cm:t,mode:"cell"})),!0===l){n=e;break}!1!==n?r.jqGrid("editCell",d,n,!0):0<a.savedRow.length&&r.jqGrid("saveCell",d,s)}})},GridNav:function(){return this.each(function(){var i,r,h=this,a=D(h),n=h.p,e=h.grid;if(e&&!0===n.cellEdit){var p=e.bDiv;n.knv=n.id+"_kn";var l=D("<div style='position:fixed;top:0px;width:1px;height:1px;' tabindex='0'><div tabindex='-1' style='width:1px;height:1px;' id='"+n.knv+"'></div></div>");D(l).insertBefore(e.cDiv),D("#"+n.knv).focus().keydown(function(e){var l=parseInt(n.iRow,10),t=parseInt(n.iCol,10);switch(r=e.keyCode,"rtl"===n.direction&&(37===r?r=39:39===r&&(r=37)),r){case 38:0<l-1&&(o(l-1,t,"vu"),a.jqGrid("editCell",l-1,t,!1));break;case 40:l+1<=h.rows.length-1&&(o(l+1,t,"vd"),a.jqGrid("editCell",l+1,t,!1));break;case 37:0<=t-1&&(o(l,i=d(t-1,"lft"),"h"),a.jqGrid("editCell",l,i,!1));break;case 39:t+1<=n.colModel.length-1&&(o(l,i=d(t+1,"rgt"),"h"),a.jqGrid("editCell",l,i,!1));break;case 13:0<=t&&0<=l&&a.jqGrid("editCell",l,t,!0);break;default:return!0}return!1})}function o(e,l,t){var i=h.rows[e];if("v"===t.substr(0,1)){var r=p.clientHeight,a=p.scrollTop,n=i.offsetTop+i.clientHeight,o=i.offsetTop;"vd"===t&&a+r<=n&&(p.scrollTop=p.scrollTop+i.clientHeight),"vu"===t&&o<a&&(p.scrollTop=p.scrollTop-i.clientHeight)}if("h"===t){var d=p.clientWidth,s=p.scrollLeft,c=i.cells[l],u=c.offsetLeft+c.clientWidth,f=c.offsetLeft;u>=d+parseInt(s,10)?p.scrollLeft=p.scrollLeft+c.clientWidth:f<s&&(p.scrollLeft=p.scrollLeft-c.clientWidth)}}function d(e,l){var t,i=0,r=n.colModel;if("lft"===l)for(i=e+1,t=e;0<=t;t--)if(!0!==r[t].hidden){i=t;break}if("rgt"===l)for(i=e-1,t=e;t<r.length;t++)if(!0!==r[t].hidden){i=t;break}return i}})},getChangedCells:function(u){var e=[];return u||(u="all"),this.each(function(){var o=this,d=o.p,s=F.htmlDecode,c=o.rows;o.grid&&!0===d.cellEdit&&D(c).each(function(r){var a={};if(D(this).hasClass("edited")){var n=this;D(this.cells).each(function(e){var l=d.colModel[e],t=l.name,i=N.call(o,n,e);if("cb"!==t&&"subgrid"!==t&&"rn"!==t&&("dirty"!==u||i.hasClass("dirty-cell")))try{a[t]=D.unformat.call(o,i[0],{rowId:c[r].id,colModel:l},e)}catch(e){a[t]=s(i.html())}}),a.id=this.id,e.push(a)}})}),e}})});
- //# sourceMappingURL=grid.celledit.js.map
|