+++ /dev/null
-;(function($){\r
-/**\r
- * jqGrid extension for manipulating Grid Data\r
- * Tony Tomov tony@trirand.com\r
- * http://trirand.com/blog/ \r
- * Dual licensed under the MIT and GPL licenses:\r
- * http://www.opensource.org/licenses/mit-license.php\r
- * http://www.gnu.org/licenses/gpl.html\r
-**/ \r
-$.fn.extend({\r
-//Editing\r
- editRow : function(rowid,keys,oneditfunc,succesfunc, url, extraparam, aftersavefunc,errorfunc) {\r
- return this.each(function(){\r
- var $t = this, nm, tmp, editable, cnt=0, focus=null, svr=[];\r
- if (!$t.grid ) { return; }\r
- var sz, ml,hc;\r
- if( !$t.p.multiselect ) {\r
- editable = $("#"+rowid,$t.grid.bDiv).attr("editable") || "0";\r
- if (editable == "0") {\r
- $('#'+rowid+' td',$t.grid.bDiv).each( function(i) { \r
- nm = $t.p.colModel[i].name;\r
- hc = $t.p.colModel[i].hidden===true ? true : false;\r
- tmp = $(this).html().replace(/\ \;/ig,'');\r
- svr[nm]=tmp;\r
- if ( nm !== 'cb' && nm !== 'subgrid' && $t.p.colModel[i].editable===true && !hc) {\r
- if(focus===null) { focus = i; }\r
- $(this).html("");\r
- var opt = $.extend($t.p.colModel[i].editoptions || {} ,{id:rowid+"_"+nm,name:nm});\r
- if(!$t.p.colModel[i].edittype) { $t.p.colModel[i].edittype = "text"; }\r
- var elc = createEl($t.p.colModel[i].edittype,opt,tmp,$(this));\r
- $(elc).addClass("editable");\r
- $(this).append(elc);\r
- //Agin IE\r
- if($t.p.colModel[i].edittype == "select" && $t.p.colModel[i].editoptions.multiple===true && $.browser.msie) {\r
- $(elc).width($(elc).width());\r
- }\r
- cnt++;\r
- }\r
- });\r
- if(cnt > 0) {\r
- svr['id'] = rowid; $t.p.savedRow.push(svr);\r
- $('#'+rowid,$t.grid.bDiv).attr("editable","1");\r
- $('#'+rowid+" td:eq("+focus+") input",$t.grid.bDiv).focus();\r
- if(keys===true) {\r
- $('#'+rowid,$t.grid.bDiv).bind("keydown",function(e) {\r
- if (e.keyCode === 27) { $($t).restoreRow(rowid); }\r
- if (e.keyCode === 13) {\r
- $($t).saveRow(rowid,succesfunc, url, extraparam, aftersavefunc,errorfunc);\r
- }\r
- e.stopPropagation();\r
- });\r
- }\r
- if( typeof oneditfunc === "function") { oneditfunc(rowid); }\r
- }\r
- }\r
- }\r
- });\r
- },\r
- saveRow : function(rowid, succesfunc, url, extraparam, aftersavefunc,errorfunc) {\r
- return this.each(function(){\r
- var $t = this, nm, tmp={}, tmp2, editable, fr;\r
- if (!$t.grid ) { return; }\r
- editable = $('#'+rowid,$t.grid.bDiv).attr("editable");\r
- url = url ? url : $t.p.editurl;\r
- if (editable==="1" && url) {\r
- $('#'+rowid+" td",$t.grid.bDiv).each(function(i) {\r
- nm = $t.p.colModel[i].name;\r
- if ( nm !== 'cb' && nm !== 'subgrid' && $t.p.colModel[i].editable===true) {\r
- if( $t.p.colModel[i].hidden===true) { tmp[nm] = $(this).html(); }\r
- else {\r
- switch ($t.p.colModel[i].edittype) {\r
- case "checkbox":\r
- tmp[nm]= $("input",this).attr("checked") ? 1 : 0; \r
- break;\r
- case 'text':\r
- case 'password':\r
- tmp[nm]= $("input",this).val();\r
- break;\r
- case 'textarea':\r
- tmp[nm]= $("textarea",this).val();\r
- break;\r
- case 'select':\r
- if(!$t.p.colModel[i].editoptions.multiple) {\r
- tmp[nm] = $("select>option:selected",this).val();\r
- } else {\r
- var sel = $("select",this);\r
- tmp[nm] = $(sel).val();\r
- }\r
- break;\r
- }\r
- }\r
- }\r
- });\r
- if(tmp) { tmp["id"] = rowid; if(extraparam) { $.extend(tmp,extraparam);} }\r
- if(!$t.grid.hDiv.loading) {\r
- $t.grid.hDiv.loading = true;\r
- $("div.loading",$t.grid.hDiv).fadeIn("fast");\r
- $.ajax({url:url,\r
- data: tmp,\r
- type: "POST",\r
- complete: function(res,stat){\r
- if (stat === "success"){\r
- var ret;\r
- if( typeof succesfunc === "function") { ret = succesfunc(res); }\r
- else ret = true;\r
- if (ret===true) {\r
- $('#'+rowid+" td",$t.grid.bDiv).each(function(i) {\r
- nm = $t.p.colModel[i].name;\r
- if ( nm !== 'cb' && nm !== 'subgrid' && $t.p.colModel[i].editable===true) {\r
- switch ($t.p.colModel[i].edittype) {\r
- case "select":\r
- if(!$t.p.colModel[i].editoptions.multiple) {\r
- tmp2 = $("select>option:selected", this).text();\r
- } else if( $t.p.colModel[i].editoptions.multiple ===true) {\r
- var selectedText = [];\r
- $("select > option:selected",this).each(\r
- function(i,selected){\r
- selectedText[i] = $(selected).text();\r
- }\r
- );\r
- tmp2= selectedText.join(",");\r
- }\r
- break;\r
- case "checkbox":\r
- var cbv = $t.p.colModel[i].editoptions.value.split(":") || ["Yes","No"];\r
- tmp2 = $("input",this).attr("checked") ? cbv[0] : cbv[1];\r
- break;\r
- case "password":\r
- case "text":\r
- case "textarea":\r
- tmp2 = $("input, textarea", this).val();\r
- break;\r
- }\r
- $(this).empty();\r
- $(this).html(tmp2 || " ");\r
- }\r
- });\r
- $('#'+rowid,$t.grid.bDiv).attr("editable","0");\r
- for( var k=0;k<$t.p.savedRow.length;k++) {\r
- if( $t.p.savedRow[k].id===rowid) {fr = k; break;}\r
- };\r
- if(fr >= 0) { $t.p.savedRow.splice(fr,1); }\r
- if( typeof aftersavefunc === "function") { aftersavefunc(rowid,res.responseText); }\r
- } else { $($t).restoreRow(rowid); }\r
- }\r
- },\r
- error:function(res,stat){\r
- if(typeof errorfunc == "function") {\r
- errorfunc(res,stat)\r
- } else {\r
- alert("Error Row: "+rowid+" Result: " +res.status+":"+res.statusText+" Status: "+stat);\r
- }\r
- }\r
- });\r
- $t.grid.hDiv.loading = false;\r
- $("div.loading",$t.grid.hDiv).fadeOut("fast");\r
- $("#"+rowid,$t.grid.bDiv).unbind("keydown");\r
- }\r
- }\r
- });\r
- },\r
- restoreRow : function(rowid) {\r
- return this.each(function(){\r
- var $t= this, nm, fr;\r
- if (!$t.grid ) { return; }\r
- for( var k=0;k<$t.p.savedRow.length;k++) {\r
- if( $t.p.savedRow[k].id===rowid) {fr = k; break;}\r
- };\r
- if(fr >= 0) {\r
- $('#'+rowid+" td",$t.grid.bDiv).each(function(i) {\r
- nm = $t.p.colModel[i].name;\r
- if ( nm !== 'cb' && nm !== 'subgrid') {\r
- $(this).empty();\r
- $(this).html($t.p.savedRow[fr][nm] || " ");\r
- }\r
- });\r
- $('#'+rowid,$t.grid.bDiv).attr("editable","0");\r
- $t.p.savedRow.splice(fr,1);\r
- }\r
- });\r
- }\r
-//end inline edit\r
-});\r
-})(jQuery);\r