// ==ClosureCompiler== // @compilation_level SIMPLE_OPTIMIZATIONS /** * @license jqGrid 4.3.2 - jQuery Grid * Copyright (c) 2008, Tony Tomov, tony@trirand.com * 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 * Date: 2011-04-10 */ //jsHint options /*global document, window, jQuery, DOMParser, ActiveXObject, $, alert */ (function ($) { "use strict"; $.jgrid = $.jgrid || {}; $.extend($.jgrid,{ version : "4.3.3", htmlDecode : function(value){ if(value && (value==' ' || value==' ' || (value.length===1 && value.charCodeAt(0)===160))) { return "";} return !value ? value : String(value).replace(/>/g, ">").replace(/</g, "<").replace(/"/g, '"').replace(/&/g, "&"); }, htmlEncode : function (value){ return !value ? value : String(value).replace(/&/g, "&").replace(/\"/g, """).replace(//g, ">"); }, format : function(format){ //jqgformat var args = $.makeArray(arguments).slice(1); if(format===undefined) { format = ""; } return format.replace(/\{(\d+)\}/g, function(m, i){ return args[i]; }); }, getCellIndex : function (cell) { var c = $(cell); if (c.is('tr')) { return -1; } c = (!c.is('td') && !c.is('th') ? c.closest("td,th") : c)[0]; if ($.browser.msie) { return $.inArray(c, c.parentNode.cells); } return c.cellIndex; }, stripHtml : function(v) { v = v+""; var regexp = /<("[^"]*"|'[^']*'|[^'">])*>/gi; if (v) { v = v.replace(regexp,""); return (v && v !== ' ' && v !== ' ') ? v.replace(/\"/g,"'") : ""; } else { return v; } }, stripPref : function (pref, id) { var obj = $.type( pref ); if( obj == "string" || obj =="number") { pref = String(pref); id = pref !== "" ? String(id).replace(String(pref), "") : id; } return id; }, stringToDoc : function (xmlString) { var xmlDoc; if(typeof xmlString !== 'string') { return xmlString; } try { var parser = new DOMParser(); xmlDoc = parser.parseFromString(xmlString,"text/xml"); } catch(e) { xmlDoc = new ActiveXObject("Microsoft.XMLDOM"); xmlDoc.async=false; xmlDoc.loadXML(xmlString); } return (xmlDoc && xmlDoc.documentElement && xmlDoc.documentElement.tagName != 'parsererror') ? xmlDoc : null; }, parse : function(jsonString) { var js = jsonString; if (js.substr(0,9) == "while(1);") { js = js.substr(9); } if (js.substr(0,2) == "/*") { js = js.substr(2,js.length-4); } if(!js) { js = "{}"; } return ($.jgrid.useJSON===true && typeof (JSON) === 'object' && typeof (JSON.parse) === 'function') ? JSON.parse(js) : eval('(' + js + ')'); }, parseDate : function(format, date) { var tsp = {m : 1, d : 1, y : 1970, h : 0, i : 0, s : 0, u:0},k,hl,dM, regdate = /[\\\/:_;.,\t\T\s-]/; if(date && date !== null && date !== undefined){ date = $.trim(date); date = date.split(regdate); if ($.jgrid.formatter.date.masks[format] !== undefined) { format = $.jgrid.formatter.date.masks[format]; } format = format.split(regdate); var dfmt = $.jgrid.formatter.date.monthNames; var afmt = $.jgrid.formatter.date.AmPm; var h12to24 = function(ampm, h){ if (ampm === 0){ if (h === 12) { h = 0;} } else { if (h !== 12) { h += 12; } } return h; }; for(k=0,hl=format.length;k 11){ date[k] = dM+1-12; tsp.m = date[k]; } } if(format[k] == 'a') { dM = $.inArray(date[k],afmt); if(dM !== -1 && dM < 2 && date[k] == afmt[dM]){ date[k] = dM; tsp.h = h12to24(date[k], tsp.h); } } if(format[k] == 'A') { dM = $.inArray(date[k],afmt); if(dM !== -1 && dM > 1 && date[k] == afmt[dM]){ date[k] = dM-2; tsp.h = h12to24(date[k], tsp.h); } } if(date[k] !== undefined) { tsp[format[k].toLowerCase()] = parseInt(date[k],10); } } tsp.m = parseInt(tsp.m,10)-1; var ty = tsp.y; if (ty >= 70 && ty <= 99) {tsp.y = 1900+tsp.y;} else if (ty >=0 && ty <=69) {tsp.y= 2000+tsp.y;} if(tsp.j !== undefined) { tsp.d = tsp.j; } if(tsp.n !== undefined) { tsp.m = parseInt(tsp.n,10)-1; } } return new Date(tsp.y, tsp.m, tsp.d, tsp.h, tsp.i, tsp.s, tsp.u); }, jqID : function(sid){ return String(sid).replace(/[!"#$%&'()*+,.\/:;<=>?@\[\\\]\^`{|}~]/g,"\\$&"); }, guid : 1, uidPref: 'jqg', randId : function( prefix ) { return (prefix? prefix: $.jgrid.uidPref) + ($.jgrid.guid++); }, getAccessor : function(obj, expr) { var ret,p,prm = [], i; if( typeof expr === 'function') { return expr(obj); } ret = obj[expr]; if(ret===undefined) { try { if ( typeof expr === 'string' ) { prm = expr.split('.'); } i = prm.length; if( i ) { ret = obj; while (ret && i--) { p = prm.shift(); ret = ret[p]; } } } catch (e) {} } return ret; }, getXmlData: function (obj, expr, returnObj) { var ret, m = typeof (expr) === 'string' ? expr.match(/^(.*)\[(\w+)\]$/) : null; if (typeof (expr) === 'function') { return expr(obj); } if (m && m[2]) { // m[2] is the attribute selector // m[1] is an optional element selector // examples: "[id]", "rows[page]" return m[1] ? $(m[1], obj).attr(m[2]) : $(obj).attr(m[2]); } else { ret = $(expr, obj); if (returnObj) { return ret; } //$(expr, obj).filter(':last'); // we use ':last' to be more compatible with old version of jqGrid return ret.length > 0 ? $(ret).text() : undefined; } }, ajaxOptions: {}, from : function(source){ // Original Author Hugo Bonacci // License MIT http://jlinq.codeplex.com/license var QueryObject=function(d,q){ if(typeof(d)=="string"){ d=$.data(d); } var self=this, _data=d, _usecase=true, _trim=false, _query=q, _stripNum = /[\$,%]/g, _lastCommand=null, _lastField=null, _orDepth=0, _negate=false, _queuedOperator="", _sorting=[], _useProperties=true; if(typeof(d)=="object"&&d.push) { if(d.length>0){ if(typeof(d[0])!="object"){ _useProperties=false; }else{ _useProperties=true; } } }else{ throw "data provides is not an array"; } this._hasData=function(){ return _data===null?false:_data.length===0?false:true; }; this._getStr=function(s){ var phrase=[]; if(_trim){ phrase.push("jQuery.trim("); } phrase.push("String("+s+")"); if(_trim){ phrase.push(")"); } if(!_usecase){ phrase.push(".toLowerCase()"); } return phrase.join(""); }; this._strComp=function(val){ if(typeof(val)=="string"){ return".toString()"; }else{ return""; } }; this._group=function(f,u){ return({field:f.toString(),unique:u,items:[]}); }; this._toStr=function(phrase){ if(_trim){ phrase=$.trim(phrase); } if(!_usecase){ phrase=phrase.toLowerCase(); } phrase=phrase.toString().replace(/\\/g,'\\\\').replace(/\"/g,'\\"'); return phrase; }; this._funcLoop=function(func){ var results=[]; $.each(_data,function(i,v){ results.push(func(v)); }); return results; }; this._append=function(s){ var i; if(_query===null){ _query=""; } else { _query+=_queuedOperator === "" ? " && " :_queuedOperator; } for (i=0;i<_orDepth;i++){ _query+="("; } if(_negate){ _query+="!"; } _query+="("+s+")"; _negate=false; _queuedOperator=""; _orDepth=0; }; this._setCommand=function(f,c){ _lastCommand=f; _lastField=c; }; this._resetNegate=function(){ _negate=false; }; this._repeatCommand=function(f,v){ if(_lastCommand===null){ return self; } if(f!==null&&v!==null){ return _lastCommand(f,v); } if(_lastField===null){ return _lastCommand(f); } if(!_useProperties){ return _lastCommand(f); } return _lastCommand(_lastField,f); }; this._equals=function(a,b){ return(self._compare(a,b,1)===0); }; this._compare=function(a,b,d){ var toString = Object.prototype.toString; if( d === undefined) { d = 1; } if(a===undefined) { a = null; } if(b===undefined) { b = null; } if(a===null && b===null){ return 0; } if(a===null&&b!==null){ return 1; } if(a!==null&&b===null){ return -1; } if (toString.call(a) === '[object Date]' && toString.call(b) === '[object Date]') { if (a < b) { return -d; } if (a > b) { return d; } return 0; } if(!_usecase && typeof(a) !== "number" && typeof(b) !== "number" ) { a=String(a).toLowerCase(); b=String(b).toLowerCase(); } if(ab){return d;} return 0; }; this._performSort=function(){ if(_sorting.length===0){return;} _data=self._doSort(_data,0); }; this._doSort=function(d,q){ var by=_sorting[q].by, dir=_sorting[q].dir, type = _sorting[q].type, dfmt = _sorting[q].datefmt; if(q==_sorting.length-1){ return self._getOrder(d, by, dir, type, dfmt); } q++; var values=self._getGroup(d,by,dir,type,dfmt); var results=[]; for(var i=0;i0; }; this.andNot=function(f,v,x){ _negate=!_negate; return self.and(f,v,x); }; this.orNot=function(f,v,x){ _negate=!_negate; return self.or(f,v,x); }; this.not=function(f,v,x){ return self.andNot(f,v,x); }; this.and=function(f,v,x){ _queuedOperator=" && "; if(f===undefined){ return self; } return self._repeatCommand(f,v,x); }; this.or=function(f,v,x){ _queuedOperator=" || "; if(f===undefined) { return self; } return self._repeatCommand(f,v,x); }; this.orBegin=function(){ _orDepth++; return self; }; this.orEnd=function(){ if (_query !== null){ _query+=")"; } return self; }; this.isNot=function(f){ _negate=!_negate; return self.is(f); }; this.is=function(f){ self._append('this.'+f); self._resetNegate(); return self; }; this._compareValues=function(func,f,v,how,t){ var fld; if(_useProperties){ fld='jQuery.jgrid.getAccessor(this,\''+f+'\')'; }else{ fld='this'; } if(v===undefined) { v = null; } //var val=v===null?f:v, var val =v, swst = t.stype === undefined ? "text" : t.stype; if(v !== null) { switch(swst) { case 'int': case 'integer': val = (isNaN(Number(val)) || val==="") ? '0' : val; // To be fixed with more inteligent code fld = 'parseInt('+fld+',10)'; val = 'parseInt('+val+',10)'; break; case 'float': case 'number': case 'numeric': val = String(val).replace(_stripNum, ''); val = (isNaN(Number(val)) || val==="") ? '0' : val; // To be fixed with more inteligent code fld = 'parseFloat('+fld+')'; val = 'parseFloat('+val+')'; break; case 'date': case 'datetime': val = String($.jgrid.parseDate(t.newfmt || 'Y-m-d',val).getTime()); fld = 'jQuery.jgrid.parseDate("'+t.srcfmt+'",'+fld+').getTime()'; break; default : fld=self._getStr(fld); val=self._getStr('"'+self._toStr(val)+'"'); } } self._append(fld+' '+how+' '+val); self._setCommand(func,f); self._resetNegate(); return self; }; this.equals=function(f,v,t){ return self._compareValues(self.equals,f,v,"==",t); }; this.notEquals=function(f,v,t){ return self._compareValues(self.equals,f,v,"!==",t); }; this.isNull = function(f,v,t){ return self._compareValues(self.equals,f,null,"===",t); }; this.greater=function(f,v,t){ return self._compareValues(self.greater,f,v,">",t); }; this.less=function(f,v,t){ return self._compareValues(self.less,f,v,"<",t); }; this.greaterOrEquals=function(f,v,t){ return self._compareValues(self.greaterOrEquals,f,v,">=",t); }; this.lessOrEquals=function(f,v,t){ return self._compareValues(self.lessOrEquals,f,v,"<=",t); }; this.startsWith=function(f,v){ var val = (v===undefined || v===null) ? f: v, length=_trim ? $.trim(val.toString()).length : val.toString().length; if(_useProperties){ self._append(self._getStr('jQuery.jgrid.getAccessor(this,\''+f+'\')')+'.substr(0,'+length+') == '+self._getStr('"'+self._toStr(v)+'"')); }else{ length=_trim?$.trim(v.toString()).length:v.toString().length; self._append(self._getStr('this')+'.substr(0,'+length+') == '+self._getStr('"'+self._toStr(f)+'"')); } self._setCommand(self.startsWith,f); self._resetNegate(); return self; }; this.endsWith=function(f,v){ var val = (v===undefined || v===null) ? f: v, length=_trim ? $.trim(val.toString()).length:val.toString().length; if(_useProperties){ self._append(self._getStr('jQuery.jgrid.getAccessor(this,\''+f+'\')')+'.substr('+self._getStr('jQuery.jgrid.getAccessor(this,\''+f+'\')')+'.length-'+length+','+length+') == "'+self._toStr(v)+'"'); } else { self._append(self._getStr('this')+'.substr('+self._getStr('this')+'.length-"'+self._toStr(f)+'".length,"'+self._toStr(f)+'".length) == "'+self._toStr(f)+'"'); } self._setCommand(self.endsWith,f);self._resetNegate(); return self; }; this.contains=function(f,v){ if(_useProperties){ self._append(self._getStr('jQuery.jgrid.getAccessor(this,\''+f+'\')')+'.indexOf("'+self._toStr(v)+'",0) > -1'); }else{ self._append(self._getStr('this')+'.indexOf("'+self._toStr(f)+'",0) > -1'); } self._setCommand(self.contains,f); self._resetNegate(); return self; }; this.groupBy=function(by,dir,type, datefmt){ if(!self._hasData()){ return null; } return self._getGroup(_data,by,dir,type, datefmt); }; this.orderBy=function(by,dir,stype, dfmt){ dir = dir === undefined || dir === null ? "a" :$.trim(dir.toString().toLowerCase()); if(stype === null || stype === undefined) { stype = "text"; } if(dfmt === null || dfmt === undefined) { dfmt = "Y-m-d"; } if(dir=="desc"||dir=="descending"){dir="d";} if(dir=="asc"||dir=="ascending"){dir="a";} _sorting.push({by:by,dir:dir,type:stype, datefmt: dfmt}); return self; }; return self; }; return new QueryObject(source,null); }, extend : function(methods) { $.extend($.fn.jqGrid,methods); if (!this.no_legacy_api) { $.fn.extend(methods); } } }); $.fn.jqGrid = function( pin ) { if (typeof pin == 'string') { //var fn = $.fn.jqGrid[pin]; var fn = $.jgrid.getAccessor($.fn.jqGrid,pin); if (!fn) { throw ("jqGrid - No such method: " + pin); } var args = $.makeArray(arguments).slice(1); return fn.apply(this,args); } return this.each( function() { if(this.grid) {return;} var p = $.extend(true,{ url: "", height: 150, page: 1, rowNum: 20, rowTotal : null, records: 0, pager: "", pgbuttons: true, pginput: true, colModel: [], rowList: [], colNames: [], sortorder: "asc", sortname: "", datatype: "xml", mtype: "GET", altRows: false, selarrrow: [], savedRow: [], shrinkToFit: true, xmlReader: {}, jsonReader: {}, subGrid: false, subGridModel :[], reccount: 0, lastpage: 0, lastsort: 0, selrow: null, beforeSelectRow: null, onSelectRow: null, onSortCol: null, ondblClickRow: null, onRightClickRow: null, onPaging: null, onSelectAll: null, loadComplete: null, gridComplete: null, loadError: null, loadBeforeSend: null, afterInsertRow: null, beforeRequest: null, beforeProcessing : null, onHeaderClick: null, viewrecords: false, loadonce: false, multiselect: false, multikey: false, editurl: null, search: false, caption: "", hidegrid: true, hiddengrid: false, postData: {}, userData: {}, treeGrid : false, treeGridModel : 'nested', treeReader : {}, treeANode : -1, ExpandColumn: null, tree_root_level : 0, prmNames: {page:"page",rows:"rows", sort: "sidx",order: "sord", search:"_search", nd:"nd", id:"id",oper:"oper",editoper:"edit",addoper:"add",deloper:"del", subgridid:"id", npage: null, totalrows:"totalrows"}, forceFit : false, gridstate : "visible", cellEdit: false, cellsubmit: "remote", nv:0, loadui: "enable", toolbar: [false,""], scroll: false, multiboxonly : false, deselectAfterSort : true, scrollrows : false, autowidth: false, scrollOffset :18, cellLayout: 5, subGridWidth: 20, multiselectWidth: 20, gridview: false, rownumWidth: 25, rownumbers : false, pagerpos: 'center', recordpos: 'right', footerrow : false, userDataOnFooter : false, hoverrows : true, altclass : 'ui-priority-secondary', viewsortcols : [false,'vertical',true], resizeclass : '', autoencode : false, remapColumns : [], ajaxGridOptions :{}, direction : "ltr", toppager: false, headertitles: false, scrollTimeout: 40, data : [], _index : {}, grouping : false, groupingView : {groupField:[],groupOrder:[], groupText:[],groupColumnShow:[],groupSummary:[], showSummaryOnHide: false, sortitems:[], sortnames:[], groupDataSorted : false, summary:[],summaryval:[], plusicon: 'ui-icon-circlesmall-plus', minusicon: 'ui-icon-circlesmall-minus'}, ignoreCase : false, cmTemplate : {}, idPrefix : "" }, $.jgrid.defaults, pin || {}); var ts= this, grid={ headers:[], cols:[], footers: [], dragStart: function(i,x,y) { this.resizing = { idx: i, startX: x.clientX, sOL : y[0]}; this.hDiv.style.cursor = "col-resize"; this.curGbox = $("#rs_m"+$.jgrid.jqID(p.id),"#gbox_"+$.jgrid.jqID(p.id)); this.curGbox.css({display:"block",left:y[0],top:y[1],height:y[2]}); $(ts).triggerHandler("jqGridResizeStart", [x, i]); if($.isFunction(p.resizeStart)) { p.resizeStart.call(this,x,i); } document.onselectstart=function(){return false;}; }, dragMove: function(x) { if(this.resizing) { var diff = x.clientX-this.resizing.startX, h = this.headers[this.resizing.idx], newWidth = p.direction === "ltr" ? h.width + diff : h.width - diff, hn, nWn; if(newWidth > 33) { this.curGbox.css({left:this.resizing.sOL+diff}); if(p.forceFit===true ){ hn = this.headers[this.resizing.idx+p.nv]; nWn = p.direction === "ltr" ? hn.width - diff : hn.width + diff; if(nWn >33) { h.newWidth = newWidth; hn.newWidth = nWn; } } else { this.newWidth = p.direction === "ltr" ? p.tblwidth+diff : p.tblwidth-diff; h.newWidth = newWidth; } } } }, dragEnd: function() { this.hDiv.style.cursor = "default"; if(this.resizing) { var idx = this.resizing.idx, nw = this.headers[idx].newWidth || this.headers[idx].width; nw = parseInt(nw,10); this.resizing = false; $("#rs_m"+$.jgrid.jqID(p.id)).css("display","none"); p.colModel[idx].width = nw; this.headers[idx].width = nw; this.headers[idx].el.style.width = nw + "px"; this.cols[idx].style.width = nw+"px"; if(this.footers.length>0) {this.footers[idx].style.width = nw+"px";} if(p.forceFit===true){ nw = this.headers[idx+p.nv].newWidth || this.headers[idx+p.nv].width; this.headers[idx+p.nv].width = nw; this.headers[idx+p.nv].el.style.width = nw + "px"; this.cols[idx+p.nv].style.width = nw+"px"; if(this.footers.length>0) {this.footers[idx+p.nv].style.width = nw+"px";} p.colModel[idx+p.nv].width = nw; } else { p.tblwidth = this.newWidth || p.tblwidth; $('table:first',this.bDiv).css("width",p.tblwidth+"px"); $('table:first',this.hDiv).css("width",p.tblwidth+"px"); this.hDiv.scrollLeft = this.bDiv.scrollLeft; if(p.footerrow) { $('table:first',this.sDiv).css("width",p.tblwidth+"px"); this.sDiv.scrollLeft = this.bDiv.scrollLeft; } } $(ts).triggerHandler("jqGridResizeStop", [nw, idx]); if($.isFunction(p.resizeStop)) { p.resizeStop.call(this,nw,idx); } } this.curGbox = null; document.onselectstart=function(){return true;}; }, populateVisible: function() { if (grid.timer) { clearTimeout(grid.timer); } grid.timer = null; var dh = $(grid.bDiv).height(); if (!dh) { return; } var table = $("table:first", grid.bDiv); var rows, rh; if(table[0].rows.length) { try { rows = table[0].rows[1]; rh = rows ? $(rows).outerHeight() || grid.prevRowHeight : grid.prevRowHeight; } catch (pv) { rh = grid.prevRowHeight; } } if (!rh) { return; } grid.prevRowHeight = rh; var rn = p.rowNum; var scrollTop = grid.scrollTop = grid.bDiv.scrollTop; var ttop = Math.round(table.position().top) - scrollTop; var tbot = ttop + table.height(); var div = rh * rn; var page, npage, empty; if ( tbot < dh && ttop <= 0 && (p.lastpage===undefined||parseInt((tbot + scrollTop + div - 1) / div,10) <= p.lastpage)) { npage = parseInt((dh - tbot + div - 1) / div,10); if (tbot >= 0 || npage < 2 || p.scroll === true) { page = Math.round((tbot + scrollTop) / div) + 1; ttop = -1; } else { ttop = 1; } } if (ttop > 0) { page = parseInt(scrollTop / div,10) + 1; npage = parseInt((scrollTop + dh) / div,10) + 2 - page; empty = true; } if (npage) { if (p.lastpage && page > p.lastpage || p.lastpage==1 || (page === p.page && page===p.lastpage) ) { return; } if (grid.hDiv.loading) { grid.timer = setTimeout(grid.populateVisible, p.scrollTimeout); } else { p.page = page; if (empty) { grid.selectionPreserver(table[0]); grid.emptyRows(grid.bDiv,false, false); } grid.populate(npage); } } }, scrollGrid: function( e ) { if(p.scroll) { var scrollTop = grid.bDiv.scrollTop; if(grid.scrollTop === undefined) { grid.scrollTop = 0; } if (scrollTop != grid.scrollTop) { grid.scrollTop = scrollTop; if (grid.timer) { clearTimeout(grid.timer); } grid.timer = setTimeout(grid.populateVisible, p.scrollTimeout); } } grid.hDiv.scrollLeft = grid.bDiv.scrollLeft; if(p.footerrow) { grid.sDiv.scrollLeft = grid.bDiv.scrollLeft; } if( e ) { e.stopPropagation(); } }, selectionPreserver : function(ts) { var p = ts.p, sr = p.selrow, sra = p.selarrrow ? $.makeArray(p.selarrrow) : null, left = ts.grid.bDiv.scrollLeft, restoreSelection = function() { var i; p.selrow = null; p.selarrrow = []; if(p.multiselect && sra && sra.length>0) { for(i=0;i"), ii, isMSIE = $.browser.msie ? true:false, isSafari = $.browser.webkit || $.browser.safari ? true : false; ts.p.direction = $.trim(ts.p.direction.toLowerCase()); if($.inArray(ts.p.direction,["ltr","rtl"]) == -1) { ts.p.direction = "ltr"; } dir = ts.p.direction; $(gv).insertBefore(this); $(this).appendTo(gv).removeClass("scroll"); var eg = $("
"); $(eg).insertBefore(gv).attr({"id" : "gbox_"+this.id,"dir":dir}); $(gv).appendTo(eg).attr("id","gview_"+this.id); if (isMSIE && $.browser.version <= 6) { ii = ''; } else { ii="";} $("
").append(ii).insertBefore(gv); $("
"+this.p.loadtext+"
").insertBefore(gv); $(this).attr({cellspacing:"0",cellpadding:"0",border:"0","role":"grid","aria-multiselectable":!!this.p.multiselect,"aria-labelledby":"gbox_"+this.id}); var sortkeys = ["shiftKey","altKey","ctrlKey"], intNum = function(val,defval) { val = parseInt(val,10); if (isNaN(val)) { return defval ? defval : 0;} else {return val;} }, formatCol = function (pos, rowInd, tv, rawObject, rowId, rdata){ var cm = ts.p.colModel[pos], ral = cm.align, result="style=\"", clas = cm.classes, nm = cm.name, celp, acp=[]; if(ral) { result += "text-align:"+ral+";"; } if(cm.hidden===true) { result += "display:none;"; } if(rowInd===0) { result += "width: "+grid.headers[pos].width+"px;"; } else if (cm.cellattr && $.isFunction(cm.cellattr)) { celp = cm.cellattr.call(ts, rowId, tv, rawObject, cm, rdata); if(celp && typeof(celp) === "string") { celp = celp.replace(/style/i,'style').replace(/title/i,'title'); if(celp.indexOf('title') > -1) { cm.title=false;} if(celp.indexOf('class') > -1) { clas = undefined;} acp = celp.split("style"); if(acp.length === 2 ) { acp[1] = $.trim(acp[1].replace("=","")); if(acp[1].indexOf("'") === 0 || acp[1].indexOf('"') === 0) { acp[1] = acp[1].substring(1); } result += acp[1].replace(/'/gi,'"'); } else { result += "\""; } } } if(!acp.length) { acp[0] = ""; result += "\"";} result += (clas !== undefined ? (" class=\""+clas+"\"") :"") + ((cm.title && tv) ? (" title=\""+$.jgrid.stripHtml(tv)+"\"") :""); result += " aria-describedby=\""+ts.p.id+"_"+nm+"\""; return result + acp[0]; }, cellVal = function (val) { return val === undefined || val === null || val === "" ? " " : (ts.p.autoencode ? $.jgrid.htmlEncode(val) : val+""); }, formatter = function (rowId, cellval , colpos, rwdat, _act){ var cm = ts.p.colModel[colpos],v; if(typeof cm.formatter !== 'undefined') { var opts= {rowId: rowId, colModel:cm, gid:ts.p.id, pos:colpos }; if($.isFunction( cm.formatter ) ) { v = cm.formatter.call(ts,cellval,opts,rwdat,_act); } else if($.fmatter){ v = $.fn.fmatter.call(ts,cm.formatter,cellval,opts,rwdat,_act); } else { v = cellVal(cellval); } } else { v = cellVal(cellval); } return v; }, addCell = function(rowId,cell,pos,irow, srvr) { var v,prp; v = formatter(rowId,cell,pos,srvr,'add'); prp = formatCol( pos,irow, v, srvr, rowId, true); return ""+v+""; }, addMulti = function(rowid,pos,irow){ var v = "", prp = formatCol( pos,irow,'',null, rowid, true); return ""+v+""; }, addRowNum = function (pos,irow,pG,rN) { var v = (parseInt(pG,10)-1)*parseInt(rN,10)+1+irow, prp = formatCol( pos,irow,v, null, irow, true); return ""+v+""; }, reader = function (datatype) { var field, f=[], j=0, i; for(i =0; idiv:first", parent).css({height:"auto"}).children("div:first").css({height:0,display:"none"}); parent.scrollTop = 0; } if(locdata === true) { if(ts.p.treeGrid === true ) { ts.p.data = []; ts.p._index = {}; } } }, refreshIndex = function() { var datalen = ts.p.data.length, idname, i, val, ni = ts.p.rownumbers===true ? 1 :0, gi = ts.p.multiselect ===true ? 1 :0, si = ts.p.subGrid===true ? 1 :0; if(ts.p.keyIndex === false || ts.p.loadonce === true) { idname = ts.p.localReader.id; } else { idname = ts.p.colModel[ts.p.keyIndex+gi+si+ni].name; } for(i =0;i < datalen; i++) { val = $.jgrid.getAccessor(ts.p.data[i],idname); ts.p._index[val] = i; } }, constructTr = function(id, hide, altClass, rd, cur) { var tabindex = '-1', restAttr = '', attrName, style = hide ? 'display:none;' : '', classes = 'ui-widget-content jqgrow ui-row-' + ts.p.direction + altClass, rowAttrObj = $.isFunction(ts.p.rowattr) ? ts.p.rowattr.call(ts, rd, cur) : {}; if(!$.isEmptyObject( rowAttrObj )) { if (rowAttrObj.hasOwnProperty("id")) { id = rowAttrObj.id; delete rowAttrObj.id; } if (rowAttrObj.hasOwnProperty("tabindex")) { tabindex = rowAttrObj.tabindex; delete rowAttrObj.tabindex; } if (rowAttrObj.hasOwnProperty("style")) { style += rowAttrObj.style; delete rowAttrObj.style; } if (rowAttrObj.hasOwnProperty("class")) { classes += ' ' + rowAttrObj['class']; delete rowAttrObj['class']; } // dot't allow to change role attribute try { delete rowAttrObj.role; } catch(ra){} for (attrName in rowAttrObj) { if (rowAttrObj.hasOwnProperty(attrName)) { restAttr += ' ' + attrName + '=' + rowAttrObj[attrName]; } } } return ''; }, addXmlData = function (xml,t, rcnt, more, adjust) { var startReq = new Date(), locdata = (ts.p.datatype != "local" && ts.p.loadonce) || ts.p.datatype == "xmlstring", xmlid = "_id_", xmlRd = ts.p.xmlReader, frd = ts.p.datatype == "local" ? "local" : "xml"; if(locdata) { ts.p.data = []; ts.p._index = {}; ts.p.localReader.id = xmlid; } ts.p.reccount = 0; if($.isXMLDoc(xml)) { if(ts.p.treeANode===-1 && !ts.p.scroll) { emptyRows(t,false, true); rcnt=1; } else { rcnt = rcnt > 1 ? rcnt :1; } } else { return; } var i,fpos,ir=0,v,gi=ts.p.multiselect===true?1:0,si=ts.p.subGrid===true?1:0,ni=ts.p.rownumbers===true?1:0,idn, getId,f=[],F,rd ={}, xmlr,rid, rowData=[], cn=(ts.p.altRows === true) ? " "+ts.p.altclass:"",cn1; if(!xmlRd.repeatitems) {f = reader(frd);} if( ts.p.keyIndex===false) { idn = $.isFunction( xmlRd.id ) ? xmlRd.id.call(ts, xml) : xmlRd.id; } else { idn = ts.p.keyIndex; } if(f.length>0 && !isNaN(idn)) { if (ts.p.remapColumns && ts.p.remapColumns.length) { idn = $.inArray(idn, ts.p.remapColumns); } idn=f[idn]; } if( (idn+"").indexOf("[") === -1 ) { if (f.length) { getId = function( trow, k) {return $(idn,trow).text() || k;}; } else { getId = function( trow, k) {return $(xmlRd.cell,trow).eq(idn).text() || k;}; } } else { getId = function( trow, k) {return trow.getAttribute(idn.replace(/[\[\]]/g,"")) || k;}; } ts.p.userData = {}; ts.p.page = $.jgrid.getXmlData( xml,xmlRd.page ) || 0; ts.p.lastpage = $.jgrid.getXmlData( xml,xmlRd.total ); if(ts.p.lastpage===undefined) { ts.p.lastpage=1; } ts.p.records = $.jgrid.getXmlData( xml,xmlRd.records ) || 0; if($.isFunction(xmlRd.userdata)) { ts.p.userData = xmlRd.userdata.call(ts, xml) || {}; } else { $.jgrid.getXmlData(xml, xmlRd.userdata, true).each(function() {ts.p.userData[this.getAttribute("name")]= $(this).text();}); } var gxml = $.jgrid.getXmlData( xml, xmlRd.root, true); gxml = $.jgrid.getXmlData( gxml, xmlRd.row, true); if (!gxml) { gxml = []; } var gl = gxml.length, j=0, grpdata={}, rn = parseInt(ts.p.rowNum,10); if (gl > 0 && ts.p.page <= 0) { ts.p.page = 1; } if(gxml && gl){ var br=ts.p.scroll?$.jgrid.randId():1,altr; if (adjust) { rn *= adjust+1; } var afterInsRow = $.isFunction(ts.p.afterInsertRow), hiderow=ts.p.grouping && ts.p.groupingView.groupCollapse === true; while (j"); if(ts.p.grouping) { var grlen = ts.p.groupingView.groupField.length, grpitem = []; for(var z=0;z -1 ? ts.p.treeANode: 0; if(ts.p.grouping) { $(ts).jqGrid('groupingRender',grpdata,ts.p.colModel.length); grpdata = null; } else if(ts.p.treeGrid === true && fpos > 0) { $(ts.rows[fpos]).after(rowData.join('')); } else { $("tbody:first",t).append(rowData.join('')); } } if(ts.p.subGrid === true ) { try {$(ts).jqGrid("addSubGrid",gi+ni);} catch (_){} } ts.p.totaltime = new Date() - startReq; if(ir>0) { if(ts.p.records===0) { ts.p.records=gl;} } rowData =null; if( ts.p.treeGrid === true) { try {$(ts).jqGrid("setTreeNode", fpos+1, ir+fpos+1);} catch (e) {} } if(!ts.p.treeGrid && !ts.p.scroll) {ts.grid.bDiv.scrollTop = 0;} ts.p.reccount=ir; ts.p.treeANode = -1; if(ts.p.userDataOnFooter) { $(ts).jqGrid("footerData","set",ts.p.userData,true); } if(locdata) { ts.p.records = gl; ts.p.lastpage = Math.ceil(gl/ rn); } if (!more) { ts.updatepager(false,true); } if(locdata) { while (ir 1 ? rcnt :1; } } else { return; } var dReader, locid = "_id_", frd, locdata = (ts.p.datatype != "local" && ts.p.loadonce) || ts.p.datatype == "jsonstring"; if(locdata) { ts.p.data = []; ts.p._index = {}; ts.p.localReader.id = locid;} ts.p.reccount = 0; if(ts.p.datatype == "local") { dReader = ts.p.localReader; frd= 'local'; } else { dReader = ts.p.jsonReader; frd='json'; } var ir=0,v,i,j,f=[],F,cur,gi=ts.p.multiselect?1:0,si=ts.p.subGrid?1:0,ni=ts.p.rownumbers===true?1:0,len,drows,idn,rd={}, fpos, idr,rowData=[],cn=(ts.p.altRows === true) ? " "+ts.p.altclass:"",cn1,lp; ts.p.page = $.jgrid.getAccessor(data,dReader.page) || 0; lp = $.jgrid.getAccessor(data,dReader.total); ts.p.lastpage = lp === undefined ? 1 : lp; ts.p.records = $.jgrid.getAccessor(data,dReader.records) || 0; ts.p.userData = $.jgrid.getAccessor(data,dReader.userdata) || {}; if(!dReader.repeatitems) { F = f = reader(frd); } if( ts.p.keyIndex===false ) { idn = $.isFunction(dReader.id) ? dReader.id.call(ts, data) : dReader.id; } else { idn = ts.p.keyIndex; } if(f.length>0 && !isNaN(idn)) { if (ts.p.remapColumns && ts.p.remapColumns.length) { idn = $.inArray(idn, ts.p.remapColumns); } idn=f[idn]; } drows = $.jgrid.getAccessor(data,dReader.root); if (!drows) { drows = []; } len = drows.length; i=0; if (len > 0 && ts.p.page <= 0) { ts.p.page = 1; } var rn = parseInt(ts.p.rowNum,10),br=ts.p.scroll?$.jgrid.randId():1, altr; if (adjust) { rn *= adjust+1; } var afterInsRow = $.isFunction(ts.p.afterInsertRow), grpdata={}, hiderow=ts.p.grouping && ts.p.groupingView.groupCollapse === true; while (i" ); if(ts.p.grouping) { var grlen = ts.p.groupingView.groupField.length, grpitem = []; for(var z=0;z -1 ? ts.p.treeANode: 0; if(ts.p.grouping) { $(ts).jqGrid('groupingRender',grpdata,ts.p.colModel.length); grpdata = null; } else if(ts.p.treeGrid === true && fpos > 0) { $(ts.rows[fpos]).after(rowData.join('')); } else { $("#"+$.jgrid.jqID(ts.p.id)+" tbody:first").append(rowData.join('')); } } if(ts.p.subGrid === true ) { try { $(ts).jqGrid("addSubGrid",gi+ni);} catch (_){} } ts.p.totaltime = new Date() - startReq; if(ir>0) { if(ts.p.records===0) { ts.p.records=len; } } rowData = null; if( ts.p.treeGrid === true) { try {$(ts).jqGrid("setTreeNode", fpos+1, ir+fpos+1);} catch (e) {} } if(!ts.p.treeGrid && !ts.p.scroll) {ts.grid.bDiv.scrollTop = 0;} ts.p.reccount=ir; ts.p.treeANode = -1; if(ts.p.userDataOnFooter) { $(ts).jqGrid("footerData","set",ts.p.userData,true); } if(locdata) { ts.p.records = len; ts.p.lastpage = Math.ceil(len/ rn); } if (!more) { ts.updatepager(false,true); } if(locdata) { while (ir 0 && gor) { query.or(); } try { tojLinq(group.groups[index]); } catch (e) {alert(e);} s++; } if (gor) { query.orEnd(); } } if (group.rules !== undefined) { if(s>0) { var result = query.select(); query = $.jgrid.from( result); if (ts.p.ignoreCase) { query = query.ignoreCase(); } } try{ ror = group.rules.length && group.groupOp.toString().toUpperCase() === "OR"; if (ror) { query.orBegin(); } for (index = 0; index < group.rules.length; index++) { rule = group.rules[index]; opr = group.groupOp.toString().toUpperCase(); if (compareFnMap[rule.op] && rule.field ) { if(s > 0 && opr && opr === "OR") { query = query.or(); } query = compareFnMap[rule.op](query, opr)(rule.field, rule.data, cmtypes[rule.field]); } s++; } if (ror) { query.orEnd(); } } catch (g) {alert(g);} } } if (ts.p.search === true) { var srules = ts.p.postData.filters; if(srules) { if(typeof srules == "string") { srules = $.jgrid.parse(srules);} tojLinq( srules ); } else { try { query = compareFnMap[ts.p.postData.searchOper](query)(ts.p.postData.searchField, ts.p.postData.searchString,cmtypes[ts.p.postData.searchField]); } catch (se){} } } if(ts.p.grouping) { query.orderBy(grindexes,grpview.groupOrder[0],grtypes[0].stype, grtypes[0].srcfmt); grpview.groupDataSorted = true; } if (st && ts.p.sortorder && fndsort) { if(ts.p.sortorder.toUpperCase() == "DESC") { query.orderBy(ts.p.sortname, "d", cmtypes[st].stype, cmtypes[st].srcfmt); } else { query.orderBy(ts.p.sortname, "a", cmtypes[st].stype, cmtypes[st].srcfmt); } } var queryResults = query.select(), recordsperpage = parseInt(ts.p.rowNum,10), total = queryResults.length, page = parseInt(ts.p.page,10), totalpages = Math.ceil(total / recordsperpage), retresult = {}; queryResults = queryResults.slice( (page-1)*recordsperpage , page*recordsperpage ); query = null; cmtypes = null; retresult[ts.p.localReader.total] = totalpages; retresult[ts.p.localReader.page] = page; retresult[ts.p.localReader.records] = total; retresult[ts.p.localReader.root] = queryResults; retresult[ts.p.localReader.userdata] = ts.p.userData; queryResults = null; return retresult; }, updatepager = function(rn, dnd) { var cp, last, base, from,to,tot,fmt, pgboxes = "", sppg, tspg = ts.p.pager ? "_"+$.jgrid.jqID(ts.p.pager.substr(1)) : "", tspg_t = ts.p.toppager ? "_"+ts.p.toppager.substr(1) : ""; base = parseInt(ts.p.page,10)-1; if(base < 0) { base = 0; } base = base*parseInt(ts.p.rowNum,10); to = base + ts.p.reccount; if (ts.p.scroll) { var rows = $("tbody:first > tr:gt(0)", ts.grid.bDiv); base = to - rows.length; ts.p.reccount = rows.length; var rh = rows.outerHeight() || ts.grid.prevRowHeight; if (rh) { var top = base * rh; var height = parseInt(ts.p.records,10) * rh; $(">div:first",ts.grid.bDiv).css({height : height}).children("div:first").css({height:top,display:top?"":"none"}); } ts.grid.bDiv.scrollLeft = ts.grid.hDiv.scrollLeft; } pgboxes = ts.p.pager ? ts.p.pager : ""; pgboxes += ts.p.toppager ? (pgboxes ? "," + ts.p.toppager : ts.p.toppager) : ""; if(pgboxes) { fmt = $.jgrid.formatter.integer || {}; cp = intNum(ts.p.page); last = intNum(ts.p.lastpage); $(".selbox",pgboxes)[ this.p.useProp ? 'prop' : 'attr' ]("disabled",false); if(ts.p.pginput===true) { $('.ui-pg-input',pgboxes).val(ts.p.page); sppg = ts.p.toppager ? '#sp_1'+tspg+",#sp_1"+tspg_t : '#sp_1'+tspg; $(sppg).html($.fmatter ? $.fmatter.util.NumberFormat(ts.p.lastpage,fmt):ts.p.lastpage); } if (ts.p.viewrecords){ if(ts.p.reccount === 0) { $(".ui-paging-info",pgboxes).html(ts.p.emptyrecords); } else { from = base+1; tot=ts.p.records; if($.fmatter) { from = $.fmatter.util.NumberFormat(from,fmt); to = $.fmatter.util.NumberFormat(to,fmt); tot = $.fmatter.util.NumberFormat(tot,fmt); } $(".ui-paging-info",pgboxes).html($.jgrid.format(ts.p.recordtext,from,to,tot)); } } if(ts.p.pgbuttons===true) { if(cp<=0) {cp = last = 0;} if(cp==1 || cp === 0) { $("#first"+tspg+", #prev"+tspg).addClass('ui-state-disabled').removeClass('ui-state-hover'); if(ts.p.toppager) { $("#first_t"+tspg_t+", #prev_t"+tspg_t).addClass('ui-state-disabled').removeClass('ui-state-hover'); } } else { $("#first"+tspg+", #prev"+tspg).removeClass('ui-state-disabled'); if(ts.p.toppager) { $("#first_t"+tspg_t+", #prev_t"+tspg_t).removeClass('ui-state-disabled'); } } if(cp==last || cp === 0) { $("#next"+tspg+", #last"+tspg).addClass('ui-state-disabled').removeClass('ui-state-hover'); if(ts.p.toppager) { $("#next_t"+tspg_t+", #last_t"+tspg_t).addClass('ui-state-disabled').removeClass('ui-state-hover'); } } else { $("#next"+tspg+", #last"+tspg).removeClass('ui-state-disabled'); if(ts.p.toppager) { $("#next_t"+tspg_t+", #last_t"+tspg_t).removeClass('ui-state-disabled'); } } } } if(rn===true && ts.p.rownumbers === true) { $("td.jqgrid-rownum",ts.rows).each(function(i){ $(this).html(base+1+i); }); } if(dnd && ts.p.jqgdnd) { $(ts).jqGrid('gridDnD','updateDnD');} $(ts).triggerHandler("jqGridGridComplete"); if($.isFunction(ts.p.gridComplete)) {ts.p.gridComplete.call(ts);} $(ts).triggerHandler("jqGridAfterGridComplete"); }, beginReq = function() { ts.grid.hDiv.loading = true; if(ts.p.hiddengrid) { return;} switch(ts.p.loadui) { case "disable": break; case "enable": $("#load_"+$.jgrid.jqID(ts.p.id)).show(); break; case "block": $("#lui_"+$.jgrid.jqID(ts.p.id)).show(); $("#load_"+$.jgrid.jqID(ts.p.id)).show(); break; } }, endReq = function() { ts.grid.hDiv.loading = false; switch(ts.p.loadui) { case "disable": break; case "enable": $("#load_"+$.jgrid.jqID(ts.p.id)).hide(); break; case "block": $("#lui_"+$.jgrid.jqID(ts.p.id)).hide(); $("#load_"+$.jgrid.jqID(ts.p.id)).hide(); break; } }, populate = function (npage) { if(!ts.grid.hDiv.loading) { var pvis = ts.p.scroll && npage === false, prm = {}, dt, dstr, pN=ts.p.prmNames; if(ts.p.page <=0) { ts.p.page = 1; } if(pN.search !== null) {prm[pN.search] = ts.p.search;} if(pN.nd !== null) {prm[pN.nd] = new Date().getTime();} if(pN.rows !== null) {prm[pN.rows]= ts.p.rowNum;} if(pN.page !== null) {prm[pN.page]= ts.p.page;} if(pN.sort !== null) {prm[pN.sort]= ts.p.sortname;} if(pN.order !== null) {prm[pN.order]= ts.p.sortorder;} if(ts.p.rowTotal !== null && pN.totalrows !== null) { prm[pN.totalrows]= ts.p.rowTotal; } var lcf = $.isFunction(ts.p.loadComplete), lc = lcf ? ts.p.loadComplete : null; var adjust = 0; npage = npage || 1; if (npage > 1) { if(pN.npage !== null) { prm[pN.npage] = npage; adjust = npage - 1; npage = 1; } else { lc = function(req) { ts.p.page++; ts.grid.hDiv.loading = false; if (lcf) { ts.p.loadComplete.call(ts,req); } populate(npage-1); }; } } else if (pN.npage !== null) { delete ts.p.postData[pN.npage]; } if(ts.p.grouping) { $(ts).jqGrid('groupingSetup'); if(ts.p.groupingView.groupDataSorted === true) { prm[pN.sort] = ts.p.groupingView.groupField[0] +" "+ ts.p.groupingView.groupOrder[0]+", "+prm[pN.sort]; } } $.extend(ts.p.postData,prm); var rcnt = !ts.p.scroll ? 1 : ts.rows.length-1; var bfr = $(ts).triggerHandler("jqGridBeforeRequest"); if (bfr === false || bfr === 'stop') { return; } if ($.isFunction(ts.p.datatype)) { ts.p.datatype.call(ts,ts.p.postData,"load_"+ts.p.id); return;} else if($.isFunction(ts.p.beforeRequest)) { bfr = ts.p.beforeRequest.call(ts); if(bfr === undefined) { bfr = true; } if ( bfr === false ) { return; } } dt = ts.p.datatype.toLowerCase(); switch(dt) { case "json": case "jsonp": case "xml": case "script": $.ajax($.extend({ url:ts.p.url, type:ts.p.mtype, dataType: dt , data: $.isFunction(ts.p.serializeGridData)? ts.p.serializeGridData.call(ts,ts.p.postData) : ts.p.postData, success:function(data,st, xhr) { if ($.isFunction(ts.p.beforeProcessing)) { ts.p.beforeProcessing.call(ts, data, st, xhr); } if(dt === "xml") { addXmlData(data,ts.grid.bDiv,rcnt,npage>1,adjust); } else { addJSONData(data,ts.grid.bDiv,rcnt,npage>1,adjust); } $(ts).triggerHandler("jqGridLoadComplete", [data]); if(lc) { lc.call(ts,data); } $(ts).triggerHandler("jqGridAfterLoadComplete", [data]); if (pvis) { ts.grid.populateVisible(); } if( ts.p.loadonce || ts.p.treeGrid) {ts.p.datatype = "local";} data=null; if (npage === 1) { endReq(); } }, error:function(xhr,st,err){ if($.isFunction(ts.p.loadError)) { ts.p.loadError.call(ts,xhr,st,err); } if (npage === 1) { endReq(); } xhr=null; }, beforeSend: function(xhr, settings ){ var gotoreq = true; if($.isFunction(ts.p.loadBeforeSend)) { gotoreq = ts.p.loadBeforeSend.call(ts,xhr, settings); } if(gotoreq === undefined) { gotoreq = true; } if(gotoreq === false) { return false; } else { beginReq(); } } },$.jgrid.ajaxOptions, ts.p.ajaxGridOptions)); break; case "xmlstring": beginReq(); dstr = $.jgrid.stringToDoc(ts.p.datastr); addXmlData(dstr,ts.grid.bDiv); $(ts).triggerHandler("jqGridLoadComplete", [dstr]); if(lcf) {ts.p.loadComplete.call(ts,dstr);} $(ts).triggerHandler("jqGridAfterLoadComplete", [dstr]); ts.p.datatype = "local"; ts.p.datastr = null; endReq(); break; case "jsonstring": beginReq(); if(typeof ts.p.datastr == 'string') { dstr = $.jgrid.parse(ts.p.datastr); } else { dstr = ts.p.datastr; } addJSONData(dstr,ts.grid.bDiv); $(ts).triggerHandler("jqGridLoadComplete", [dstr]); if(lcf) {ts.p.loadComplete.call(ts,dstr);} $(ts).triggerHandler("jqGridAfterLoadComplete", [dstr]); ts.p.datatype = "local"; ts.p.datastr = null; endReq(); break; case "local": case "clientside": beginReq(); ts.p.datatype = "local"; var req = addLocalData(); addJSONData(req,ts.grid.bDiv,rcnt,npage>1,adjust); $(ts).triggerHandler("jqGridLoadComplete", [req]); if(lc) { lc.call(ts,req); } $(ts).triggerHandler("jqGridAfterLoadComplete", [req]); if (pvis) { ts.grid.populateVisible(); } endReq(); break; } } }, setHeadCheckBox = function ( checked ) { $('#cb_'+$.jgrid.jqID(ts.p.id),ts.grid.hDiv)[ts.p.useProp ? 'prop': 'attr']("checked", checked); var fid = ts.p.frozenColumns ? ts.p.id+"_frozen" : ""; if(fid) { $('#cb_'+$.jgrid.jqID(ts.p.id),ts.grid.fhDiv)[ts.p.useProp ? 'prop': 'attr']("checked", checked); } }, setPager = function (pgid, tp){ // TBD - consider escaping pgid with pgid = $.jgrid.jqID(pgid); var sep = "", pginp = "", pgl="", str="", pgcnt, lft, cent, rgt, twd, tdw, i, clearVals = function(onpaging){ var ret; if ($.isFunction(ts.p.onPaging) ) { ret = ts.p.onPaging.call(ts,onpaging); } ts.p.selrow = null; if(ts.p.multiselect) {ts.p.selarrrow =[]; setHeadCheckBox( false );} ts.p.savedRow = []; if(ret=='stop') {return false;} return true; }; pgid = pgid.substr(1); tp += "_" + pgid; pgcnt = "pg_"+pgid; lft = pgid+"_left"; cent = pgid+"_center"; rgt = pgid+"_right"; $("#"+$.jgrid.jqID(pgid) ) .append("
") .attr("dir","ltr"); //explicit setting if(ts.p.rowList.length >0){ str = ""; str +=""; } if(dir=="rtl") { pgl += str; } if(ts.p.pginput===true) { pginp= ""+$.jgrid.format(ts.p.pgtext || "","","")+"";} if(ts.p.pgbuttons===true) { var po=["first"+tp,"prev"+tp, "next"+tp,"last"+tp]; if(dir=="rtl") { po.reverse(); } pgl += ""; pgl += ""; pgl += pginp !== "" ? sep+pginp+sep:""; pgl += ""; pgl += ""; } else if (pginp !== "") { pgl += pginp; } if(dir=="ltr") { pgl += str; } pgl += ""; if(ts.p.viewrecords===true) {$("td#"+pgid+"_"+ts.p.recordpos,"#"+pgcnt).append("
");} $("td#"+pgid+"_"+ts.p.pagerpos,"#"+pgcnt).append(pgl); tdw = $(".ui-jqgrid").css("font-size") || "11px"; $(document.body).append(""); twd = $(pgl).clone().appendTo("#testpg").width(); $("#testpg").remove(); if(twd > 0) { if(pginp !== "") { twd += 50; } //should be param $("td#"+pgid+"_"+ts.p.pagerpos,"#"+pgcnt).width(twd); } ts.p._nvtd = []; ts.p._nvtd[0] = twd ? Math.floor((ts.p.width - twd)/2) : Math.floor(ts.p.width/3); ts.p._nvtd[1] = 0; pgl=null; $('.ui-pg-selbox',"#"+pgcnt).bind('change',function() { ts.p.page = Math.round(ts.p.rowNum*(ts.p.page-1)/this.value-0.5)+1; ts.p.rowNum = this.value; if(ts.p.pager) { $('.ui-pg-selbox',ts.p.pager).val(this.value); } if(ts.p.toppager) { $('.ui-pg-selbox',ts.p.toppager).val(this.value); } if(!clearVals('records')) { return false; } populate(); return false; }); if(ts.p.pgbuttons===true) { $(".ui-pg-button","#"+pgcnt).hover(function(){ if($(this).hasClass('ui-state-disabled')) { this.style.cursor='default'; } else { $(this).addClass('ui-state-hover'); this.style.cursor='pointer'; } },function() { if(!$(this).hasClass('ui-state-disabled')) { $(this).removeClass('ui-state-hover'); this.style.cursor= "default"; } }); $("#first"+$.jgrid.jqID(tp)+", #prev"+$.jgrid.jqID(tp)+", #next"+$.jgrid.jqID(tp)+", #last"+$.jgrid.jqID(tp)).click( function() { var cp = intNum(ts.p.page,1), last = intNum(ts.p.lastpage,1), selclick = false, fp=true, pp=true, np=true,lp=true; if(last ===0 || last===1) {fp=false;pp=false;np=false;lp=false; } else if( last>1 && cp >=1) { if( cp === 1) { fp=false; pp=false; } //else if( cp>1 && cp 1 && cp===0 ) { np=false;lp=false; cp=last-1;} if( this.id === 'first'+tp && fp ) { ts.p.page=1; selclick=true;} if( this.id === 'prev'+tp && pp) { ts.p.page=(cp-1); selclick=true;} if( this.id === 'next'+tp && np) { ts.p.page=(cp+1); selclick=true;} if( this.id === 'last'+tp && lp) { ts.p.page=last; selclick=true;} if(selclick) { if(!clearVals(this.id)) { return false; } populate(); } return false; }); } if(ts.p.pginput===true) { $('input.ui-pg-input',"#"+pgcnt).keypress( function(e) { var key = e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0; if(key == 13) { ts.p.page = ($(this).val()>0) ? $(this).val():ts.p.page; if(!clearVals('user')) { return false; } populate(); return false; } return this; }); } }, sortData = function (index, idxcol,reload,sor){ if(!ts.p.colModel[idxcol].sortable) { return; } var so; if(ts.p.savedRow.length > 0) {return;} if(!reload) { if( ts.p.lastsort == idxcol ) { if( ts.p.sortorder == 'asc') { ts.p.sortorder = 'desc'; } else if(ts.p.sortorder == 'desc') { ts.p.sortorder = 'asc';} } else { ts.p.sortorder = ts.p.colModel[idxcol].firstsortorder || 'asc'; } ts.p.page = 1; } if(sor) { if(ts.p.lastsort == idxcol && ts.p.sortorder == sor && !reload) { return; } else { ts.p.sortorder = sor; } } var previousSelectedTh = ts.grid.headers[ts.p.lastsort].el, newSelectedTh = ts.grid.headers[idxcol].el; $("span.ui-grid-ico-sort",previousSelectedTh).addClass('ui-state-disabled'); $(previousSelectedTh).attr("aria-selected","false"); $("span.ui-icon-"+ts.p.sortorder,newSelectedTh).removeClass('ui-state-disabled'); $(newSelectedTh).attr("aria-selected","true"); if(!ts.p.viewsortcols[0]) { if(ts.p.lastsort != idxcol) { $("span.s-ico",previousSelectedTh).hide(); $("span.s-ico",newSelectedTh).show(); } } index = index.substring(5 + ts.p.id.length + 1); // bad to be changed!?! ts.p.sortname = ts.p.colModel[idxcol].index || index; so = ts.p.sortorder; if ($(ts).triggerHandler("jqGridSortCol", [index, idxcol, so]) === 'stop') { ts.p.lastsort = idxcol; return; } if($.isFunction(ts.p.onSortCol)) {if (ts.p.onSortCol.call(ts,index,idxcol,so)=='stop') {ts.p.lastsort = idxcol; return;}} if(ts.p.datatype == "local") { if(ts.p.deselectAfterSort) {$(ts).jqGrid("resetSelection");} } else { ts.p.selrow = null; if(ts.p.multiselect){setHeadCheckBox( false );} ts.p.selarrrow =[]; ts.p.savedRow =[]; } if(ts.p.scroll) { var sscroll = ts.grid.bDiv.scrollLeft; emptyRows(ts.grid.bDiv,true, false); ts.grid.hDiv.scrollLeft = sscroll; } if(ts.p.subGrid && ts.p.datatype=='local') { $("td.sgexpanded","#"+$.jgrid.jqID(ts.p.id)).each(function(){ $(this).trigger("click"); }); } populate(); ts.p.lastsort = idxcol; if(ts.p.sortname != index && idxcol) {ts.p.lastsort = idxcol;} }, setColWidth = function () { var initwidth = 0, brd=isSafari? 0: intNum(ts.p.cellLayout,0), vc=0, lvc, scw=intNum(ts.p.scrollOffset,0),cw,hs=false,aw,gw=0, cl = 0, cr; $.each(ts.p.colModel, function() { if(typeof this.hidden === 'undefined') {this.hidden=false;} this.widthOrg = cw = intNum(this.width,0); if(this.hidden===false){ initwidth += cw+brd; if(this.fixed) { gw += cw+brd; } else { vc++; } cl++; } }); if(isNaN(ts.p.width)) {ts.p.width = grid.width = initwidth;} else { grid.width = ts.p.width;} ts.p.tblwidth = initwidth; if(ts.p.shrinkToFit ===false && ts.p.forceFit === true) {ts.p.forceFit=false;} if(ts.p.shrinkToFit===true && vc > 0) { aw = grid.width-brd*vc-gw; if(!isNaN(ts.p.height)) { aw -= scw; hs = true; } initwidth =0; $.each(ts.p.colModel, function(i) { if(this.hidden === false && !this.fixed){ cw = Math.round(aw*this.width/(ts.p.tblwidth-brd*vc-gw)); this.width =cw; initwidth += cw; lvc = i; } }); cr =0; if (hs) { if(grid.width-gw-(initwidth+brd*vc) !== scw){ cr = grid.width-gw-(initwidth+brd*vc)-scw; } } else if(!hs && Math.abs(grid.width-gw-(initwidth+brd*vc)) !== 1) { cr = grid.width-gw-(initwidth+brd*vc); } ts.p.colModel[lvc].width += cr; ts.p.tblwidth = initwidth+cr+brd*vc+gw; if(ts.p.tblwidth > ts.p.width) { ts.p.colModel[lvc].width -= (ts.p.tblwidth - parseInt(ts.p.width,10)); ts.p.tblwidth = ts.p.width; } } }, nextVisible= function(iCol) { var ret = iCol, j=iCol, i; for (i = iCol+1;i"); this.p.colModel.unshift({name:'cb',width:isSafari ? ts.p.multiselectWidth+ts.p.cellLayout : ts.p.multiselectWidth,sortable:false,resizable:false,hidedlg:true,search:false,align:'center',fixed:true}); } if(this.p.rownumbers) { this.p.colNames.unshift(""); this.p.colModel.unshift({name:'rn',width:ts.p.rownumWidth,sortable:false,resizable:false,hidedlg:true,search:false,align:'center',fixed:true}); } ts.p.xmlReader = $.extend(true,{ root: "rows", row: "row", page: "rows>page", total: "rows>total", records : "rows>records", repeatitems: true, cell: "cell", id: "[id]", userdata: "userdata", subgrid: {root:"rows", row: "row", repeatitems: true, cell:"cell"} }, ts.p.xmlReader); ts.p.jsonReader = $.extend(true,{ root: "rows", page: "page", total: "total", records: "records", repeatitems: true, cell: "cell", id: "id", userdata: "userdata", subgrid: {root:"rows", repeatitems: true, cell:"cell"} },ts.p.jsonReader); ts.p.localReader = $.extend(true,{ root: "rows", page: "page", total: "total", records: "records", repeatitems: false, cell: "cell", id: "id", userdata: "userdata", subgrid: {root:"rows", repeatitems: true, cell:"cell"} },ts.p.localReader); if(ts.p.scroll){ ts.p.pgbuttons = false; ts.p.pginput=false; ts.p.rowList=[]; } if(ts.p.data.length) { refreshIndex(); } var thead = "", tdc, idn, w, res, sort, td, ptr, tbody, imgs,iac="",idc=""; if(ts.p.shrinkToFit===true && ts.p.forceFit===true) { for (i=ts.p.colModel.length-1;i>=0;i--){ if(!ts.p.colModel[i].hidden) { ts.p.colModel[i].resizable=false; break; } } } if(ts.p.viewsortcols[1] == 'horizontal') {iac=" ui-i-asc";idc=" ui-i-desc";} tdc = isMSIE ? "class='ui-th-div-ie'" :""; imgs = ""; for(i=0;i"; idn = ts.p.colModel[i].index || ts.p.colModel[i].name; thead += "
"+ts.p.colNames[i]; if(!ts.p.colModel[i].width) { ts.p.colModel[i].width = 150; } else { ts.p.colModel[i].width = parseInt(ts.p.colModel[i].width,10); } if(typeof(ts.p.colModel[i].title) !== "boolean") { ts.p.colModel[i].title = true; } if (idn == ts.p.sortname) { ts.p.lastsort = i; } thead += imgs+"
"; } thead += ""; imgs = null; $(this).append(thead); $("thead tr:first th",this).hover(function(){$(this).addClass('ui-state-hover');},function(){$(this).removeClass('ui-state-hover');}); if(this.p.multiselect) { var emp=[], chk; $('#cb_'+$.jgrid.jqID(ts.p.id),this).bind('click',function(){ ts.p.selarrrow = []; var froz = ts.p.frozenColumns === true ? ts.p.id + "_frozen" : ""; if (this.checked) { $(ts.rows).each(function(i) { if (i>0) { if(!$(this).hasClass("ui-subgrid") && !$(this).hasClass("jqgroup") && !$(this).hasClass('ui-state-disabled')){ $("#jqg_"+$.jgrid.jqID(ts.p.id)+"_"+$.jgrid.jqID(this.id) )[ts.p.useProp ? 'prop': 'attr']("checked",true); $(this).addClass("ui-state-highlight").attr("aria-selected","true"); ts.p.selarrrow.push(this.id); ts.p.selrow = this.id; if(froz) { $("#jqg_"+$.jgrid.jqID(ts.p.id)+"_"+$.jgrid.jqID(this.id), ts.grid.fbDiv )[ts.p.useProp ? 'prop': 'attr']("checked",true); $("#"+$.jgrid.jqID(this.id), ts.grid.fbDiv).addClass("ui-state-highlight"); } } } }); chk=true; emp=[]; } else { $(ts.rows).each(function(i) { if(i>0) { if(!$(this).hasClass("ui-subgrid") && !$(this).hasClass('ui-state-disabled')){ $("#jqg_"+$.jgrid.jqID(ts.p.id)+"_"+$.jgrid.jqID(this.id) )[ts.p.useProp ? 'prop': 'attr']("checked", false); $(this).removeClass("ui-state-highlight").attr("aria-selected","false"); emp.push(this.id); if(froz) { $("#jqg_"+$.jgrid.jqID(ts.p.id)+"_"+$.jgrid.jqID(this.id), ts.grid.fbDiv )[ts.p.useProp ? 'prop': 'attr']("checked",false); $("#"+$.jgrid.jqID(this.id), ts.grid.fbDiv).removeClass("ui-state-highlight"); } } } }); ts.p.selrow = null; chk=false; } $(ts).triggerHandler("jqGridSelectAll", [chk ? ts.p.selarrrow : emp, chk]); if($.isFunction(ts.p.onSelectAll)) {ts.p.onSelectAll.call(ts, chk ? ts.p.selarrrow : emp,chk);} }); } if(ts.p.autowidth===true) { var pw = $(eg).innerWidth(); ts.p.width = pw > 0? pw: 'nw'; } setColWidth(); $(eg).css("width",grid.width+"px").append("
 
"); $(gv).css("width",grid.width+"px"); thead = $("thead:first",ts).get(0); var tfoot = ""; if(ts.p.footerrow) { tfoot += ""; } var thr = $("tr:first",thead), firstr = ""; ts.p.disableClick=false; $("th",thr).each(function ( j ) { w = ts.p.colModel[j].width; if(typeof ts.p.colModel[j].resizable === 'undefined') {ts.p.colModel[j].resizable = true;} if(ts.p.colModel[j].resizable){ res = document.createElement("span"); $(res).html(" ").addClass('ui-jqgrid-resize ui-jqgrid-resize-'+dir); if(!$.browser.opera) { $(res).css("cursor","col-resize"); } $(this).addClass(ts.p.resizeclass); } else { res = ""; } $(this).css("width",w+"px").prepend(res); var hdcol = ""; if( ts.p.colModel[j].hidden ) { $(this).css("display","none"); hdcol = "display:none;"; } firstr += ""; grid.headers[j] = { width: w, el: this }; sort = ts.p.colModel[j].sortable; if( typeof sort !== 'boolean') {ts.p.colModel[j].sortable = true; sort=true;} var nm = ts.p.colModel[j].name; if( !(nm == 'cb' || nm=='subgrid' || nm=='rn') ) { if(ts.p.viewsortcols[2]){ $(">div",this).addClass('ui-jqgrid-sortable'); } } if(sort) { if(ts.p.viewsortcols[0]) {$("div span.s-ico",this).show(); if(j==ts.p.lastsort){ $("div span.ui-icon-"+ts.p.sortorder,this).removeClass("ui-state-disabled");}} else if( j == ts.p.lastsort) {$("div span.s-ico",this).show();$("div span.ui-icon-"+ts.p.sortorder,this).removeClass("ui-state-disabled");} } if(ts.p.footerrow) { tfoot += ""; } }).mousedown(function(e) { if ($(e.target).closest("th>span.ui-jqgrid-resize").length != 1) { return; } var ci = getColumnHeaderIndex(this); if(ts.p.forceFit===true) {ts.p.nv= nextVisible(ci);} grid.dragStart(ci, e, getOffset(ci)); return false; }).click(function(e) { if (ts.p.disableClick) { ts.p.disableClick = false; return false; } var s = "th>div.ui-jqgrid-sortable",r,d; if (!ts.p.viewsortcols[2]) { s = "th>div>span>span.ui-grid-ico-sort"; } var t = $(e.target).closest(s); if (t.length != 1) { return; } var ci = getColumnHeaderIndex(this); if (!ts.p.viewsortcols[2]) { r=true;d=t.attr("sort"); } sortData( $('div',this)[0].id, ci, r, d); return false; }); if (ts.p.sortable && $.fn.sortable) { try { $(ts).jqGrid("sortableColumns", thr); } catch (e){} } if(ts.p.footerrow) { tfoot += "
 
"; } firstr += ""; tbody = document.createElement("tbody"); this.appendChild(tbody); $(this).addClass('ui-jqgrid-btable').append(firstr); firstr = null; var hTable = $("
").append(thead), hg = (ts.p.caption && ts.p.hiddengrid===true) ? true : false, hb = $("
"); thead = null; grid.hDiv = document.createElement("div"); $(grid.hDiv) .css({ width: grid.width+"px"}) .addClass("ui-state-default ui-jqgrid-hdiv") .append(hb); $(hb).append(hTable); hTable = null; if(hg) { $(grid.hDiv).hide(); } if(ts.p.pager){ // TBD -- escape ts.p.pager here? if(typeof ts.p.pager == "string") {if(ts.p.pager.substr(0,1) !="#") { ts.p.pager = "#"+ts.p.pager;} } else { ts.p.pager = "#"+ $(ts.p.pager).attr("id");} $(ts.p.pager).css({width: grid.width+"px"}).appendTo(eg).addClass('ui-state-default ui-jqgrid-pager ui-corner-bottom'); if(hg) {$(ts.p.pager).hide();} setPager(ts.p.pager,''); } if( ts.p.cellEdit === false && ts.p.hoverrows === true) { $(ts).bind('mouseover',function(e) { ptr = $(e.target).closest("tr.jqgrow"); if($(ptr).attr("class") !== "ui-subgrid") { $(ptr).addClass("ui-state-hover"); } }).bind('mouseout',function(e) { ptr = $(e.target).closest("tr.jqgrow"); $(ptr).removeClass("ui-state-hover"); }); } var ri,ci, tdHtml; $(ts).before(grid.hDiv).click(function(e) { td = e.target; ptr = $(td,ts.rows).closest("tr.jqgrow"); if($(ptr).length === 0 || ptr[0].className.indexOf( 'ui-state-disabled' ) > -1 || ($(td,ts).closest("table.ui-jqgrid-btable").attr('id') || '').replace("_frozen","") !== ts.id ) { return this; } var scb = $(td).hasClass("cbox"), cSel = $(ts).triggerHandler("jqGridBeforeSelectRow", [ptr[0].id, e]); cSel = (cSel === false || cSel === 'stop') ? false : true; if(cSel && $.isFunction(ts.p.beforeSelectRow)) { cSel = ts.p.beforeSelectRow.call(ts,ptr[0].id, e); } if (td.tagName == 'A' || ((td.tagName == 'INPUT' || td.tagName == 'TEXTAREA' || td.tagName == 'OPTION' || td.tagName == 'SELECT' ) && !scb) ) { return; } if(cSel === true) { ri = ptr[0].id; ci = $.jgrid.getCellIndex(td); tdHtml = $(td).closest("td,th").html(); $(ts).triggerHandler("jqGridCellSelect", [ri,ci,tdHtml,e]); if($.isFunction(ts.p.onCellSelect)) { ts.p.onCellSelect.call(ts,ri,ci,tdHtml,e); } if(ts.p.cellEdit === true) { if(ts.p.multiselect && scb){ $(ts).jqGrid("setSelection", ri ,true,e); } else { ri = ptr[0].rowIndex; try {$(ts).jqGrid("editCell",ri,ci,true);} catch (_) {} } } else if ( !ts.p.multikey ) { if(ts.p.multiselect && ts.p.multiboxonly) { if(scb){$(ts).jqGrid("setSelection",ri,true,e);} else { var frz = ts.p.frozenColumns ? ts.p.id+"_frozen" : ""; $(ts.p.selarrrow).each(function(i,n){ var ind = ts.rows.namedItem(n); $(ind).removeClass("ui-state-highlight"); $("#jqg_"+$.jgrid.jqID(ts.p.id)+"_"+$.jgrid.jqID(n))[ts.p.useProp ? 'prop': 'attr']("checked", false); if(frz) { $("#"+$.jgrid.jqID(n), "#"+$.jgrid.jqID(frz)).removeClass("ui-state-highlight"); $("#jqg_"+$.jgrid.jqID(ts.p.id)+"_"+$.jgrid.jqID(n), "#"+$.jgrid.jqID(frz))[ts.p.useProp ? 'prop': 'attr']("checked", false); } }); ts.p.selarrrow = []; $(ts).jqGrid("setSelection",ri,true,e); } } else { $(ts).jqGrid("setSelection",ri,true,e); } } else { if(e[ts.p.multikey]) { $(ts).jqGrid("setSelection",ri,true,e); } else if(ts.p.multiselect && scb) { scb = $("#jqg_"+$.jgrid.jqID(ts.p.id)+"_"+ri).is(":checked"); $("#jqg_"+$.jgrid.jqID(ts.p.id)+"_"+ri)[ts.p.useProp ? 'prop' : 'attr']("checked", scb); } } } }).bind('reloadGrid', function(e,opts) { if(ts.p.treeGrid ===true) { ts.p.datatype = ts.p.treedatatype;} if (opts && opts.current) { ts.grid.selectionPreserver(ts); } if(ts.p.datatype=="local"){ $(ts).jqGrid("resetSelection"); if(ts.p.data.length) { refreshIndex();} } else if(!ts.p.treeGrid) { ts.p.selrow=null; if(ts.p.multiselect) {ts.p.selarrrow =[];setHeadCheckBox(false);} ts.p.savedRow = []; } if(ts.p.scroll) {emptyRows(ts.grid.bDiv,true, false);} if (opts && opts.page) { var page = opts.page; if (page > ts.p.lastpage) { page = ts.p.lastpage; } if (page < 1) { page = 1; } ts.p.page = page; if (ts.grid.prevRowHeight) { ts.grid.bDiv.scrollTop = (page - 1) * ts.grid.prevRowHeight * ts.p.rowNum; } else { ts.grid.bDiv.scrollTop = 0; } } if (ts.grid.prevRowHeight && ts.p.scroll) { delete ts.p.lastpage; ts.grid.populateVisible(); } else { ts.grid.populate(); } return false; }) .dblclick(function(e) { td = e.target; ptr = $(td,ts.rows).closest("tr.jqgrow"); if($(ptr).length === 0 ){return;} ri = ptr[0].rowIndex; ci = $.jgrid.getCellIndex(td); $(ts).triggerHandler("jqGridDblClickRow", [$(ptr).attr("id"),ri,ci,e]); if ($.isFunction(this.p.ondblClickRow)) { ts.p.ondblClickRow.call(ts,$(ptr).attr("id"),ri,ci, e); } }) .bind('contextmenu', function(e) { td = e.target; ptr = $(td,ts.rows).closest("tr.jqgrow"); if($(ptr).length === 0 ){return;} if(!ts.p.multiselect) { $(ts).jqGrid("setSelection",ptr[0].id,true,e); } ri = ptr[0].rowIndex; ci = $.jgrid.getCellIndex(td); $(ts).triggerHandler("jqGridRightClickRow", [$(ptr).attr("id"),ri,ci,e]); if ($.isFunction(this.p.onRightClickRow)) { ts.p.onRightClickRow.call(ts,$(ptr).attr("id"),ri,ci, e); } }); grid.bDiv = document.createElement("div"); if(isMSIE) { if(String(ts.p.height).toLowerCase() === "auto") { ts.p.height = "100%"; } } $(grid.bDiv) .append($('
').append('
').append(this)) .addClass("ui-jqgrid-bdiv") .css({ height: ts.p.height+(isNaN(ts.p.height)?"":"px"), width: (grid.width)+"px"}) .scroll(grid.scrollGrid); $("table:first",grid.bDiv).css({width:ts.p.tblwidth+"px"}); if( isMSIE ) { if( $("tbody",this).size() == 2 ) { $("tbody:gt(0)",this).remove();} if( ts.p.multikey) {$(grid.bDiv).bind("selectstart",function(){return false;});} } else { if( ts.p.multikey) {$(grid.bDiv).bind("mousedown",function(){return false;});} } if(hg) {$(grid.bDiv).hide();} grid.cDiv = document.createElement("div"); var arf = ts.p.hidegrid===true ? $("").addClass('ui-jqgrid-titlebar-close HeaderButton').hover( function(){ arf.addClass('ui-state-hover');}, function() {arf.removeClass('ui-state-hover');}) .append("").css((dir=="rtl"?"left":"right"),"0px") : ""; $(grid.cDiv).append(arf).append(""+ts.p.caption+"") .addClass("ui-jqgrid-titlebar ui-widget-header ui-corner-top ui-helper-clearfix"); $(grid.cDiv).insertBefore(grid.hDiv); if( ts.p.toolbar[0] ) { grid.uDiv = document.createElement("div"); if(ts.p.toolbar[1] == "top") {$(grid.uDiv).insertBefore(grid.hDiv);} else if (ts.p.toolbar[1]=="bottom" ) {$(grid.uDiv).insertAfter(grid.hDiv);} if(ts.p.toolbar[1]=="both") { grid.ubDiv = document.createElement("div"); $(grid.uDiv).insertBefore(grid.hDiv).addClass("ui-userdata ui-state-default").attr("id","t_"+this.id); $(grid.ubDiv).insertAfter(grid.hDiv).addClass("ui-userdata ui-state-default").attr("id","tb_"+this.id); if(hg) {$(grid.ubDiv).hide();} } else { $(grid.uDiv).width(grid.width).addClass("ui-userdata ui-state-default").attr("id","t_"+this.id); } if(hg) {$(grid.uDiv).hide();} } if(ts.p.toppager) { ts.p.toppager = $.jgrid.jqID(ts.p.id)+"_toppager"; grid.topDiv = $("
")[0]; ts.p.toppager = "#"+ts.p.toppager; $(grid.topDiv).insertBefore(grid.hDiv).addClass('ui-state-default ui-jqgrid-toppager').width(grid.width); setPager(ts.p.toppager,'_t'); } if(ts.p.footerrow) { grid.sDiv = $("
")[0]; hb = $("
"); $(grid.sDiv).append(hb).insertAfter(grid.hDiv).width(grid.width); $(hb).append(tfoot); grid.footers = $(".ui-jqgrid-ftable",grid.sDiv)[0].rows[0].cells; if(ts.p.rownumbers) { grid.footers[0].className = 'ui-state-default jqgrid-rownum'; } if(hg) {$(grid.sDiv).hide();} } hb = null; if(ts.p.caption) { var tdt = ts.p.datatype; if(ts.p.hidegrid===true) { $(".ui-jqgrid-titlebar-close",grid.cDiv).click( function(e){ var onHdCl = $.isFunction(ts.p.onHeaderClick), elems = ".ui-jqgrid-bdiv, .ui-jqgrid-hdiv, .ui-jqgrid-pager, .ui-jqgrid-sdiv", counter, self = this; if(ts.p.toolbar[0]===true) { if( ts.p.toolbar[1]=='both') { elems += ', #' + $(grid.ubDiv).attr('id'); } elems += ', #' + $(grid.uDiv).attr('id'); } counter = $(elems,"#gview_"+$.jgrid.jqID(ts.p.id)).length; if(ts.p.gridstate == 'visible') { $(elems,"#gbox_"+$.jgrid.jqID(ts.p.id)).slideUp("fast", function() { counter--; if (counter === 0) { $("span",self).removeClass("ui-icon-circle-triangle-n").addClass("ui-icon-circle-triangle-s"); ts.p.gridstate = 'hidden'; if($("#gbox_"+$.jgrid.jqID(ts.p.id)).hasClass("ui-resizable")) { $(".ui-resizable-handle","#gbox_"+$.jgrid.jqID(ts.p.id)).hide(); } $(ts).triggerHandler("jqGridHeaderClick", [ts.p.gridstate,e]); if(onHdCl) {if(!hg) {ts.p.onHeaderClick.call(ts,ts.p.gridstate,e);}} } }); } else if(ts.p.gridstate == 'hidden'){ $(elems,"#gbox_"+$.jgrid.jqID(ts.p.id)).slideDown("fast", function() { counter--; if (counter === 0) { $("span",self).removeClass("ui-icon-circle-triangle-s").addClass("ui-icon-circle-triangle-n"); if(hg) {ts.p.datatype = tdt;populate();hg=false;} ts.p.gridstate = 'visible'; if($("#gbox_"+$.jgrid.jqID(ts.p.id)).hasClass("ui-resizable")) { $(".ui-resizable-handle","#gbox_"+$.jgrid.jqID(ts.p.id)).show(); } $(ts).triggerHandler("jqGridHeaderClick", [ts.p.gridstate,e]); if(onHdCl) {if(!hg) {ts.p.onHeaderClick.call(ts,ts.p.gridstate,e);}} } }); } return false; }); if(hg) {ts.p.datatype="local"; $(".ui-jqgrid-titlebar-close",grid.cDiv).trigger("click");} } } else {$(grid.cDiv).hide();} $(grid.hDiv).after(grid.bDiv) .mousemove(function (e) { if(grid.resizing){grid.dragMove(e);return false;} }); $(".ui-jqgrid-labels",grid.hDiv).bind("selectstart", function () { return false; }); $(document).mouseup(function () { if(grid.resizing) { grid.dragEnd(); return false;} return true; }); ts.formatCol = formatCol; ts.sortData = sortData; ts.updatepager = updatepager; ts.refreshIndex = refreshIndex; ts.setHeadCheckBox = setHeadCheckBox; ts.formatter = function ( rowId, cellval , colpos, rwdat, act){return formatter(rowId, cellval , colpos, rwdat, act);}; $.extend(grid,{populate : populate, emptyRows: emptyRows}); this.grid = grid; ts.addXmlData = function(d) {addXmlData(d,ts.grid.bDiv);}; ts.addJSONData = function(d) {addJSONData(d,ts.grid.bDiv);}; this.grid.cols = this.rows[0].cells; populate();ts.p.hiddengrid=false; $(window).unload(function () { ts = null; }); }); }; $.jgrid.extend({ getGridParam : function(pName) { var $t = this[0]; if (!$t || !$t.grid) {return;} if (!pName) { return $t.p; } else {return typeof($t.p[pName]) != "undefined" ? $t.p[pName] : null;} }, setGridParam : function (newParams){ return this.each(function(){ if (this.grid && typeof(newParams) === 'object') {$.extend(true,this.p,newParams);} }); }, getDataIDs : function () { var ids=[], i=0, len, j=0; this.each(function(){ len = this.rows.length; if(len && len>0){ while(i -1 ) { return; } function scrGrid(iR){ var ch = $($t.grid.bDiv)[0].clientHeight, st = $($t.grid.bDiv)[0].scrollTop, rpos = $t.rows[iR].offsetTop, rh = $t.rows[iR].clientHeight; if(rpos+rh >= ch+st) { $($t.grid.bDiv)[0].scrollTop = rpos-(ch+st)+rh+st; } else if(rpos < ch+st) { if(rpos < st) { $($t.grid.bDiv)[0].scrollTop = rpos; } } } if($t.p.scrollrows===true) { ner = $t.rows.namedItem(selection).rowIndex; if(ner >=0 ){ scrGrid(ner); } } if($t.p.frozenColumns === true ) { fid = $t.p.id+"_frozen"; } if(!$t.p.multiselect) { if(pt.className !== "ui-subgrid") { if( $t.p.selrow != pt.id) { $($t.rows.namedItem($t.p.selrow)).removeClass("ui-state-highlight").attr({"aria-selected":"false", "tabindex" : "-1"}); $(pt).addClass("ui-state-highlight").attr({"aria-selected":"true", "tabindex" : "0"});//.focus(); if(fid) { $("#"+$.jgrid.jqID($t.p.selrow), "#"+$.jgrid.jqID(fid)).removeClass("ui-state-highlight"); $("#"+$.jgrid.jqID(selection), "#"+$.jgrid.jqID(fid)).addClass("ui-state-highlight"); } stat = true; } else { stat = false; } $t.p.selrow = pt.id; $($t).triggerHandler("jqGridSelectRow", [pt.id, stat, e]); if( $t.p.onSelectRow && onsr) { $t.p.onSelectRow.call($t, pt.id, stat, e); } } } else { //unselect selectall checkbox when deselecting a specific row $t.setHeadCheckBox( false ); $t.p.selrow = pt.id; ia = $.inArray($t.p.selrow,$t.p.selarrrow); if ( ia === -1 ){ if(pt.className !== "ui-subgrid") { $(pt).addClass("ui-state-highlight").attr("aria-selected","true");} stat = true; $t.p.selarrrow.push($t.p.selrow); } else { if(pt.className !== "ui-subgrid") { $(pt).removeClass("ui-state-highlight").attr("aria-selected","false");} stat = false; $t.p.selarrrow.splice(ia,1); tpsr = $t.p.selarrrow[0]; $t.p.selrow = (tpsr === undefined) ? null : tpsr; } $("#jqg_"+$.jgrid.jqID($t.p.id)+"_"+$.jgrid.jqID(pt.id))[$t.p.useProp ? 'prop': 'attr']("checked",stat); if(fid) { if(ia === -1) { $("#"+$.jgrid.jqID(selection), "#"+$.jgrid.jqID(fid)).addClass("ui-state-highlight"); } else { $("#"+$.jgrid.jqID(selection), "#"+$.jgrid.jqID(fid)).removeClass("ui-state-highlight"); } $("#jqg_"+$.jgrid.jqID($t.p.id)+"_"+$.jgrid.jqID(selection), "#"+$.jgrid.jqID(fid))[$t.p.useProp ? 'prop': 'attr']("checked",stat); } $($t).triggerHandler("jqGridSelectRow", [pt.id, stat, e]); if( $t.p.onSelectRow && onsr) { $t.p.onSelectRow.call($t, pt.id , stat, e); } } }); }, resetSelection : function( rowid ){ return this.each(function(){ var t = this, ind, sr, fid; if( t.p.frozenColumns === true ) { fid = t.p.id+"_frozen"; } if(typeof(rowid) !== "undefined" ) { sr = rowid === t.p.selrow ? t.p.selrow : rowid; $("#"+$.jgrid.jqID(t.p.id)+" tbody:first tr#"+$.jgrid.jqID(sr)).removeClass("ui-state-highlight").attr("aria-selected","false"); if (fid) { $("#"+$.jgrid.jqID(sr), "#"+$.jgrid.jqID(fid)).removeClass("ui-state-highlight"); } if(t.p.multiselect) { $("#jqg_"+$.jgrid.jqID(t.p.id)+"_"+$.jgrid.jqID(sr), "#"+$.jgrid.jqID(t.p.id))[t.p.useProp ? 'prop': 'attr']("checked",false); if(fid) { $("#jqg_"+$.jgrid.jqID(t.p.id)+"_"+$.jgrid.jqID(sr), "#"+$.jgrid.jqID(fid))[t.p.useProp ? 'prop': 'attr']("checked",false); } t.setHeadCheckBox( false); } sr = null; } else if(!t.p.multiselect) { if(t.p.selrow) { $("#"+$.jgrid.jqID(t.p.id)+" tbody:first tr#"+$.jgrid.jqID(t.p.selrow)).removeClass("ui-state-highlight").attr("aria-selected","false"); if(fid) { $("#"+$.jgrid.jqID(t.p.selrow), "#"+$.jgrid.jqID(fid)).removeClass("ui-state-highlight"); } t.p.selrow = null; } } else { $(t.p.selarrrow).each(function(i,n){ ind = t.rows.namedItem(n); $(ind).removeClass("ui-state-highlight").attr("aria-selected","false"); $("#jqg_"+$.jgrid.jqID(t.p.id)+"_"+$.jgrid.jqID(n))[t.p.useProp ? 'prop': 'attr']("checked",false); if(fid) { $("#"+$.jgrid.jqID(n), "#"+$.jgrid.jqID(fid)).removeClass("ui-state-highlight"); $("#jqg_"+$.jgrid.jqID(t.p.id)+"_"+$.jgrid.jqID(n), "#"+$.jgrid.jqID(fid))[t.p.useProp ? 'prop': 'attr']("checked",false); } }); t.setHeadCheckBox( false ); t.p.selarrrow = []; } if(t.p.cellEdit === true) { if(parseInt(t.p.iCol,10)>=0 && parseInt(t.p.iRow,10)>=0) { $("td:eq("+t.p.iCol+")",t.rows[t.p.iRow]).removeClass("edit-cell ui-state-highlight"); $(t.rows[t.p.iRow]).removeClass("selected-row ui-state-hover"); } } t.p.savedRow = []; }); }, getRowData : function( rowid ) { var res = {}, resall, getall=false, len, j=0; this.each(function(){ var $t = this,nm,ind; if(typeof(rowid) == 'undefined') { getall = true; resall = []; len = $t.rows.length; } else { ind = $t.rows.namedItem(rowid); if(!ind) { return res; } len = 2; } while(j span:first",ind).html(vl).attr(title); } else { $("td:eq("+i+")",ind).html(vl).attr(title); } } }); if(t.p.datatype == 'local') { var id = $.jgrid.stripPref(t.p.idPrefix, rowid), pos = t.p._index[id]; if(t.p.treeGrid) { for(var key in t.p.treeReader ){ if(lcdata.hasOwnProperty(t.p.treeReader[key])) { delete lcdata[t.p.treeReader[key]]; } } } if(typeof(pos) != 'undefined') { t.p.data[pos] = $.extend(true, t.p.data[pos], lcdata); } lcdata = null; } } catch (e) { success = false; } } if(success) { if(cp === 'string') {$(ind).addClass(cssp);} else if(cp === 'object') {$(ind).css(cssp);} $(t).triggerHandler("jqGridAfterGridComplete"); } }); return success; }, addRowData : function(rowid,rdata,pos,src) { if(!pos) {pos = "last";} var success = false, nm, row, gi, si, ni,sind, i, v, prp="", aradd, cnm, cn, data, cm, id; if(rdata) { if($.isArray(rdata)) { aradd=true; pos = "last"; cnm = rowid; } else { rdata = [rdata]; aradd = false; } this.each(function() { var t = this, datalen = rdata.length; ni = t.p.rownumbers===true ? 1 :0; gi = t.p.multiselect ===true ? 1 :0; si = t.p.subGrid===true ? 1 :0; if(!aradd) { if(typeof(rowid) != 'undefined') { rowid = rowid+"";} else { rowid = $.jgrid.randId(); if(t.p.keyIndex !== false) { cnm = t.p.colModel[t.p.keyIndex+gi+si+ni].name; if(typeof rdata[0][cnm] != "undefined") { rowid = rdata[0][cnm]; } } } } cn = t.p.altclass; var k = 0, cna ="", lcdata = {}, air = $.isFunction(t.p.afterInsertRow) ? true : false; while(k < datalen) { data = rdata[k]; row=""; if(aradd) { try {rowid = data[cnm];} catch (e) {rowid = $.jgrid.randId();} cna = t.p.altRows === true ? (t.rows.length-1)%2 === 0 ? cn : "" : ""; } id = rowid; rowid = t.p.idPrefix + rowid; if(ni){ prp = t.formatCol(0,1,'',null,rowid, true); row += "0"; } if(gi) { v = ""; prp = t.formatCol(ni,1,'', null, rowid, true); row += ""+v+""; } if(si) { row += $(t).jqGrid("addSubGridCell",gi+ni,1); } for(i = gi+si+ni; i < t.p.colModel.length;i++){ cm = t.p.colModel[i]; nm = cm.name; lcdata[nm] = cm.formatter && typeof(cm.formatter) === 'string' && cm.formatter == 'date' ? $.unformat.date.call(t,data[nm],cm) : data[nm]; v = t.formatter( rowid, $.jgrid.getAccessor(data,nm), i, data, 'edit'); prp = t.formatCol(i,1,v, data, rowid, true); row += ""+v+""; } row = "" + row+""; if(t.rows.length === 0){ $("table:first",t.grid.bDiv).append(row); } else { switch (pos) { case 'last': $(t.rows[t.rows.length-1]).after(row); sind = t.rows.length-1; break; case 'first': $(t.rows[0]).after(row); sind = 1; break; case 'after': sind = t.rows.namedItem(src); if (sind) { if($(t.rows[sind.rowIndex+1]).hasClass("ui-subgrid")) { $(t.rows[sind.rowIndex+1]).after(row); } else { $(sind).after(row); } } sind++; break; case 'before': sind = t.rows.namedItem(src); if(sind) {$(sind).before(row);sind=sind.rowIndex;} sind--; break; } } if(t.p.subGrid===true) { $(t).jqGrid("addSubGrid",gi+ni, sind); } t.p.records++; t.p.reccount++; $(t).triggerHandler("jqGridAfterInsertRow", [rowid,data,data]); if(air) { t.p.afterInsertRow.call(t,rowid,data,data); } k++; if(t.p.datatype == 'local') { lcdata[t.p.localReader.id] = id; t.p._index[id] = t.p.data.length; t.p.data.push(lcdata); lcdata = {}; } } if( t.p.altRows === true && !aradd) { if (pos == "last") { if ((t.rows.length-1)%2 == 1) {$(t.rows[t.rows.length-1]).addClass(cn);} } else { $(t.rows).each(function(i){ if(i % 2 ==1) { $(this).addClass(cn); } else { $(this).removeClass(cn); } }); } } t.updatepager(true,true); success = true; }); } return success; }, footerData : function(action,data, format) { var nm, success=false, res={}, title; function isEmpty(obj) { for(var i in obj) { if (obj.hasOwnProperty(i)) { return false; } } return true; } if(typeof(action) == "undefined") { action = "get"; } if(typeof(format) != "boolean") { format = true; } action = action.toLowerCase(); this.each(function(){ var t = this, vl; if(!t.grid || !t.p.footerrow) {return false;} if(action == "set") { if(isEmpty(data)) { return false; } } success=true; $(this.p.colModel).each(function(i){ nm = this.name; if(action == "set") { if( data[nm] !== undefined) { vl = format ? t.formatter( "", data[nm], i, data, 'edit') : data[nm]; title = this.title ? {"title":$.jgrid.stripHtml(vl)} : {}; $("tr.footrow td:eq("+i+")",t.grid.sDiv).html(vl).attr(title); success = true; } } else if(action == "get") { res[nm] = $("tr.footrow td:eq("+i+")",t.grid.sDiv).html(); } }); }); return action == "get" ? res : success; }, showHideCol : function(colname,show) { return this.each(function() { var $t = this, fndh=false, brd=$.browser.webkit||$.browser.safari? 0: $t.p.cellLayout, cw; if (!$t.grid ) {return;} if( typeof colname === 'string') {colname=[colname];} show = show != "none" ? "" : "none"; var sw = show === "" ? true :false, gh = $t.p.groupHeader && (typeof $t.p.groupHeader === 'object' || $.isFunction($t.p.groupHeader) ); if(gh) { $($t).jqGrid('destroyGroupHeader', false); } $(this.p.colModel).each(function(i) { if ($.inArray(this.name,colname) !== -1 && this.hidden === sw) { if($t.p.frozenColumns === true && this.frozen === true) { return true; } $("tr",$t.grid.hDiv).each(function(){ $(this.cells[i]).css("display", show); }); $($t.rows).each(function(){ if (!$(this).hasClass("jqgroup")) { $(this.cells[i]).css("display", show); } }); if($t.p.footerrow) { $("tr.footrow td:eq("+i+")", $t.grid.sDiv).css("display", show); } cw = this.widthOrg? this.widthOrg: parseInt(this.width,10); if(show === "none") {$t.p.tblwidth -= cw+brd;} else {$t.p.tblwidth += cw+brd;} this.hidden = !sw; fndh=true; $($t).triggerHandler("jqGridShowHideCol", [sw,this.name,i]); } }); if(fndh===true) { $($t).jqGrid("setGridWidth",$t.p.shrinkToFit === true ? $t.p.tblwidth : $t.p.width ); } if( gh ) { $($t).jqGrid('setGroupHeaders',$t.p.groupHeader); } }); }, hideCol : function (colname) { return this.each(function(){$(this).jqGrid("showHideCol",colname,"none");}); }, showCol : function(colname) { return this.each(function(){$(this).jqGrid("showHideCol",colname,"");}); }, remapColumns : function(permutation, updateCells, keepHeader) { function resortArray(a) { var ac; if (a.length) { ac = $.makeArray(a); } else { ac = $.extend({}, a); } $.each(permutation, function(i) { a[i] = ac[this]; }); } var ts = this.get(0); function resortRows(parent, clobj) { $(">tr"+(clobj||""), parent).each(function() { var row = this; var elems = $.makeArray(row.cells); $.each(permutation, function() { var e = elems[this]; if (e) { row.appendChild(e); } }); }); } resortArray(ts.p.colModel); resortArray(ts.p.colNames); resortArray(ts.grid.headers); resortRows($("thead:first", ts.grid.hDiv), keepHeader && ":not(.ui-jqgrid-labels)"); if (updateCells) { resortRows($("#"+$.jgrid.jqID(ts.p.id)+" tbody:first"), ".jqgfirstrow, tr.jqgrow, tr.jqfoot"); } if (ts.p.footerrow) { resortRows($("tbody:first", ts.grid.sDiv)); } if (ts.p.remapColumns) { if (!ts.p.remapColumns.length){ ts.p.remapColumns = $.makeArray(permutation); } else { resortArray(ts.p.remapColumns); } } ts.p.lastsort = $.inArray(ts.p.lastsort, permutation); if(ts.p.treeGrid) { ts.p.expColInd = $.inArray(ts.p.expColInd, permutation); } $(ts).triggerHandler("jqGridRemapColumns", [permutation, updateCells, keepHeader]); }, setGridWidth : function(nwidth, shrink) { return this.each(function(){ if (!this.grid ) {return;} var $t = this, cw, initwidth = 0, brd=$.browser.webkit||$.browser.safari? 0: $t.p.cellLayout, lvc, vc=0, hs=false, scw=$t.p.scrollOffset, aw, gw=0, cl = 0,cr; if(typeof shrink != 'boolean') { shrink=$t.p.shrinkToFit; } if(isNaN(nwidth)) {return;} else { nwidth = parseInt(nwidth,10); $t.grid.width = $t.p.width = nwidth;} $("#gbox_"+$.jgrid.jqID($t.p.id)).css("width",nwidth+"px"); $("#gview_"+$.jgrid.jqID($t.p.id)).css("width",nwidth+"px"); $($t.grid.bDiv).css("width",nwidth+"px"); $($t.grid.hDiv).css("width",nwidth+"px"); if($t.p.pager ) {$($t.p.pager).css("width",nwidth+"px");} if($t.p.toppager ) {$($t.p.toppager).css("width",nwidth+"px");} if($t.p.toolbar[0] === true){ $($t.grid.uDiv).css("width",nwidth+"px"); if($t.p.toolbar[1]=="both") {$($t.grid.ubDiv).css("width",nwidth+"px");} } if($t.p.footerrow) { $($t.grid.sDiv).css("width",nwidth+"px"); } if(shrink ===false && $t.p.forceFit === true) {$t.p.forceFit=false;} if(shrink===true) { $.each($t.p.colModel, function() { if(this.hidden===false){ cw = this.widthOrg? this.widthOrg: parseInt(this.width,10); initwidth += cw+brd; if(this.fixed) { gw += cw+brd; } else { vc++; } cl++; } }); if(vc === 0) { return; } $t.p.tblwidth = initwidth; aw = nwidth-brd*vc-gw; if(!isNaN($t.p.height)) { if($($t.grid.bDiv)[0].clientHeight < $($t.grid.bDiv)[0].scrollHeight || $t.rows.length === 1){ hs = true; aw -= scw; } } initwidth =0; var cle = $t.grid.cols.length >0; $.each($t.p.colModel, function(i) { if(this.hidden === false && !this.fixed){ cw = this.widthOrg? this.widthOrg: parseInt(this.width,10); cw = Math.round(aw*cw/($t.p.tblwidth-brd*vc-gw)); if (cw < 0) { return; } this.width =cw; initwidth += cw; $t.grid.headers[i].width=cw; $t.grid.headers[i].el.style.width=cw+"px"; if($t.p.footerrow) { $t.grid.footers[i].style.width = cw+"px"; } if(cle) { $t.grid.cols[i].style.width = cw+"px"; } lvc = i; } }); if (!lvc) { return; } cr =0; if (hs) { if(nwidth-gw-(initwidth+brd*vc) !== scw){ cr = nwidth-gw-(initwidth+brd*vc)-scw; } } else if( Math.abs(nwidth-gw-(initwidth+brd*vc)) !== 1) { cr = nwidth-gw-(initwidth+brd*vc); } $t.p.colModel[lvc].width += cr; $t.p.tblwidth = initwidth+cr+brd*vc+gw; if($t.p.tblwidth > nwidth) { var delta = $t.p.tblwidth - parseInt(nwidth,10); $t.p.tblwidth = nwidth; cw = $t.p.colModel[lvc].width = $t.p.colModel[lvc].width-delta; } else { cw= $t.p.colModel[lvc].width; } $t.grid.headers[lvc].width = cw; $t.grid.headers[lvc].el.style.width=cw+"px"; if(cle) { $t.grid.cols[lvc].style.width = cw+"px"; } if($t.p.footerrow) { $t.grid.footers[lvc].style.width = cw+"px"; } } if($t.p.tblwidth) { $('table:first',$t.grid.bDiv).css("width",$t.p.tblwidth+"px"); $('table:first',$t.grid.hDiv).css("width",$t.p.tblwidth+"px"); $t.grid.hDiv.scrollLeft = $t.grid.bDiv.scrollLeft; if($t.p.footerrow) { $('table:first',$t.grid.sDiv).css("width",$t.p.tblwidth+"px"); } } }); }, setGridHeight : function (nh) { return this.each(function (){ var $t = this; if(!$t.grid) {return;} var bDiv = $($t.grid.bDiv); bDiv.css({height: nh+(isNaN(nh)?"":"px")}); if($t.p.frozenColumns === true){ //follow the original set height to use 16, better scrollbar width detection $('#'+$.jgrid.jqID($t.p.id)+"_frozen").parent().height(bDiv.height() - 16); } $t.p.height = nh; if ($t.p.scroll) { $t.grid.populateVisible(); } }); }, setCaption : function (newcap){ return this.each(function(){ this.p.caption=newcap; $("span.ui-jqgrid-title, span.ui-jqgrid-title-rtl",this.grid.cDiv).html(newcap); $(this.grid.cDiv).show(); }); }, setLabel : function(colname, nData, prop, attrp ){ return this.each(function(){ var $t = this, pos=-1; if(!$t.grid) {return;} if(typeof(colname) != "undefined") { $($t.p.colModel).each(function(i){ if (this.name == colname) { pos = i;return false; } }); } else { return; } if(pos>=0) { var thecol = $("tr.ui-jqgrid-labels th:eq("+pos+")",$t.grid.hDiv); if (nData){ var ico = $(".s-ico",thecol); $("[id^=jqgh_]",thecol).empty().html(nData).append(ico); $t.p.colNames[pos] = nData; } if (prop) { if(typeof prop === 'string') {$(thecol).addClass(prop);} else {$(thecol).css(prop);} } if(typeof attrp === 'object') {$(thecol).attr(attrp);} } }); }, setCell : function(rowid,colname,nData,cssp,attrp, forceupd) { return this.each(function(){ var $t = this, pos =-1,v, title; if(!$t.grid) {return;} if(isNaN(colname)) { $($t.p.colModel).each(function(i){ if (this.name == colname) { pos = i;return false; } }); } else {pos = parseInt(colname,10);} if(pos>=0) { var ind = $t.rows.namedItem(rowid); if (ind){ var tcell = $("td:eq("+pos+")",ind); if(nData !== "" || forceupd === true) { v = $t.formatter(rowid, nData, pos,ind,'edit'); title = $t.p.colModel[pos].title ? {"title":$.jgrid.stripHtml(v)} : {}; if($t.p.treeGrid && $(".tree-wrap",$(tcell)).length>0) { $("span",$(tcell)).html(v).attr(title); } else { $(tcell).html(v).attr(title); } if($t.p.datatype == "local") { var cm = $t.p.colModel[pos], index; nData = cm.formatter && typeof(cm.formatter) === 'string' && cm.formatter == 'date' ? $.unformat.date.call($t,nData,cm) : nData; index = $t.p._index[rowid]; if(typeof index != "undefined") { $t.p.data[index][cm.name] = nData; } } } if(typeof cssp === 'string'){ $(tcell).addClass(cssp); } else if(cssp) { $(tcell).css(cssp); } if(typeof attrp === 'object') {$(tcell).attr(attrp);} } } }); }, getCell : function(rowid,col) { var ret = false; this.each(function(){ var $t=this, pos=-1; if(!$t.grid) {return;} if(isNaN(col)) { $($t.p.colModel).each(function(i){ if (this.name === col) { pos = i;return false; } }); } else {pos = parseInt(col,10);} if(pos>=0) { var ind = $t.rows.namedItem(rowid); if(ind) { try { ret = $.unformat.call($t,$("td:eq("+pos+")",ind),{rowId:ind.id, colModel:$t.p.colModel[pos]},pos); } catch (e){ ret = $.jgrid.htmlDecode($("td:eq("+pos+")",ind).html()); } } } }); return ret; }, getCol : function (col, obj, mathopr) { var ret = [], val, sum=0, min, max, v; obj = typeof (obj) != 'boolean' ? false : obj; if(typeof mathopr == 'undefined') { mathopr = false; } this.each(function(){ var $t=this, pos=-1; if(!$t.grid) {return;} if(isNaN(col)) { $($t.p.colModel).each(function(i){ if (this.name === col) { pos = i;return false; } }); } else {pos = parseInt(col,10);} if(pos>=0) { var ln = $t.rows.length, i =0; if (ln && ln>0){ while(i= 0 ) { ret = this.p.data[ind]; } } }); return ret; } }); })(jQuery); ;(function($){ /* ** * jqGrid extension for cellediting 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 **/ /** * all events and options here are aded anonynous and not in the base grid * since the array is to big. Here is the order of execution. * From this point we use jQuery isFunction * formatCell * beforeEditCell, * onSelectCell (used only for noneditable cels) * afterEditCell, * beforeSaveCell, (called before validation of values if any) * beforeSubmitCell (if cellsubmit remote (ajax)) * afterSubmitCell(if cellsubmit remote (ajax)), * afterSaveCell, * errorCell, * serializeCellData - new * Options * cellsubmit (remote,clientArray) (added in grid options) * cellurl * ajaxCellOptions * */ "use strict"; $.jgrid.extend({ editCell : function (iRow,iCol, ed){ return this.each(function (){ var $t = this, nm, tmp,cc, cm; if (!$t.grid || $t.p.cellEdit !== true) {return;} iCol = parseInt(iCol,10); // select the row that can be used for other methods $t.p.selrow = $t.rows[iRow].id; if (!$t.p.knv) {$($t).jqGrid("GridNav");} // check to see if we have already edited cell if ($t.p.savedRow.length>0) { // prevent second click on that field and enable selects if (ed===true ) { if(iRow == $t.p.iRow && iCol == $t.p.iCol){ return; } } // save the cell $($t).jqGrid("saveCell",$t.p.savedRow[0].id,$t.p.savedRow[0].ic); } else { window.setTimeout(function () { $("#"+$.jgrid.jqID($t.p.knv)).attr("tabindex","-1").focus();},0); } cm = $t.p.colModel[iCol]; nm = cm.name; if (nm=='subgrid' || nm=='cb' || nm=='rn') {return;} cc = $("td:eq("+iCol+")",$t.rows[iRow]); if (cm.editable===true && ed===true && !cc.hasClass("not-editable-cell")) { if(parseInt($t.p.iCol,10)>=0 && parseInt($t.p.iRow,10)>=0) { $("td:eq("+$t.p.iCol+")",$t.rows[$t.p.iRow]).removeClass("edit-cell ui-state-highlight"); $($t.rows[$t.p.iRow]).removeClass("selected-row ui-state-hover"); } $(cc).addClass("edit-cell ui-state-highlight"); $($t.rows[iRow]).addClass("selected-row ui-state-hover"); try { tmp = $.unformat.call($t,cc,{rowId: $t.rows[iRow].id, colModel:cm},iCol); } catch (_) { tmp = ( cm.edittype && cm.edittype == 'textarea' ) ? $(cc).text() : $(cc).html(); } if($t.p.autoencode) { tmp = $.jgrid.htmlDecode(tmp); } if (!cm.edittype) {cm.edittype = "text";} $t.p.savedRow.push({id:iRow,ic:iCol,name:nm,v:tmp}); if(tmp === " " || tmp === " " || (tmp.length===1 && tmp.charCodeAt(0)===160) ) {tmp='';} if($.isFunction($t.p.formatCell)) { var tmp2 = $t.p.formatCell.call($t, $t.rows[iRow].id,nm,tmp,iRow,iCol); if(tmp2 !== undefined ) {tmp = tmp2;} } var opt = $.extend({}, cm.editoptions || {} ,{id:iRow+"_"+nm,name:nm}); var elc = $.jgrid.createEl(cm.edittype,opt,tmp,true,$.extend({},$.jgrid.ajaxOptions,$t.p.ajaxSelectOptions || {})); $($t).triggerHandler("jqGridBeforeEditCell", [$t.rows[iRow].id, nm, tmp, iRow, iCol]); if ($.isFunction($t.p.beforeEditCell)) { $t.p.beforeEditCell.call($t, $t.rows[iRow].id,nm,tmp,iRow,iCol); } $(cc).html("").append(elc).attr("tabindex","0"); window.setTimeout(function () { $(elc).focus();},0); $("input, select, textarea",cc).bind("keydown",function(e) { if (e.keyCode === 27) { if($("input.hasDatepicker",cc).length >0) { if( $(".ui-datepicker").is(":hidden") ) { $($t).jqGrid("restoreCell",iRow,iCol); } else { $("input.hasDatepicker",cc).datepicker('hide'); } } else { $($t).jqGrid("restoreCell",iRow,iCol); } } //ESC if (e.keyCode === 13) { $($t).jqGrid("saveCell",iRow,iCol); // Prevent default action return false; } //Enter if (e.keyCode === 9) { if(!$t.grid.hDiv.loading ) { if (e.shiftKey) {$($t).jqGrid("prevCell",iRow,iCol);} //Shift TAb else {$($t).jqGrid("nextCell",iRow,iCol);} //Tab } else { return false; } } e.stopPropagation(); }); $($t).triggerHandler("jqGridAfterEditCell", [$t.rows[iRow].id, nm, tmp, iRow, iCol]); if ($.isFunction($t.p.afterEditCell)) { $t.p.afterEditCell.call($t, $t.rows[iRow].id,nm,tmp,iRow,iCol); } } else { if (parseInt($t.p.iCol,10)>=0 && parseInt($t.p.iRow,10)>=0) { $("td:eq("+$t.p.iCol+")",$t.rows[$t.p.iRow]).removeClass("edit-cell ui-state-highlight"); $($t.rows[$t.p.iRow]).removeClass("selected-row ui-state-hover"); } cc.addClass("edit-cell ui-state-highlight"); $($t.rows[iRow]).addClass("selected-row ui-state-hover"); tmp = cc.html().replace(/\ \;/ig,''); $($t).triggerHandler("jqGridSelectCell", [$t.rows[iRow].id, nm, tmp, iRow, iCol]); if ($.isFunction($t.p.onSelectCell)) { $t.p.onSelectCell.call($t, $t.rows[iRow].id,nm,tmp,iRow,iCol); } } $t.p.iCol = iCol; $t.p.iRow = iRow; }); }, saveCell : function (iRow, iCol){ return this.each(function(){ var $t= this, fr; if (!$t.grid || $t.p.cellEdit !== true) {return;} if ( $t.p.savedRow.length >= 1) {fr = 0;} else {fr=null;} if(fr !== null) { var cc = $("td:eq("+iCol+")",$t.rows[iRow]),v,v2, cm = $t.p.colModel[iCol], nm = cm.name, nmjq = $.jgrid.jqID(nm) ; switch (cm.edittype) { case "select": if(!cm.editoptions.multiple) { v = $("#"+iRow+"_"+nmjq+" option:selected",$t.rows[iRow]).val(); v2 = $("#"+iRow+"_"+nmjq+" option:selected",$t.rows[iRow]).text(); } else { var sel = $("#"+iRow+"_"+nmjq,$t.rows[iRow]), selectedText = []; v = $(sel).val(); if(v) { v.join(",");} else { v=""; } $("option:selected",sel).each( function(i,selected){ selectedText[i] = $(selected).text(); } ); v2 = selectedText.join(","); } if(cm.formatter) { v2 = v; } break; case "checkbox": var cbv = ["Yes","No"]; if(cm.editoptions){ cbv = cm.editoptions.value.split(":"); } v = $("#"+iRow+"_"+nmjq,$t.rows[iRow]).is(":checked") ? cbv[0] : cbv[1]; v2=v; break; case "password": case "text": case "textarea": case "button" : v = $("#"+iRow+"_"+nmjq,$t.rows[iRow]).val(); v2=v; break; case 'custom' : try { if(cm.editoptions && $.isFunction(cm.editoptions.custom_value)) { v = cm.editoptions.custom_value.call($t, $(".customelement",cc),'get'); if (v===undefined) { throw "e2";} else { v2=v; } } else { throw "e1"; } } catch (e) { if (e=="e1") { $.jgrid.info_dialog(jQuery.jgrid.errors.errcap,"function 'custom_value' "+$.jgrid.edit.msg.nodefined,jQuery.jgrid.edit.bClose); } if (e=="e2") { $.jgrid.info_dialog(jQuery.jgrid.errors.errcap,"function 'custom_value' "+$.jgrid.edit.msg.novalue,jQuery.jgrid.edit.bClose); } else {$.jgrid.info_dialog(jQuery.jgrid.errors.errcap,e.message,jQuery.jgrid.edit.bClose); } } break; } // The common approach is if nothing changed do not do anything if (v2 !== $t.p.savedRow[fr].v){ var vvv = $($t).triggerHandler("jqGridBeforeSaveCell", [$t.rows[iRow].id, nm, v, iRow, iCol]); if (vvv) {v = vvv; v2=vvv;} if ($.isFunction($t.p.beforeSaveCell)) { var vv = $t.p.beforeSaveCell.call($t, $t.rows[iRow].id,nm, v, iRow,iCol); if (vv) {v = vv; v2=vv;} } var cv = $.jgrid.checkValues(v,iCol,$t); if(cv[0] === true) { var addpost = $($t).triggerHandler("jqGridBeforeSubmitCell", [$t.rows[iRow].id, nm, v, iRow, iCol]) || {}; if ($.isFunction($t.p.beforeSubmitCell)) { addpost = $t.p.beforeSubmitCell.call($t, $t.rows[iRow].id,nm, v, iRow,iCol); if (!addpost) {addpost={};} } if( $("input.hasDatepicker",cc).length >0) { $("input.hasDatepicker",cc).datepicker('hide'); } if ($t.p.cellsubmit == 'remote') { if ($t.p.cellurl) { var postdata = {}; if($t.p.autoencode) { v = $.jgrid.htmlEncode(v); } postdata[nm] = v; var idname,oper, opers; opers = $t.p.prmNames; idname = opers.id; oper = opers.oper; postdata[idname] = $.jgrid.stripPref($t.p.idPrefix, $t.rows[iRow].id); postdata[oper] = opers.editoper; postdata = $.extend(addpost,postdata); $("#lui_"+$.jgrid.jqID($t.p.id)).show(); $t.grid.hDiv.loading = true; $.ajax( $.extend( { url: $t.p.cellurl, data :$.isFunction($t.p.serializeCellData) ? $t.p.serializeCellData.call($t, postdata) : postdata, type: "POST", complete: function (result, stat) { $("#lui_"+$t.p.id).hide(); $t.grid.hDiv.loading = false; if (stat == 'success') { var ret = $($t).triggerHandler("jqGridAfterSubmitCell", [$t, result, postdata.id, nm, v, iRow, iCol]) || [true, '']; if (ret[0] === true && $.isFunction($t.p.afterSubmitCell)) { ret = $t.p.afterSubmitCell.call($t, result,postdata.id,nm,v,iRow,iCol); } if(ret[0] === true){ $(cc).empty(); $($t).jqGrid("setCell",$t.rows[iRow].id, iCol, v2, false, false, true); $(cc).addClass("dirty-cell"); $($t.rows[iRow]).addClass("edited"); $($t).triggerHandler("jqGridAfterSaveCell", [$t.rows[iRow].id, nm, v, iRow, iCol]); if ($.isFunction($t.p.afterSaveCell)) { $t.p.afterSaveCell.call($t, $t.rows[iRow].id,nm, v, iRow,iCol); } $t.p.savedRow.splice(0,1); } else { $.jgrid.info_dialog($.jgrid.errors.errcap,ret[1],$.jgrid.edit.bClose); $($t).jqGrid("restoreCell",iRow,iCol); } } }, error:function(res,stat,err) { $("#lui_"+$.jgrid.jqID($t.p.id)).hide(); $t.grid.hDiv.loading = false; $($t).triggerHandler("jqGridErrorCell", [res, stat, err]); if ($.isFunction($t.p.errorCell)) { $t.p.errorCell.call($t, res,stat,err); $($t).jqGrid("restoreCell",iRow,iCol); } else { $.jgrid.info_dialog($.jgrid.errors.errcap,res.status+" : "+res.statusText+"
"+stat,$.jgrid.edit.bClose); $($t).jqGrid("restoreCell",iRow,iCol); } } }, $.jgrid.ajaxOptions, $t.p.ajaxCellOptions || {})); } else { try { $.jgrid.info_dialog($.jgrid.errors.errcap,$.jgrid.errors.nourl,$.jgrid.edit.bClose); $($t).jqGrid("restoreCell",iRow,iCol); } catch (e) {} } } if ($t.p.cellsubmit == 'clientArray') { $(cc).empty(); $($t).jqGrid("setCell",$t.rows[iRow].id,iCol, v2, false, false, true); $(cc).addClass("dirty-cell"); $($t.rows[iRow]).addClass("edited"); $($t).triggerHandler("jqGridAfterSaveCell", [$t.rows[iRow].id, nm, v, iRow, iCol]); if ($.isFunction($t.p.afterSaveCell)) { $t.p.afterSaveCell.call($t, $t.rows[iRow].id,nm, v, iRow,iCol); } $t.p.savedRow.splice(0,1); } } else { try { window.setTimeout(function(){$.jgrid.info_dialog($.jgrid.errors.errcap,v+" "+cv[1],$.jgrid.edit.bClose);},100); $($t).jqGrid("restoreCell",iRow,iCol); } catch (e) {} } } else { $($t).jqGrid("restoreCell",iRow,iCol); } } if ($.browser.opera) { $("#"+$.jgrid.jqID($t.p.knv)).attr("tabindex","-1").focus(); } else { window.setTimeout(function () { $("#"+$.jgrid.jqID($t.p.knv)).attr("tabindex","-1").focus();},0); } }); }, restoreCell : function(iRow, iCol) { return this.each(function(){ var $t= this, fr; if (!$t.grid || $t.p.cellEdit !== true ) {return;} if ( $t.p.savedRow.length >= 1) {fr = 0;} else {fr=null;} if(fr !== null) { var cc = $("td:eq("+iCol+")",$t.rows[iRow]); // datepicker fix if($.isFunction($.fn.datepicker)) { try { $("input.hasDatepicker",cc).datepicker('hide'); } catch (e) {} } $(cc).empty().attr("tabindex","-1"); $($t).jqGrid("setCell",$t.rows[iRow].id, iCol, $t.p.savedRow[fr].v, false, false, true); $($t).triggerHandler("jqGridAfterRestoreCell", [$t.rows[iRow].id, $t.p.savedRow[fr].v, iRow, iCol]); if ($.isFunction($t.p.afterRestoreCell)) { $t.p.afterRestoreCell.call($t, $t.rows[iRow].id, $t.p.savedRow[fr].v, iRow, iCol); } $t.p.savedRow.splice(0,1); } window.setTimeout(function () { $("#"+$t.p.knv).attr("tabindex","-1").focus();},0); }); }, nextCell : function (iRow,iCol) { return this.each(function (){ var $t = this, nCol=false; if (!$t.grid || $t.p.cellEdit !== true) {return;} // try to find next editable cell for (var i=iCol+1; i<$t.p.colModel.length; i++) { if ( $t.p.colModel[i].editable ===true) { nCol = i; break; } } if(nCol !== false) { $($t).jqGrid("editCell",iRow,nCol,true); } else { if ($t.p.savedRow.length >0) { $($t).jqGrid("saveCell",iRow,iCol); } } }); }, prevCell : function (iRow,iCol) { return this.each(function (){ var $t = this, nCol=false; if (!$t.grid || $t.p.cellEdit !== true) {return;} // try to find next editable cell for (var i=iCol-1; i>=0; i--) { if ( $t.p.colModel[i].editable ===true) { nCol = i; break; } } if(nCol !== false) { $($t).jqGrid("editCell",iRow,nCol,true); } else { if ($t.p.savedRow.length >0) { $($t).jqGrid("saveCell",iRow,iCol); } } }); }, GridNav : function() { return this.each(function () { var $t = this; if (!$t.grid || $t.p.cellEdit !== true ) {return;} // trick to process keydown on non input elements $t.p.knv = $t.p.id + "_kn"; var selection = $(""), i, kdir; function scrollGrid(iR, iC, tp){ if (tp.substr(0,1)=='v') { var ch = $($t.grid.bDiv)[0].clientHeight, st = $($t.grid.bDiv)[0].scrollTop, nROT = $t.rows[iR].offsetTop+$t.rows[iR].clientHeight, pROT = $t.rows[iR].offsetTop; if(tp == 'vd') { if(nROT >= ch) { $($t.grid.bDiv)[0].scrollTop = $($t.grid.bDiv)[0].scrollTop + $t.rows[iR].clientHeight; } } if(tp == 'vu'){ if (pROT < st ) { $($t.grid.bDiv)[0].scrollTop = $($t.grid.bDiv)[0].scrollTop - $t.rows[iR].clientHeight; } } } if(tp=='h') { var cw = $($t.grid.bDiv)[0].clientWidth, sl = $($t.grid.bDiv)[0].scrollLeft, nCOL = $t.rows[iR].cells[iC].offsetLeft+$t.rows[iR].cells[iC].clientWidth, pCOL = $t.rows[iR].cells[iC].offsetLeft; if(nCOL >= cw+parseInt(sl,10)) { $($t.grid.bDiv)[0].scrollLeft = $($t.grid.bDiv)[0].scrollLeft + $t.rows[iR].cells[iC].clientWidth; } else if (pCOL < sl) { $($t.grid.bDiv)[0].scrollLeft = $($t.grid.bDiv)[0].scrollLeft - $t.rows[iR].cells[iC].clientWidth; } } } function findNextVisible(iC,act){ var ind, i; if(act == 'lft') { ind = iC+1; for (i=iC;i>=0;i--){ if ($t.p.colModel[i].hidden !== true) { ind = i; break; } } } if(act == 'rgt') { ind = iC-1; for (i=iC; i<$t.p.colModel.length;i++){ if ($t.p.colModel[i].hidden !== true) { ind = i; break; } } } return ind; } $(selection).insertBefore($t.grid.cDiv); $("#"+$t.p.knv) .focus() .keydown(function (e){ kdir = e.keyCode; if($t.p.direction == "rtl") { if(kdir===37) { kdir = 39;} else if (kdir===39) { kdir = 37; } } switch (kdir) { case 38: if ($t.p.iRow-1 >0 ) { scrollGrid($t.p.iRow-1,$t.p.iCol,'vu'); $($t).jqGrid("editCell",$t.p.iRow-1,$t.p.iCol,false); } break; case 40 : if ($t.p.iRow+1 <= $t.rows.length-1) { scrollGrid($t.p.iRow+1,$t.p.iCol,'vd'); $($t).jqGrid("editCell",$t.p.iRow+1,$t.p.iCol,false); } break; case 37 : if ($t.p.iCol -1 >= 0) { i = findNextVisible($t.p.iCol-1,'lft'); scrollGrid($t.p.iRow, i,'h'); $($t).jqGrid("editCell",$t.p.iRow, i,false); } break; case 39 : if ($t.p.iCol +1 <= $t.p.colModel.length-1) { i = findNextVisible($t.p.iCol+1,'rgt'); scrollGrid($t.p.iRow,i,'h'); $($t).jqGrid("editCell",$t.p.iRow,i,false); } break; case 13: if (parseInt($t.p.iCol,10)>=0 && parseInt($t.p.iRow,10)>=0) { $($t).jqGrid("editCell",$t.p.iRow,$t.p.iCol,true); } break; default : return true; } return false; }); }); }, getChangedCells : function (mthd) { var ret=[]; if (!mthd) {mthd='all';} this.each(function(){ var $t= this,nm; if (!$t.grid || $t.p.cellEdit !== true ) {return;} $($t.rows).each(function(j){ var res = {}; if ($(this).hasClass("edited")) { $('td',this).each( function(i) { nm = $t.p.colModel[i].name; if ( nm !== 'cb' && nm !== 'subgrid') { if (mthd=='dirty') { if ($(this).hasClass('dirty-cell')) { try { res[nm] = $.unformat.call($t,this,{rowId:$t.rows[j].id, colModel:$t.p.colModel[i]},i); } catch (e){ res[nm] = $.jgrid.htmlDecode($(this).html()); } } } else { try { res[nm] = $.unformat.call($t,this,{rowId:$t.rows[j].id,colModel:$t.p.colModel[i]},i); } catch (e) { res[nm] = $.jgrid.htmlDecode($(this).html()); } } } }); res.id = this.id; ret.push(res); } }); }); return ret; } /// end cell editing }); })(jQuery); ;(function($){ /* * jqGrid common function * 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 */ /*global jQuery, $ */ $.extend($.jgrid,{ // Modal functions showModal : function(h) { h.w.show(); }, closeModal : function(h) { h.w.hide().attr("aria-hidden","true"); if(h.o) {h.o.remove();} }, hideModal : function (selector,o) { o = $.extend({jqm : true, gb :''}, o || {}); if(o.onClose) { var oncret = o.onClose(selector); if (typeof oncret == 'boolean' && !oncret ) { return; } } if ($.fn.jqm && o.jqm === true) { $(selector).attr("aria-hidden","true").jqmHide(); } else { if(o.gb !== '') { try {$(".jqgrid-overlay:first",o.gb).hide();} catch (e){} } $(selector).hide().attr("aria-hidden","true"); } }, //Helper functions findPos : function(obj) { var curleft = 0, curtop = 0; if (obj.offsetParent) { do { curleft += obj.offsetLeft; curtop += obj.offsetTop; } while (obj = obj.offsetParent); //do not change obj == obj.offsetParent } return [curleft,curtop]; }, createModal : function(aIDs, content, p, insertSelector, posSelector, appendsel, css) { var mw = document.createElement('div'), rtlsup, self = this; css = $.extend({}, css || {}); rtlsup = $(p.gbox).attr("dir") == "rtl" ? true : false; mw.className= "ui-widget ui-widget-content ui-corner-all ui-jqdialog"; mw.id = aIDs.themodal; var mh = document.createElement('div'); mh.className = "ui-jqdialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix"; mh.id = aIDs.modalhead; $(mh).append(""+p.caption+""); var ahr= $("
") .hover(function(){ahr.addClass('ui-state-hover');}, function(){ahr.removeClass('ui-state-hover');}) .append(""); $(mh).append(ahr); if(rtlsup) { mw.dir = "rtl"; $(".ui-jqdialog-title",mh).css("float","right"); $(".ui-jqdialog-titlebar-close",mh).css("left",0.3+"em"); } else { mw.dir = "ltr"; $(".ui-jqdialog-title",mh).css("float","left"); $(".ui-jqdialog-titlebar-close",mh).css("right",0.3+"em"); } var mc = document.createElement('div'); $(mc).addClass("ui-jqdialog-content ui-widget-content").attr("id",aIDs.modalcontent); $(mc).append(content); mw.appendChild(mc); $(mw).prepend(mh); if(appendsel===true) { $('body').append(mw); } //append as first child in body -for alert dialog else if (typeof appendsel == "string") $(appendsel).append(mw); else {$(mw).insertBefore(insertSelector);} $(mw).css(css); if(typeof p.jqModal === 'undefined') {p.jqModal = true;} // internal use var coord = {}; if ( $.fn.jqm && p.jqModal === true) { if(p.left ===0 && p.top===0 && p.overlay) { var pos = []; pos = this.findPos(posSelector); p.left = pos[0] + 4; p.top = pos[1] + 4; } coord.top = p.top+"px"; coord.left = p.left; } else if(p.left !==0 || p.top!==0) { coord.left = p.left; coord.top = p.top+"px"; } $("a.ui-jqdialog-titlebar-close",mh).click(function(){ var oncm = $("#"+$.jgrid.jqID(aIDs.themodal)).data("onClose") || p.onClose; var gboxclose = $("#"+$.jgrid.jqID(aIDs.themodal)).data("gbox") || p.gbox; self.hideModal("#"+$.jgrid.jqID(aIDs.themodal),{gb:gboxclose,jqm:p.jqModal,onClose:oncm}); return false; }); if (p.width === 0 || !p.width) {p.width = 300;} if(p.height === 0 || !p.height) {p.height =200;} if(!p.zIndex) { var parentZ = $(insertSelector).parents("*[role=dialog]").filter(':first').css("z-index"); if(parentZ) { p.zIndex = parseInt(parentZ,10)+2; } else { p.zIndex = 950; } } var rtlt = 0; if( rtlsup && coord.left && !appendsel) { rtlt = $(p.gbox).width()- (!isNaN(p.width) ? parseInt(p.width,10) :0) - 8; // to do // just in case coord.left = parseInt(coord.left,10) + parseInt(rtlt,10); } if(coord.left) { coord.left += "px"; } $(mw).css($.extend({ width: isNaN(p.width) ? "auto": p.width+"px", height:isNaN(p.height) ? "auto" : p.height + "px", zIndex:p.zIndex, overflow: 'hidden' },coord)) .attr({tabIndex: "-1","role":"dialog","aria-labelledby":aIDs.modalhead,"aria-hidden":"true"}); if(typeof p.drag == 'undefined') { p.drag=true;} if(typeof p.resize == 'undefined') {p.resize=true;} if (p.drag) { $(mh).css('cursor','move'); if($.fn.jqDrag) { $(mw).jqDrag(mh); } else { try { $(mw).draggable({handle: $("#"+$.jgrid.jqID(mh.id))}); } catch (e) {} } } if(p.resize) { if($.fn.jqResize) { $(mw).append("
"); $("#"+$.jgrid.jqID(aIDs.themodal)).jqResize(".jqResize",aIDs.scrollelm ? "#"+$.jgrid.jqID(aIDs.scrollelm) : false); } else { try { $(mw).resizable({handles: 'se, sw',alsoResize: aIDs.scrollelm ? "#"+$.jgrid.jqID(aIDs.scrollelm) : false}); } catch (r) {} } } if(p.closeOnEscape === true){ $(mw).keydown( function( e ) { if( e.which == 27 ) { var cone = $("#"+$.jgrid.jqID(aIDs.themodal)).data("onClose") || p.onClose; self.hideModal(this,{gb:p.gbox,jqm:p.jqModal,onClose: cone}); } }); } }, viewModal : function (selector,o){ o = $.extend({ toTop: true, overlay: 10, modal: false, overlayClass : 'ui-widget-overlay', onShow: this.showModal, onHide: this.closeModal, gbox: '', jqm : true, jqM : true }, o || {}); if ($.fn.jqm && o.jqm === true) { if(o.jqM) { $(selector).attr("aria-hidden","false").jqm(o).jqmShow(); } else {$(selector).attr("aria-hidden","false").jqmShow();} } else { if(o.gbox !== '') { $(".jqgrid-overlay:first",o.gbox).show(); $(selector).data("gbox",o.gbox); } $(selector).show().attr("aria-hidden","false"); try{$(':input:visible',selector)[0].focus();}catch(_){} } }, info_dialog : function(caption, content,c_b, modalopt) { var mopt = { width:290, height:'auto', dataheight: 'auto', drag: true, resize: false, caption:""+caption+"", left:250, top:170, zIndex : 1000, jqModal : true, modal : false, closeOnEscape : true, align: 'center', buttonalign : 'center', buttons : [] // {text:'textbutt', id:"buttid", onClick : function(){...}} // if the id is not provided we set it like info_button_+ the index in the array - i.e info_button_0,info_button_1... }; $.extend(mopt,modalopt || {}); var jm = mopt.jqModal, self = this; if($.fn.jqm && !jm) { jm = false; } // in case there is no jqModal var buttstr =""; if(mopt.buttons.length > 0) { for(var i=0;i"+mopt.buttons[i].text+""; } } var dh = isNaN(mopt.dataheight) ? mopt.dataheight : mopt.dataheight+"px", cn = "text-align:"+mopt.align+";"; var cnt = "
"; cnt += "
"+content+"
"; cnt += c_b ? "
"+c_b+""+buttstr+"
" : buttstr !== "" ? "
"+buttstr+"
" : ""; cnt += "
"; try { if($("#info_dialog").attr("aria-hidden") == "false") { this.hideModal("#info_dialog",{jqm:jm}); } $("#info_dialog").remove(); } catch (e){} this.createModal({ themodal:'info_dialog', modalhead:'info_head', modalcontent:'info_content', scrollelm: 'infocnt'}, cnt, mopt, '','',true ); // attach onclick after inserting into the dom if(buttstr) { $.each(mopt.buttons,function(i){ $("#"+$.jgrid.jqID(this.id),"#info_id").bind('click',function(){mopt.buttons[i].onClick.call($("#info_dialog")); return false;}); }); } $("#closedialog", "#info_id").click(function(){ self.hideModal("#info_dialog",{jqm:jm}); return false; }); $(".fm-button","#info_dialog").hover( function(){$(this).addClass('ui-state-hover');}, function(){$(this).removeClass('ui-state-hover');} ); if($.isFunction(mopt.beforeOpen) ) { mopt.beforeOpen(); } this.viewModal("#info_dialog",{ onHide: function(h) { h.w.hide().remove(); if(h.o) { h.o.remove(); } }, modal :mopt.modal, jqm:jm }); if($.isFunction(mopt.afterOpen) ) { mopt.afterOpen(); } try{ $("#info_dialog").focus();} catch (m){} }, // Form Functions createEl : function(eltype,options,vl,autowidth, ajaxso) { var elem = ""; function bindEv (el, opt) { if($.isFunction(opt.dataInit)) { opt.dataInit(el); } if(opt.dataEvents) { $.each(opt.dataEvents, function() { if (this.data !== undefined) { $(el).bind(this.type, this.data, this.fn); } else { $(el).bind(this.type, this.fn); } }); } return opt; } function setAttributes(elm, atr, exl ) { var exclude = ['dataInit','dataEvents','dataUrl', 'buildSelect','sopt', 'searchhidden', 'defaultValue', 'attr']; if(typeof(exl) != "undefined" && $.isArray(exl)) { $.merge(exclude, exl); } $.each(atr, function(key, value){ if($.inArray(key, exclude) === -1) { $(elm).attr(key,value); } }); if(!atr.hasOwnProperty('id')) { $(elm).attr('id', $.jgrid.randId()); } } switch (eltype) { case "textarea" : elem = document.createElement("textarea"); if(autowidth) { if(!options.cols) { $(elem).css({width:"98%"});} } else if (!options.cols) { options.cols = 20; } if(!options.rows) { options.rows = 2; } if(vl==' ' || vl==' ' || (vl.length==1 && vl.charCodeAt(0)==160)) {vl="";} elem.value = vl; setAttributes(elem, options); options = bindEv(elem,options); $(elem).attr({"role":"textbox","multiline":"true"}); break; case "checkbox" : //what code for simple checkbox elem = document.createElement("input"); elem.type = "checkbox"; if( !options.value ) { var vl1 = vl.toLowerCase(); if(vl1.search(/(false|0|no|off|undefined)/i)<0 && vl1!=="") { elem.checked=true; elem.defaultChecked=true; elem.value = vl; } else { elem.value = "on"; } $(elem).attr("offval","off"); } else { var cbval = options.value.split(":"); if(vl === cbval[0]) { elem.checked=true; elem.defaultChecked=true; } elem.value = cbval[0]; $(elem).attr("offval",cbval[1]); } setAttributes(elem, options, ['value']); options = bindEv(elem,options); $(elem).attr("role","checkbox"); break; case "select" : elem = document.createElement("select"); elem.setAttribute("role","select"); var msl, ovm = []; if(options.multiple===true) { msl = true; elem.multiple="multiple"; $(elem).attr("aria-multiselectable","true"); } else { msl = false; } if(typeof(options.dataUrl) != "undefined") { $.ajax($.extend({ url: options.dataUrl, type : "GET", dataType: "html", context: {elem:elem, options:options, vl:vl}, success: function(data){ var a, ovm = [], elem = this.elem, vl = this.vl, options = $.extend({},this.options), msl = options.multiple===true; if(typeof(options.buildSelect) != "undefined") { var b = options.buildSelect(data); a = $(b).html(); } else { a = $(data).html(); } if(a) { $(elem).append(a); setAttributes(elem, options); options = bindEv(elem,options); if(typeof options.size === 'undefined') { options.size = msl ? 3 : 1;} if(msl) { ovm = vl.split(","); ovm = $.map(ovm,function(n){return $.trim(n);}); } else { ovm[0] = $.trim(vl); } //$(elem).attr(options); setTimeout(function(){ $("option",elem).each(function(i){ //if(i===0) { this.selected = ""; } // fix IE8/IE7 problem with selecting of the first item on multiple=true if (i === 0 && elem.multiple) { this.selected = false; } $(this).attr("role","option"); if($.inArray($.trim($(this).text()),ovm) > -1 || $.inArray($.trim($(this).val()),ovm) > -1 ) { this.selected= "selected"; } }); },0); } } },ajaxso || {})); } else if(options.value) { var i; if(typeof options.size === 'undefined') { options.size = msl ? 3 : 1; } if(msl) { ovm = vl.split(","); ovm = $.map(ovm,function(n){return $.trim(n);}); } if(typeof options.value === 'function') { options.value = options.value(); } var so,sv, ov, sep = options.separator === undefined ? ":" : options.separator, delim = options.delimiter === undefined ? ";" : options.delimiter; if(typeof options.value === 'string') { so = options.value.split(delim); for(i=0; i 2 ) { sv[1] = $.map(sv,function(n,ii){if(ii>0) { return n;} }).join(sep); } ov = document.createElement("option"); ov.setAttribute("role","option"); ov.value = sv[0]; ov.innerHTML = sv[1]; elem.appendChild(ov); if (!msl && ($.trim(sv[0]) == $.trim(vl) || $.trim(sv[1]) == $.trim(vl))) { ov.selected ="selected"; } if (msl && ($.inArray($.trim(sv[1]), ovm)>-1 || $.inArray($.trim(sv[0]), ovm)>-1)) {ov.selected ="selected";} } } else if (typeof options.value === 'object') { var oSv = options.value; for ( var key in oSv) { if (oSv.hasOwnProperty(key ) ){ ov = document.createElement("option"); ov.setAttribute("role","option"); ov.value = key; ov.innerHTML = oSv[key]; elem.appendChild(ov); if (!msl && ( $.trim(key) == $.trim(vl) || $.trim(oSv[key]) == $.trim(vl)) ) { ov.selected ="selected"; } if (msl && ($.inArray($.trim(oSv[key]),ovm)>-1 || $.inArray($.trim(key),ovm)>-1)) { ov.selected ="selected"; } } } } setAttributes(elem, options, ['value']); options = bindEv(elem,options); } break; case "text" : case "password" : case "button" : var role; if(eltype=="button") { role = "button"; } else { role = "textbox"; } elem = document.createElement("input"); elem.type = eltype; elem.value = vl; setAttributes(elem, options); options = bindEv(elem,options); if(eltype != "button"){ if(autowidth) { if(!options.size) { $(elem).css({width:"98%"}); } } else if (!options.size) { options.size = 20; } } $(elem).attr("role",role); break; case "image" : case "file" : elem = document.createElement("input"); elem.type = eltype; setAttributes(elem, options); options = bindEv(elem,options); break; case "custom" : elem = document.createElement("span"); try { if($.isFunction(options.custom_element)) { var celm = options.custom_element.call(this,vl,options); if(celm) { celm = $(celm).addClass("customelement").attr({id:options.id,name:options.name}); $(elem).empty().append(celm); } else { throw "e2"; } } else { throw "e1"; } } catch (e) { if (e=="e1") { this.info_dialog($.jgrid.errors.errcap,"function 'custom_element' "+$.jgrid.edit.msg.nodefined, $.jgrid.edit.bClose);} if (e=="e2") { this.info_dialog($.jgrid.errors.errcap,"function 'custom_element' "+$.jgrid.edit.msg.novalue,$.jgrid.edit.bClose);} else { this.info_dialog($.jgrid.errors.errcap,typeof(e)==="string"?e:e.message,$.jgrid.edit.bClose); } } break; } return elem; }, // Date Validation Javascript checkDate : function (format, date) { var daysInFebruary = function(year){ // February has 29 days in any year evenly divisible by four, // EXCEPT for centurial years which are not also divisible by 400. return (((year % 4 === 0) && ( year % 100 !== 0 || (year % 400 === 0))) ? 29 : 28 ); }, DaysArray = function(n) { for (var i = 1; i <= n; i++) { this[i] = 31; if (i==4 || i==6 || i==9 || i==11) {this[i] = 30;} if (i==2) {this[i] = 29;} } return this; }; var tsp = {}, sep; format = format.toLowerCase(); //we search for /,-,. for the date separator if(format.indexOf("/") != -1) { sep = "/"; } else if(format.indexOf("-") != -1) { sep = "-"; } else if(format.indexOf(".") != -1) { sep = "."; } else { sep = "/"; } format = format.split(sep); date = date.split(sep); if (date.length != 3) { return false; } var j=-1,yln, dln=-1, mln=-1; for(var i=0;i12){ return false; } } if(dln === -1) { return false; } else { strDate = tsp[format[dln]].toString(); if (strDate.length<1 || tsp[format[dln]]<1 || tsp[format[dln]]>31 || (tsp[format[mln]]==2 && tsp[format[dln]]>daysInFebruary(tsp[format[j]])) || tsp[format[dln]] > daysInMonth[tsp[format[mln]]]){ return false; } } return true; }, isEmpty : function(val) { if (val.match(/^\s+$/) || val === "") { return true; } else { return false; } }, checkTime : function(time){ // checks only hh:ss (and optional am/pm) var re = /^(\d{1,2}):(\d{2})([ap]m)?$/,regs; if(!this.isEmpty(time)) { regs = time.match(re); if(regs) { if(regs[3]) { if(regs[1] < 1 || regs[1] > 12) { return false; } } else { if(regs[1] > 23) { return false; } } if(regs[2] > 59) { return false; } } else { return false; } } return true; }, checkValues : function(val, valref,g, customobject, nam) { var edtrul,i, nm, dft, len; if(typeof(customobject) === "undefined") { if(typeof(valref)=='string'){ for( i =0, len=g.p.colModel.length;i=0) { edtrul = g.p.colModel[valref].editrules; } } else { edtrul = customobject; nm = nam===undefined ? "_" : nam; } if(edtrul) { if(!nm) { nm = g.p.colNames[valref]; } if(edtrul.required === true) { if( this.isEmpty(val) ) { return [false,nm+": "+$.jgrid.edit.msg.required,""]; } } // force required var rqfield = edtrul.required === false ? false : true; if(edtrul.number === true) { if( !(rqfield === false && this.isEmpty(val)) ) { if(isNaN(val)) { return [false,nm+": "+$.jgrid.edit.msg.number,""]; } } } if(typeof edtrul.minValue != 'undefined' && !isNaN(edtrul.minValue)) { if (parseFloat(val) < parseFloat(edtrul.minValue) ) { return [false,nm+": "+$.jgrid.edit.msg.minValue+" "+edtrul.minValue,""];} } if(typeof edtrul.maxValue != 'undefined' && !isNaN(edtrul.maxValue)) { if (parseFloat(val) > parseFloat(edtrul.maxValue) ) { return [false,nm+": "+$.jgrid.edit.msg.maxValue+" "+edtrul.maxValue,""];} } var filter; if(edtrul.email === true) { if( !(rqfield === false && this.isEmpty(val)) ) { // taken from $ Validate plugin filter = /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i; if(!filter.test(val)) {return [false,nm+": "+$.jgrid.edit.msg.email,""];} } } if(edtrul.integer === true) { if( !(rqfield === false && this.isEmpty(val)) ) { if(isNaN(val)) { return [false,nm+": "+$.jgrid.edit.msg.integer,""]; } if ((val % 1 !== 0) || (val.indexOf('.') != -1)) { return [false,nm+": "+$.jgrid.edit.msg.integer,""];} } } if(edtrul.date === true) { if( !(rqfield === false && this.isEmpty(val)) ) { if(g.p.colModel[valref].formatoptions && g.p.colModel[valref].formatoptions.newformat) { dft = g.p.colModel[valref].formatoptions.newformat; } else { dft = g.p.colModel[valref].datefmt || "Y-m-d"; } if(!this.checkDate (dft, val)) { return [false,nm+": "+$.jgrid.edit.msg.date+" - "+dft,""]; } } } if(edtrul.time === true) { if( !(rqfield === false && this.isEmpty(val)) ) { if(!this.checkTime (val)) { return [false,nm+": "+$.jgrid.edit.msg.date+" - hh:mm (am/pm)",""]; } } } if(edtrul.url === true) { if( !(rqfield === false && this.isEmpty(val)) ) { filter = /^(((https?)|(ftp)):\/\/([\-\w]+\.)+\w{2,3}(\/[%\-\w]+(\.\w{2,})?)*(([\w\-\.\?\\\/+@&#;`~=%!]*)(\.\w{2,})?)*\/?)/i; if(!filter.test(val)) {return [false,nm+": "+$.jgrid.edit.msg.url,""];} } } if(edtrul.custom === true) { if( !(rqfield === false && this.isEmpty(val)) ) { if($.isFunction(edtrul.custom_func)) { var ret = edtrul.custom_func.call(g,val,nm); if($.isArray(ret)) { return ret; } else { return [false,$.jgrid.edit.msg.customarray,""]; } } else { return [false,$.jgrid.edit.msg.customfcheck,""]; } } } } return [true,"",""]; } }); })(jQuery);(function($){ /** * jqGrid extension for custom methods * Tony Tomov tony@trirand.com * http://trirand.com/blog/ * * Wildraid wildraid@mail.ru * Oleg Kiriljuk oleg.kiriljuk@ok-soft-gmbh.com * 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 **/ /*global jQuery, $ */ "use strict"; $.jgrid.extend({ getColProp : function(colname){ var ret ={}, $t = this[0]; if ( !$t.grid ) { return false; } var cM = $t.p.colModel; for ( var i =0;i0 ? true : false; if(p.stringResult === true || $t.p.datatype == "local") { var ruleGroup = "{\"groupOp\":\"" + p.groupOp + "\",\"rules\":["; var gi=0; $.each(sdata,function(i,n){ if (gi > 0) {ruleGroup += ",";} ruleGroup += "{\"field\":\"" + i + "\","; ruleGroup += "\"op\":\"" + sopt[i] + "\","; n+=""; ruleGroup += "\"data\":\"" + n.replace(/\\/g,'\\\\').replace(/\"/g,'\\"') + "\"}"; gi++; }); ruleGroup += "]}"; $.extend($t.p.postData,{filters:ruleGroup}); $.each(['searchField', 'searchString', 'searchOper'], function(i, n){ if($t.p.postData.hasOwnProperty(n)) { delete $t.p.postData[n];} }); } else { $.extend($t.p.postData,sdata); } var saveurl; if($t.p.searchurl) { saveurl = $t.p.url; $($t).jqGrid("setGridParam",{url:$t.p.searchurl}); } var bsr = $($t).triggerHandler("jqGridToolbarBeforeSearch") === 'stop' ? true : false; if(!bsr && $.isFunction(p.beforeSearch)){bsr = p.beforeSearch.call($t);} if(!bsr) { $($t).jqGrid("setGridParam",{search:sd}).trigger("reloadGrid",[{page:1}]); } if(saveurl) {$($t).jqGrid("setGridParam",{url:saveurl});} $($t).triggerHandler("jqGridToolbarAfterSearch"); if($.isFunction(p.afterSearch)){p.afterSearch();} }; var clearToolbar = function(trigger){ var sdata={}, j=0, nm; trigger = (typeof trigger != 'boolean') ? true : trigger; $.each($t.p.colModel,function(){ var v; if(this.searchoptions && this.searchoptions.defaultValue !== undefined) { v = this.searchoptions.defaultValue; } nm = this.index || this.name; switch (this.stype) { case 'select' : $("#gs_"+$.jgrid.jqID(this.name)+" option",(this.frozen===true && $t.p.frozenColumns === true) ? $t.grid.fhDiv : $t.grid.hDiv).each(function (i){ if(i===0) { this.selected = true; } if ($(this).val() == v) { this.selected = true; return false; } }); if ( v !== undefined ) { // post the key and not the text sdata[nm] = v; j++; } else { try { delete $t.p.postData[nm]; } catch(e) {} } break; case 'text': $("#gs_"+$.jgrid.jqID(this.name),(this.frozen===true && $t.p.frozenColumns === true) ? $t.grid.fhDiv : $t.grid.hDiv).val(v); if(v !== undefined) { sdata[nm] = v; j++; } else { try { delete $t.p.postData[nm]; } catch (y){} } break; } }); var sd = j>0 ? true : false; if(p.stringResult === true || $t.p.datatype == "local") { var ruleGroup = "{\"groupOp\":\"" + p.groupOp + "\",\"rules\":["; var gi=0; $.each(sdata,function(i,n){ if (gi > 0) {ruleGroup += ",";} ruleGroup += "{\"field\":\"" + i + "\","; ruleGroup += "\"op\":\"" + "eq" + "\","; n+=""; ruleGroup += "\"data\":\"" + n.replace(/\\/g,'\\\\').replace(/\"/g,'\\"') + "\"}"; gi++; }); ruleGroup += "]}"; $.extend($t.p.postData,{filters:ruleGroup}); $.each(['searchField', 'searchString', 'searchOper'], function(i, n){ if($t.p.postData.hasOwnProperty(n)) { delete $t.p.postData[n];} }); } else { $.extend($t.p.postData,sdata); } var saveurl; if($t.p.searchurl) { saveurl = $t.p.url; $($t).jqGrid("setGridParam",{url:$t.p.searchurl}); } var bcv = $($t).triggerHandler("jqGridToolbarBeforeClear") === 'stop' ? true : false; if(!bcv && $.isFunction(p.beforeClear)){bcv = p.beforeClear.call($t);} if(!bcv) { if(trigger) { $($t).jqGrid("setGridParam",{search:sd}).trigger("reloadGrid",[{page:1}]); } } if(saveurl) {$($t).jqGrid("setGridParam",{url:saveurl});} $($t).triggerHandler("jqGridToolbarAfterClear"); if($.isFunction(p.afterClear)){p.afterClear();} }; var toggleToolbar = function(){ var trow = $("tr.ui-search-toolbar",$t.grid.hDiv), trow2 = $t.p.frozenColumns === true ? $("tr.ui-search-toolbar",$t.grid.fhDiv) : false; if(trow.css("display")=='none') { trow.show(); if(trow2) { trow2.show(); } } else { trow.hide(); if(trow2) { trow2.hide(); } } }; // create the row function bindEvents(selector, events) { var jElem = $(selector); if (jElem[0]) { jQuery.each(events, function() { if (this.data !== undefined) { jElem.bind(this.type, this.data, this.fn); } else { jElem.bind(this.type, this.fn); } }); } } var tr = $(""); var timeoutHnd; $.each($t.p.colModel,function(){ var cm=this, thd , th, soptions,surl,self; th = $(""); thd = $("
"); if(this.hidden===true) { $(th).css("display","none");} this.search = this.search === false ? false : true; if(typeof this.stype == 'undefined' ) {this.stype='text';} soptions = $.extend({},this.searchoptions || {}); if(this.search){ switch (this.stype) { case "select": surl = this.surl || soptions.dataUrl; if(surl) { // data returned should have already constructed html select // primitive jQuery load self = thd; $.ajax($.extend({ url: surl, dataType: "html", success: function(res) { if(soptions.buildSelect !== undefined) { var d = soptions.buildSelect(res); if (d) { $(self).append(d); } } else { $(self).append(res); } if(soptions.defaultValue !== undefined) { $("select",self).val(soptions.defaultValue); } $("select",self).attr({name:cm.index || cm.name, id: "gs_"+cm.name}); if(soptions.attr) {$("select",self).attr(soptions.attr);} $("select",self).css({width: "100%"}); // preserve autoserch if(soptions.dataInit !== undefined) { soptions.dataInit($("select",self)[0]); } if(soptions.dataEvents !== undefined) { bindEvents($("select",self)[0],soptions.dataEvents); } if(p.autosearch===true){ $("select",self).change(function(){ triggerToolbar(); return false; }); } res=null; } }, $.jgrid.ajaxOptions, $t.p.ajaxSelectOptions || {} )); } else { var oSv, sep, delim; if(cm.searchoptions) { oSv = cm.searchoptions.value === undefined ? "" : cm.searchoptions.value; sep = cm.searchoptions.separator === undefined ? ":" : cm.searchoptions.separator; delim = cm.searchoptions.delimiter === undefined ? ";" : cm.searchoptions.delimiter; } else if(cm.editoptions) { oSv = cm.editoptions.value === undefined ? "" : cm.editoptions.value; sep = cm.editoptions.separator === undefined ? ":" : cm.editoptions.separator; delim = cm.editoptions.delimiter === undefined ? ";" : cm.editoptions.delimiter; } if (oSv) { var elem = document.createElement("select"); elem.style.width = "100%"; $(elem).attr({name:cm.index || cm.name, id: "gs_"+cm.name}); var so, sv, ov; if(typeof oSv === "string") { so = oSv.split(delim); for(var k=0; k"); if(soptions.attr) {$("input",thd).attr(soptions.attr);} if(soptions.dataInit !== undefined) { soptions.dataInit($("input",thd)[0]); } if(soptions.dataEvents !== undefined) { bindEvents($("input",thd)[0], soptions.dataEvents); } if(p.autosearch===true){ if(p.searchOnEnter) { $("input",thd).keypress(function(e){ var key = e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0; if(key == 13){ triggerToolbar(); return false; } return this; }); } else { $("input",thd).keydown(function(e){ var key = e.which; switch (key) { case 13: return false; case 9 : case 16: case 37: case 38: case 39: case 40: case 27: break; default : if(timeoutHnd) { clearTimeout(timeoutHnd); } timeoutHnd = setTimeout(function(){triggerToolbar();},500); } }); } } break; } } $(th).append(thd); $(tr).append(th); }); $("table thead",$t.grid.hDiv).append(tr); this.ftoolbar = true; this.triggerToolbar = triggerToolbar; this.clearToolbar = clearToolbar; this.toggleToolbar = toggleToolbar; }); }, destroyGroupHeader : function(nullHeader) { if(typeof(nullHeader) == 'undefined') { nullHeader = true; } return this.each(function() { var $t = this, $tr, i, l, headers, $th, $resizing, grid = $t.grid, thead = $("table.ui-jqgrid-htable thead", grid.hDiv), cm = $t.p.colModel, hc; if(!grid) { return; } $(this).unbind('.setGroupHeaders'); $tr = $("", {role: "rowheader"}).addClass("ui-jqgrid-labels"); headers = grid.headers; for (i = 0, l = headers.length; i < l; i++) { hc = cm[i].hidden ? "none" : ""; $th = $(headers[i].el) .width(headers[i].width) .css('display',hc); try { $th.removeAttr("rowSpan"); } catch (rs) { //IE 6/7 $th.attr("rowSpan",1); } $tr.append($th); $resizing = $th.children("span.ui-jqgrid-resize"); if ($resizing.length>0) {// resizable column $resizing[0].style.height = ""; } $th.children("div")[0].style.top = ""; } $(thead).children('tr.ui-jqgrid-labels').remove(); $(thead).prepend($tr); if(nullHeader === true) { $($t).jqGrid('setGridParam',{ 'groupHeader': null}); } }); }, setGroupHeaders : function ( o ) { o = $.extend({ useColSpanStyle : false, groupHeaders: [] },o || {}); return this.each(function(){ this.p.groupHeader = o; var ts = this, i, cmi, skip = 0, $tr, $colHeader, th, $th, thStyle, iCol, cghi, //startColumnName, numberOfColumns, titleText, cVisibleColumns, colModel = ts.p.colModel, cml = colModel.length, ths = ts.grid.headers, $htable = $("table.ui-jqgrid-htable", ts.grid.hDiv), $trLabels = $htable.children("thead").children("tr.ui-jqgrid-labels:last").addClass("jqg-second-row-header"), $thead = $htable.children("thead"), $theadInTable, $firstHeaderRow = $htable.find(".jqg-first-row-header"); if($firstHeaderRow.html() === null) { $firstHeaderRow = $('', {role: "row", "aria-hidden": "true"}).addClass("jqg-first-row-header").css("height", "auto"); } else { $firstHeaderRow.empty(); } var $firstRow, inColumnHeader = function (text, columnHeaders) { var i = 0, length = columnHeaders.length; for (; i < length; i++) { if (columnHeaders[i].startColumnName === text) { return i; } } return -1; }; $(ts).prepend($thead); $tr = $('', {role: "rowheader"}).addClass("ui-jqgrid-labels jqg-third-row-header"); for (i = 0; i < cml; i++) { th = ths[i].el; $th = $(th); cmi = colModel[i]; // build the next cell for the first header row thStyle = { height: '0px', width: ths[i].width + 'px', display: (cmi.hidden ? 'none' : '')}; $("", {role: 'gridcell'}).css(thStyle).addClass("ui-first-th-"+ts.p.direction).appendTo($firstHeaderRow); th.style.width = ""; // remove unneeded style iCol = inColumnHeader(cmi.name, o.groupHeaders); if (iCol >= 0) { cghi = o.groupHeaders[iCol]; numberOfColumns = cghi.numberOfColumns; titleText = cghi.titleText; // caclulate the number of visible columns from the next numberOfColumns columns for (cVisibleColumns = 0, iCol = 0; iCol < numberOfColumns && (i + iCol < cml); iCol++) { if (!colModel[i + iCol].hidden) { cVisibleColumns++; } } // The next numberOfColumns headers will be moved in the next row // in the current row will be placed the new column header with the titleText. // The text will be over the cVisibleColumns columns $colHeader = $('').attr({role: "columnheader"}) .addClass("ui-state-default ui-th-column-header ui-th-"+ts.p.direction) .css({'height':'22px', 'border-top': '0px none'}) .html(titleText); if(cVisibleColumns > 0) { $colHeader.attr("colspan", String(cVisibleColumns)); } if (ts.p.headertitles) { $colHeader.attr("title", $colHeader.text()); } // hide if not a visible cols if( cVisibleColumns === 0) { $colHeader.hide(); } $th.before($colHeader); // insert new column header before the current $tr.append(th); // move the current header in the next row // set the coumter of headers which will be moved in the next row skip = numberOfColumns - 1; } else { if (skip === 0) { if (o.useColSpanStyle) { // expand the header height to two rows $th.attr("rowspan", "2"); } else { $('', {role: "columnheader"}) .addClass("ui-state-default ui-th-column-header ui-th-"+ts.p.direction) .css({"display": cmi.hidden ? 'none' : '', 'border-top': '0px none'}) .insertBefore($th); $tr.append(th); } } else { // move the header to the next row //$th.css({"padding-top": "2px", height: "19px"}); $tr.append(th); skip--; } } } $theadInTable = $(ts).children("thead"); $theadInTable.prepend($firstHeaderRow); $tr.insertAfter($trLabels); $htable.append($theadInTable); if (o.useColSpanStyle) { // Increase the height of resizing span of visible headers $htable.find("span.ui-jqgrid-resize").each(function () { var $parent = $(this).parent(); if ($parent.is(":visible")) { this.style.cssText = 'height: ' + $parent.height() + 'px !important; cursor: col-resize;'; } }); // Set position of the sortable div (the main lable) // with the column header text to the middle of the cell. // One should not do this for hidden headers. $htable.find("div.ui-jqgrid-sortable").each(function () { var $ts = $(this), $parent = $ts.parent(); if ($parent.is(":visible") && $parent.is(":has(span.ui-jqgrid-resize)")) { $ts.css('top', ($parent.height() - $ts.outerHeight()) / 2 + 'px'); } }); } $firstRow = $theadInTable.find("tr.jqg-first-row-header"); $(ts).bind('jqGridResizeStop.setGroupHeaders', function (e, nw, idx) { $firstRow.find('th').eq(idx).width(nw); }); }); }, setFrozenColumns : function () { return this.each(function() { if ( !this.grid ) {return;} var $t = this, cm = $t.p.colModel,i=0, len = cm.length, maxfrozen = -1, frozen= false; // TODO treeGrid and grouping Support if($t.p.subGrid === true || $t.p.treeGrid === true || $t.p.cellEdit === true || $t.p.sortable || $t.p.scroll || $t.p.grouping ) { return; } if($t.p.rownumbers) { i++; } if($t.p.multiselect) { i++; } // get the max index of frozen col while(i=0 && frozen) { var top = $t.p.caption ? $($t.grid.cDiv).outerHeight() : 0, hth = $(".ui-jqgrid-htable","#gview_"+$.jgrid.jqID($t.p.id)).height(); //headers if($t.p.toppager) { top = top + $($t.grid.topDiv).outerHeight(); } if($t.p.toolbar[0] === true) { if($t.p.toolbar[1] != "bottom") { top = top + $($t.grid.uDiv).outerHeight(); } } $t.grid.fhDiv = $('
'); $t.grid.fbDiv = $('
'); $("#gview_"+$.jgrid.jqID($t.p.id)).append($t.grid.fhDiv); var htbl = $(".ui-jqgrid-htable","#gview_"+$.jgrid.jqID($t.p.id)).clone(true); // groupheader support - only if useColSpanstyle is false if($t.p.groupHeader) { $("tr.jqg-first-row-header, tr.jqg-third-row-header", htbl).each(function(){ $("th:gt("+maxfrozen+")",this).remove(); }); var swapfroz = -1, fdel = -1; $("tr.jqg-second-row-header th", htbl).each(function(){ var cs= parseInt($(this).attr("colspan"),10); if(cs) { swapfroz = swapfroz+cs; fdel++; } if(swapfroz === maxfrozen) { return false; } }); if(swapfroz !== maxfrozen) { fdel = maxfrozen; } $("tr.jqg-second-row-header", htbl).each(function(){ $("th:gt("+fdel+")",this).remove(); }); } else { $("tr",htbl).each(function(){ $("th:gt("+maxfrozen+")",this).remove(); }); } $(htbl).width(1); // resizing stuff $($t.grid.fhDiv).append(htbl) .mousemove(function (e) { if($t.grid.resizing){ $t.grid.dragMove(e);return false; } }); $($t).bind('jqGridResizeStop.setFrozenColumns', function (e, w, index) { var rhth = $(".ui-jqgrid-htable",$t.grid.fhDiv); $("th:eq("+index+")",rhth).width( w ); var btd = $(".ui-jqgrid-btable",$t.grid.fbDiv); $("tr:first td:eq("+index+")",btd).width( w ); }); // sorting stuff $($t).bind('jqGridOnSortCol.setFrozenColumns', function (index, idxcol) { var previousSelectedTh = $("tr.ui-jqgrid-labels:last th:eq("+$t.p.lastsort+")",$t.grid.fhDiv), newSelectedTh = $("tr.ui-jqgrid-labels:last th:eq("+idxcol+")",$t.grid.fhDiv); $("span.ui-grid-ico-sort",previousSelectedTh).addClass('ui-state-disabled'); $(previousSelectedTh).attr("aria-selected","false"); $("span.ui-icon-"+$t.p.sortorder,newSelectedTh).removeClass('ui-state-disabled'); $(newSelectedTh).attr("aria-selected","true"); if(!$t.p.viewsortcols[0]) { if($t.p.lastsort != idxcol) { $("span.s-ico",previousSelectedTh).hide(); $("span.s-ico",newSelectedTh).show(); } } }); // data stuff //TODO support for setRowData $("#gview_"+$.jgrid.jqID($t.p.id)).append($t.grid.fbDiv); jQuery($t.grid.bDiv).scroll(function () { jQuery($t.grid.fbDiv).scrollTop(jQuery(this).scrollTop()); }); if($t.p.hoverrows === true) { $("#"+$.jgrid.jqID($t.p.id)).unbind('mouseover').unbind('mouseout'); } $($t).bind('jqGridAfterGridComplete.setFrozenColumns', function () { $("#"+$.jgrid.jqID($t.p.id)+"_frozen").remove(); jQuery($t.grid.fbDiv).height( jQuery($t.grid.bDiv).height()-16); var btbl = $("#"+$.jgrid.jqID($t.p.id)).clone(true); $("tr",btbl).each(function(){ $("td:gt("+maxfrozen+")",this).remove(); }); $(btbl).width(1).attr("id",$t.p.id+"_frozen"); $($t.grid.fbDiv).append(btbl); if($t.p.hoverrows === true) { $("tr.jqgrow", btbl).hover( function(){ $(this).addClass("ui-state-hover"); $("#"+$.jgrid.jqID(this.id), "#"+$.jgrid.jqID($t.p.id)).addClass("ui-state-hover"); }, function(){ $(this).removeClass("ui-state-hover"); $("#"+$.jgrid.jqID(this.id), "#"+$.jgrid.jqID($t.p.id)).removeClass("ui-state-hover"); } ); $("tr.jqgrow", "#"+$.jgrid.jqID($t.p.id)).hover( function(){ $(this).addClass("ui-state-hover"); $("#"+$.jgrid.jqID(this.id), "#"+$.jgrid.jqID($t.p.id)+"_frozen").addClass("ui-state-hover");}, function(){ $(this).removeClass("ui-state-hover"); $("#"+$.jgrid.jqID(this.id), "#"+$.jgrid.jqID($t.p.id)+"_frozen").removeClass("ui-state-hover"); } ); } btbl=null; }); $t.p.frozenColumns = true; } }); }, destroyFrozenColumns : function() { return this.each(function() { if ( !this.grid ) {return;} if(this.p.frozenColumns === true) { var $t = this; $($t.grid.fhDiv).remove(); $($t.grid.fbDiv).remove(); $t.grid.fhDiv = null; $t.grid.fbDiv=null; $(this).unbind('.setFrozenColumns'); if($t.p.hoverrows === true) { var ptr; $("#"+$.jgrid.jqID($t.p.id)).bind('mouseover',function(e) { ptr = $(e.target).closest("tr.jqgrow"); if($(ptr).attr("class") !== "ui-subgrid") { $(ptr).addClass("ui-state-hover"); } }).bind('mouseout',function(e) { ptr = $(e.target).closest("tr.jqgrow"); $(ptr).removeClass("ui-state-hover"); }); } this.p.frozenColumns = false; } }); } }); })(jQuery);/* * jqFilter jQuery jqGrid filter addon. * Copyright (c) 2011, Tony Tomov, tony@trirand.com * 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 * * The work is inspired from this Stefan Pirvu * http://www.codeproject.com/KB/scripting/json-filtering.aspx * * The filter uses JSON entities to hold filter rules and groups. Here is an example of a filter: { "groupOp": "AND", "groups" : [ { "groupOp": "OR", "rules": [ { "field": "name", "op": "eq", "data": "England" }, { "field": "id", "op": "le", "data": "5"} ] } ], "rules": [ { "field": "name", "op": "eq", "data": "Romania" }, { "field": "id", "op": "le", "data": "1"} ] } */ /*global jQuery, $, window, navigator */ (function ($) { $.fn.jqFilter = function( arg ) { if (typeof arg === 'string') { var fn = $.fn.jqFilter[arg]; if (!fn) { throw ("jqFilter - No such method: " + arg); } var args = $.makeArray(arguments).slice(1); return fn.apply(this,args); } var p = $.extend(true,{ filter: null, columns: [], onChange : null, afterRedraw : null, checkValues : null, error: false, errmsg : "", errorcheck : true, showQuery : true, sopt : null, ops : [ {"name": "eq", "description": "equal", "operator":"="}, {"name": "ne", "description": "not equal", "operator":"<>"}, {"name": "lt", "description": "less", "operator":"<"}, {"name": "le", "description": "less or equal","operator":"<="}, {"name": "gt", "description": "greater", "operator":">"}, {"name": "ge", "description": "greater or equal", "operator":">="}, {"name": "bw", "description": "begins with", "operator":"LIKE"}, {"name": "bn", "description": "does not begin with", "operator":"NOT LIKE"}, {"name": "in", "description": "in", "operator":"IN"}, {"name": "ni", "description": "not in", "operator":"NOT IN"}, {"name": "ew", "description": "ends with", "operator":"LIKE"}, {"name": "en", "description": "does not end with", "operator":"NOT LIKE"}, {"name": "cn", "description": "contains", "operator":"LIKE"}, {"name": "nc", "description": "does not contain", "operator":"NOT LIKE"}, {"name": "nu", "description": "is null", "operator":"IS NULL"}, {"name": "nn", "description": "is not null", "operator":"IS NOT NULL"} ], numopts : ['eq','ne', 'lt', 'le', 'gt', 'ge', 'nu', 'nn', 'in', 'ni'], stropts : ['eq', 'ne', 'bw', 'bn', 'ew', 'en', 'cn', 'nc', 'nu', 'nn', 'in', 'ni'], _gridsopt : [], // grid translated strings, do not tuch groupOps : [{ op: "AND", text: "AND" }, { op: "OR", text: "OR" }], groupButton : true, ruleButtons : true, direction : "ltr" }, arg || {}); return this.each( function() { if (this.filter) {return;} this.p = p; // setup filter in case if they is not defined if (this.p.filter === null || this.p.filter === undefined) { this.p.filter = { groupOp: this.p.groupOps[0].op, rules: [], groups: [] }; } var i, len = this.p.columns.length, cl, isIE = /msie/i.test(navigator.userAgent) && !window.opera; // translating the options if(this.p._gridsopt.length) { // ['eq','ne','lt','le','gt','ge','bw','bn','in','ni','ew','en','cn','nc'] for(i=0;i"); } /* *Perform checking. * */ var checkData = function(val, colModelItem) { var ret = [true,""]; if($.isFunction(colModelItem.searchrules)) { ret = colModelItem.searchrules(val, colModelItem); } else if($.jgrid && $.jgrid.checkValues) { try { ret = $.jgrid.checkValues(val, -1, null, colModelItem.searchrules, colModelItem.label); } catch (e) {} } if(ret && ret.length && ret[0] === false) { p.error = !ret[0]; p.errmsg = ret[1]; } }; /* moving to common randId = function() { return Math.floor(Math.random()*10000).toString(); }; */ this.onchange = function ( ){ // clear any error this.p.error = false; this.p.errmsg=""; return $.isFunction(this.p.onChange) ? this.p.onChange.call( this, this.p ) : false; }; /* * Redraw the filter every time when new field is added/deleted * and field is changed */ this.reDraw = function() { $("table.group:first",this).remove(); var t = this.createTableForGroup(p.filter, null); $(this).append(t); if($.isFunction(this.p.afterRedraw) ) { this.p.afterRedraw.call(this, this.p); } }; /* * Creates a grouping data for the filter * @param group - object * @param parentgroup - object */ this.createTableForGroup = function(group, parentgroup) { var that = this, i; // this table will hold all the group (tables) and rules (rows) var table = $("
"), // create error message row align = "left"; if(this.p.direction == "rtl") { align = "right"; table.attr("dir","rtl"); } if(parentgroup === null) { table.append(""); } var tr = $(""); table.append(tr); // this header will hold the group operator type and group action buttons for // creating subgroup "+ {}", creating rule "+" or deleting the group "-" var th = $(""); tr.append(th); if(this.p.ruleButtons === true) { // dropdown for: choosing group operator type var groupOpSelect = $(""); th.append(groupOpSelect); // populate dropdown with all posible group operators: or, and var str= "", selected; for (i = 0; i < p.groupOps.length; i++) { selected = group.groupOp === that.p.groupOps[i].op ? " selected='selected'" :""; str += ""; } groupOpSelect .append(str) .bind('change',function() { group.groupOp = $(groupOpSelect).val(); that.onchange(); // signals that the filter has changed }); } // button for adding a new subgroup var inputAddSubgroup =""; if(this.p.groupButton) { inputAddSubgroup = $(""); inputAddSubgroup.bind('click',function() { if (group.groups === undefined ) { group.groups = []; } group.groups.push({ groupOp: p.groupOps[0].op, rules: [], groups: [] }); // adding a new group that.reDraw(); // the html has changed, force reDraw that.onchange(); // signals that the filter has changed return false; }); } th.append(inputAddSubgroup); if(this.p.ruleButtons === true) { // button for adding a new rule var inputAddRule = $(""), cm; inputAddRule.bind('click',function() { //if(!group) { group = {};} if (group.rules === undefined) { group.rules = []; } for (i = 0; i < that.p.columns.length; i++) { // but show only serchable and serchhidden = true fields var searchable = (typeof that.p.columns[i].search === 'undefined') ? true: that.p.columns[i].search , hidden = (that.p.columns[i].hidden === true), ignoreHiding = (that.p.columns[i].searchoptions.searchhidden === true); if ((ignoreHiding && searchable) || (searchable && !hidden)) { cm = that.p.columns[i]; break; } } var opr; if( cm.searchoptions.sopt ) {opr = cm.searchoptions.sopt;} else if(that.p.sopt) { opr= that.p.sopt; } else if (cm.searchtype === 'string') {opr = that.p.stropts;} else {opr = that.p.numopts;} group.rules.push({ field: cm.name, op: opr[0], data: "" }); // adding a new rule that.reDraw(); // the html has changed, force reDraw // for the moment no change have been made to the rule, so // this will not trigger onchange event return false; }); th.append(inputAddRule); } // button for delete the group if (parentgroup !== null) { // ignore the first group var inputDeleteGroup = $(""); th.append(inputDeleteGroup); inputDeleteGroup.bind('click',function() { // remove group from parent for (i = 0; i < parentgroup.groups.length; i++) { if (parentgroup.groups[i] === group) { parentgroup.groups.splice(i, 1); break; } } that.reDraw(); // the html has changed, force reDraw that.onchange(); // signals that the filter has changed return false; }); } // append subgroup rows if (group.groups !== undefined) { for (i = 0; i < group.groups.length; i++) { var trHolderForSubgroup = $(""); table.append(trHolderForSubgroup); var tdFirstHolderForSubgroup = $(""); trHolderForSubgroup.append(tdFirstHolderForSubgroup); var tdMainHolderForSubgroup = $(""); tdMainHolderForSubgroup.append(this.createTableForGroup(group.groups[i], group)); trHolderForSubgroup.append(tdMainHolderForSubgroup); } } if(group.groupOp === undefined) { group.groupOp = that.p.groupOps[0].op; } // append rules rows if (group.rules !== undefined) { for (i = 0; i < group.rules.length; i++) { table.append( this.createTableRowForRule(group.rules[i], group) ); } } return table; }; /* * Create the rule data for the filter */ this.createTableRowForRule = function(rule, group ) { // save current entity in a variable so that it could // be referenced in anonimous method calls var that=this, tr = $(""), //document.createElement("tr"), // first column used for padding //tdFirstHolderForRule = document.createElement("td"), i, op, trpar, cm, str="", selected; //tdFirstHolderForRule.setAttribute("class", "first"); tr.append(""); // create field container var ruleFieldTd = $(""); tr.append(ruleFieldTd); // dropdown for: choosing field var ruleFieldSelect = $(""), ina, aoprs = []; ruleFieldTd.append(ruleFieldSelect); ruleFieldSelect.bind('change',function() { rule.field = $(ruleFieldSelect).val(); trpar = $(this).parents("tr:first"); for (i=0;i"+that.p.ops[ina].description+""; so++; } } $(".selectopts",trpar).empty().append( s ); $(".selectopts",trpar)[0].selectedIndex = 0; if( $.browser.msie && $.browser.version < 9) { var sw = parseInt($("select.selectopts",trpar)[0].offsetWidth) + 1; $(".selectopts",trpar).width( sw ); $(".selectopts",trpar).css("width","auto"); } // data $(".data",trpar).empty().append( elm ); $(".input-elm",trpar).bind('change',function( e ) { var tmo = $(this).hasClass("ui-autocomplete-input") ? 200 :0; setTimeout(function(){ rule.data = e.target.value; that.onchange(); // signals that the filter has changed }, tmo); }); setTimeout(function(){ //IE, Opera, Chrome rule.data = $(elm).val(); that.onchange(); // signals that the filter has changed }, 0); }); // populate drop down with user provided column definitions var j=0; for (i = 0; i < that.p.columns.length; i++) { // but show only serchable and serchhidden = true fields var searchable = (typeof that.p.columns[i].search === 'undefined') ? true: that.p.columns[i].search , hidden = (that.p.columns[i].hidden === true), ignoreHiding = (that.p.columns[i].searchoptions.searchhidden === true); if ((ignoreHiding && searchable) || (searchable && !hidden)) { selected = ""; if(rule.field === that.p.columns[i].name) { selected = " selected='selected'"; j=i; } str += ""; } } ruleFieldSelect.append( str ); // create operator container var ruleOperatorTd = $(""); tr.append(ruleOperatorTd); cm = p.columns[j]; // create it here so it can be referentiated in the onchange event //var RD = that.createElement(rule, rule.data); cm.searchoptions.id = $.jgrid.randId(); if(isIE && cm.inputtype === "text") { if(!cm.searchoptions.size) { cm.searchoptions.size = 10; } } var ruleDataInput = $.jgrid.createEl(cm.inputtype,cm.searchoptions, rule.data, true, that.p.ajaxSelectOptions, true); // dropdown for: choosing operator var ruleOperatorSelect = $(""); ruleOperatorTd.append(ruleOperatorSelect); ruleOperatorSelect.bind('change',function() { rule.op = $(ruleOperatorSelect).val(); trpar = $(this).parents("tr:first"); var rd = $(".input-elm",trpar)[0]; if (rule.op === "nu" || rule.op === "nn") { // disable for operator "is null" and "is not null" rule.data = ""; rd.value = ""; rd.setAttribute("readonly", "true"); rd.setAttribute("disabled", "true"); } else { rd.removeAttribute("readonly"); rd.removeAttribute("disabled"); } that.onchange(); // signals that the filter has changed }); // populate drop down with all available operators if( cm.searchoptions.sopt ) {op = cm.searchoptions.sopt;} else if(that.p.sopt) { op= that.p.sopt; } else if (cm.searchtype === 'string') {op = p.stropts;} else {op = that.p.numopts;} str=""; $.each(that.p.ops, function() { aoprs.push(this.name) }); for ( i = 0; i < op.length; i++) { ina = $.inArray(op[i],aoprs); if(ina !== -1) { selected = rule.op === that.p.ops[ina].name ? " selected='selected'" : ""; str += ""; } } ruleOperatorSelect.append( str ); // create data container var ruleDataTd = $(""); tr.append(ruleDataTd); // textbox for: data // is created previously //ruleDataInput.setAttribute("type", "text"); ruleDataTd.append(ruleDataInput); $(ruleDataInput) .addClass("input-elm") .bind('change', function() { rule.data = $(this).val(); that.onchange(); // signals that the filter has changed }); // create action container var ruleDeleteTd = $(""); tr.append(ruleDeleteTd); // create button for: delete rule if(this.p.ruleButtons === true) { var ruleDeleteInput = $(""); ruleDeleteTd.append(ruleDeleteInput); //$(ruleDeleteInput).html("").height(20).width(30).button({icons: { primary: "ui-icon-minus", text:false}}); ruleDeleteInput.bind('click',function() { // remove rule from group for (i = 0; i < group.rules.length; i++) { if (group.rules[i] === rule) { group.rules.splice(i, 1); break; } } that.reDraw(); // the html has changed, force reDraw that.onchange(); // signals that the filter has changed return false; }); } return tr; }; this.getStringForGroup = function(group) { var s = "(", index; if (group.groups !== undefined) { for (index = 0; index < group.groups.length; index++) { if (s.length > 1) { s += " " + group.groupOp + " "; } try { s += this.getStringForGroup(group.groups[index]); } catch (eg) {alert(eg);} } } if (group.rules !== undefined) { try{ for (index = 0; index < group.rules.length; index++) { if (s.length > 1) { s += " " + group.groupOp + " "; } s += this.getStringForRule(group.rules[index]); } } catch (e) {alert(e);} } s += ")"; if (s === "()") { return ""; // ignore groups that don't have rules } else { return s; } }; this.getStringForRule = function(rule) { var opUF = "",opC="", i, cm, ret, val, numtypes = ['int', 'integer', 'float', 'number', 'currency']; // jqGrid for (i = 0; i < this.p.ops.length; i++) { if (this.p.ops[i].name === rule.op) { opUF = this.p.ops[i].operator; opC = this.p.ops[i].name; break; } } for (i=0; i 1) { if (group.groupOp === "OR") { s += " || "; } else { s += " && "; } } s += getStringForGroup(group.groups[index]); } } if (group.rules !== undefined) { for (index = 0; index < group.rules.length; index++) { if (s.length > 1) { if (group.groupOp === "OR") { s += " || "; } else { s += " && "; } } s += getStringRule(group.rules[index]); } } s += ")"; if (s === "()") { return ""; // ignore groups that don't have rules } else { return s; } } return getStringForGroup(this.p.filter); }; // Here we init the filter this.reDraw(); if(this.p.showQuery) { this.onchange(); } // mark is as created so that it will not be created twice on this element this.filter = true; }); }; $.extend($.fn.jqFilter,{ /* * Return SQL like string. Can be used directly */ toSQLString : function() { var s =""; this.each(function(){ s = this.toUserFriendlyString(); }); return s; }, /* * Return filter data as object. */ filterData : function() { var s; this.each(function(){ s = this.p.filter; }); return s; }, getParameter : function (param) { if(param !== undefined) { if (this.p.hasOwnProperty(param) ) { return this.p[param]; } } return this.p; }, resetFilter: function() { return this.each(function(){ this.resetFilter(); }); }, addFilter: function (pfilter) { if (typeof pfilter === "string") { pfilter = jQuery.jgrid.parse( pfilter ); } this.each(function(){ this.p.filter = pfilter; this.reDraw(); this.onchange(); }); } }); })(jQuery); (function($){ /** * jqGrid extension for form editing 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"; /*global xmlJsonClass, jQuery, $ */ var rp_ge = {}; $.jgrid.extend({ searchGrid : function (p) { p = $.extend({ recreateFilter: false, drag: true, sField:'searchField', sValue:'searchString', sOper: 'searchOper', sFilter: 'filters', loadDefaults: true, // this options activates loading of default filters from grid's postData for Multipe Search only. beforeShowSearch: null, afterShowSearch : null, onInitializeSearch: null, afterRedraw : null, closeAfterSearch : false, closeAfterReset: false, closeOnEscape : false, multipleSearch : false, multipleGroup : false, //cloneSearchRowOnAdd: true, top : 0, left: 0, jqModal : true, modal: false, resize : true, width: 450, height: 'auto', dataheight: 'auto', showQuery: false, errorcheck : true, // translation // if you want to change or remove the order change it in sopt // ['eq','ne','lt','le','gt','ge','bw','bn','in','ni','ew','en','cn','nc'], sopt: null, stringResult: undefined, onClose : null, onSearch : null, onReset : null, toTop : true, overlay : 30, columns : [], tmplNames : null, tmplFilters : null, // translations - later in lang file tmplLabel : ' Template: ', showOnLoad: false, layer: null }, $.jgrid.search, p || {}); return this.each(function() { var $t = this; if(!$t.grid) {return;} var fid = "fbox_"+$t.p.id, showFrm = true, IDs = {themodal:'searchmod'+fid,modalhead:'searchhd'+fid,modalcontent:'searchcnt'+fid, scrollelm : fid}, defaultFilters = $t.p.postData[p.sFilter], _filter = $("#"+$.jgrid.jqID(fid)); if(typeof(defaultFilters) === "string") { defaultFilters = $.jgrid.parse( defaultFilters ); } if(p.recreateFilter === true) { $("#"+$.jgrid.jqID(IDs.themodal)).remove(); } function showFilter() { showFrm = $($t).triggerHandler("jqGridFilterBeforeShow", [_filter]); if(typeof(showFrm) === "undefined") { showFrm = true; } if(showFrm && $.isFunction(p.beforeShowSearch)) { showFrm = p.beforeShowSearch.call($t,_filter); } if(showFrm) { $.jgrid.viewModal("#"+$.jgrid.jqID(IDs.themodal),{gbox:"#gbox_"+$.jgrid.jqID(fid),jqm:p.jqModal, modal:p.modal, overlay: p.overlay, toTop: p.toTop}); $($t).triggerHandler("jqGridFilterAfterShow", [_filter]); if($.isFunction(p.afterShowSearch)) { p.afterShowSearch.call($t, _filter); } } } if ( $("#"+$.jgrid.jqID(IDs.themodal)).html() !== null ) { showFilter(); } else { var fil = $("
").insertBefore("#gview_"+$.jgrid.jqID($t.p.id)), align = "left", butleft =""; if($t.p.direction == "rtl") { align = "right"; butleft = " style='text-align:left'"; fil.attr("dir","rtl"); } var columns = $.extend([],$t.p.colModel), bS =""+p.Find+"", bC =""+p.Reset+"", bQ = "", tmpl="", colnm, found = false, bt, cmi=-1; if(p.showQuery) { bQ ="Query"; } if(!p.columns.length) { $.each(columns, function(i,n){ if(!n.label) { n.label = $t.p.colNames[i]; } // find first searchable column and set it if no default filter if(!found) { var searchable = (typeof n.search === 'undefined') ? true: n.search , hidden = (n.hidden === true), ignoreHiding = (n.searchoptions && n.searchoptions.searchhidden === true); if ((ignoreHiding && searchable) || (searchable && !hidden)) { found = true; colnm = n.index || n.name; cmi =i; } } }); } else { columns = p.columns; } // old behaviour if( (!defaultFilters && colnm) || p.multipleSearch === false ) { var cmop = "eq"; if(cmi >=0 && columns[cmi].searchoptions && columns[cmi].searchoptions.sopt) { cmop = columns[cmi].searchoptions.sopt[0]; } else if(p.sopt && p.sopt.length) { cmop = p.sopt[0]; } defaultFilters = {"groupOp": "AND",rules:[{"field":colnm,"op":cmop,"data":""}]}; } found = false; if(p.tmplNames && p.tmplNames.length) { found = true; tmpl = p.tmplLabel; tmpl += ""; } bt = "

"+bC+tmpl+""+bQ+bS+"
"; fid = $.jgrid.jqID( fid); $("#"+fid).jqFilter({ columns : columns, filter: p.loadDefaults ? defaultFilters : null, showQuery: p.showQuery, errorcheck : p.errorcheck, sopt: p.sopt, groupButton : p.multipleGroup, ruleButtons : p.multipleSearch, afterRedraw : p.afterRedraw, _gridsopt : $.jgrid.search.odata, ajaxSelectOptions: $t.p.ajaxSelectOptions, groupOps: p.groupOps, onChange : function() { if(this.p.showQuery) { $('.query',this).html(this.toUserFriendlyString()); } }, direction : $t.p.direction }); fil.append( bt ); if(found && p.tmplFilters && p.tmplFilters.length) { $(".ui-template", fil).bind('change', function(){ var curtempl = $(this).val(); if(curtempl=="default") { $("#"+fid).jqFilter('addFilter', defaultFilters); } else { $("#"+fid).jqFilter('addFilter', p.tmplFilters[parseInt(curtempl,10)]); } return false; }); } if(p.multipleGroup === true) {p.multipleSearch = true;} $($t).triggerHandler("jqGridFilterInitialize", [$("#"+fid)]); if($.isFunction(p.onInitializeSearch) ) { p.onInitializeSearch.call($t, $("#"+fid)); } p.gbox = "#gbox_"+fid; if (p.layer) { $.jgrid.createModal(IDs ,fil,p,"#gview_"+$.jgrid.jqID($t.p.id),$("#gbox_"+$.jgrid.jqID($t.p.id))[0], "#"+$.jgrid.jqID(p.layer), {position: "relative"}); } else { $.jgrid.createModal(IDs ,fil,p,"#gview_"+$.jgrid.jqID($t.p.id),$("#gbox_"+$.jgrid.jqID($t.p.id))[0]); } if(bQ) { $("#"+fid+"_query").bind('click', function(){ $(".queryresult", fil).toggle(); return false; }); } if (p.stringResult===undefined) { // to provide backward compatibility, inferring stringResult value from multipleSearch p.stringResult = p.multipleSearch; } $("#"+fid+"_search").bind('click', function(){ var fl = $("#"+fid), sdata={}, res , filters = fl.jqFilter('filterData'); if(p.errorcheck) { fl[0].hideError(); if(!p.showQuery) {fl.jqFilter('toSQLString');} if(fl[0].p.error) { fl[0].showError(); return false; } } if(p.stringResult) { try { // xmlJsonClass or JSON.stringify res = xmlJsonClass.toJson(filters, '', '', false); } catch (e) { try { res = JSON.stringify(filters); } catch (e2) { } } if(typeof(res)==="string") { sdata[p.sFilter] = res; $.each([p.sField,p.sValue, p.sOper], function() {sdata[this] = "";}); } } else { if(p.multipleSearch) { sdata[p.sFilter] = filters; $.each([p.sField,p.sValue, p.sOper], function() {sdata[this] = "";}); } else { sdata[p.sField] = filters.rules[0].field; sdata[p.sValue] = filters.rules[0].data; sdata[p.sOper] = filters.rules[0].op; sdata[p.sFilter] = ""; } } $t.p.search = true; $.extend($t.p.postData,sdata); $($t).triggerHandler("jqGridFilterSearch"); if($.isFunction(p.onSearch) ) { p.onSearch.call($t); } $($t).trigger("reloadGrid",[{page:1}]); if(p.closeAfterSearch) { $.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:"#gbox_"+$.jgrid.jqID($t.p.id),jqm:p.jqModal,onClose: p.onClose}); } return false; }); $("#"+fid+"_reset").bind('click', function(){ var sdata={}, fl = $("#"+fid); $t.p.search = false; if(p.multipleSearch===false) { sdata[p.sField] = sdata[p.sValue] = sdata[p.sOper] = ""; } else { sdata[p.sFilter] = ""; } fl[0].resetFilter(); if(found) { $(".ui-template", fil).val("default"); } $.extend($t.p.postData,sdata); $($t).triggerHandler("jqGridFilterReset"); if($.isFunction(p.onReset) ) { p.onReset.call($t); } $($t).trigger("reloadGrid",[{page:1}]); return false; }); showFilter(); $(".fm-button:not(.ui-state-disabled)",fil).hover( function(){$(this).addClass('ui-state-hover');}, function(){$(this).removeClass('ui-state-hover');} ); } }); }, editGridRow : function(rowid, p){ p = $.extend({ top : 0, left: 0, width: 300, 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, _savedData : {}, processing : false, onClose : null, ajaxEditOptions : {}, serializeEditData : null, viewPagerButtons : true }, $.jgrid.edit, p || {}); rp_ge[$(this)[0].p.id] = p; return this.each(function(){ var $t = this; if (!$t.grid || !rowid) {return;} var gID = $t.p.id, frmgr = "FrmGrid_"+gID, frmtborg = "TblGrid_"+gID, frmtb = "#"+$.jgrid.jqID(frmtborg), IDs = {themodal:'editmod'+gID,modalhead:'edithd'+gID,modalcontent:'editcnt'+gID, scrollelm : frmgr}, onBeforeShow = $.isFunction(rp_ge[$t.p.id].beforeShowForm) ? rp_ge[$t.p.id].beforeShowForm : false, onAfterShow = $.isFunction(rp_ge[$t.p.id].afterShowForm) ? rp_ge[$t.p.id].afterShowForm : false, onBeforeInit = $.isFunction(rp_ge[$t.p.id].beforeInitData) ? rp_ge[$t.p.id].beforeInitData : false, onInitializeForm = $.isFunction(rp_ge[$t.p.id].onInitializeForm) ? rp_ge[$t.p.id].onInitializeForm : false, showFrm = true, maxCols = 1, maxRows=0, postdata, extpost, newData, diff, frmoper; frmgr = $.jgrid.jqID(frmgr); 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===true && $("#"+$.jgrid.jqID(IDs.themodal)).html() !== null) { $("#"+$.jgrid.jqID(IDs.themodal)).remove(); } var closeovrl = true; if(p.checkOnUpdate && p.jqModal && !p.modal) { closeovrl = false; } function getFormData(){ $(frmtb+" > tbody > tr > td > .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 && $.isFunction(this.editoptions.custom_value)) { try { postdata[nm] = this.editoptions.custom_value.call($t, $("#"+$.jgrid.jqID(nm),frmtb),'get'); if (postdata[nm] === undefined) {throw "e1";} } catch (e) { if (e==="e1") {$.jgrid.info_dialog(jQuery.jgrid.errors.errcap,"function 'custom_value' "+$.jgrid.edit.msg.novalue,jQuery.jgrid.edit.bClose);} else {$.jgrid.info_dialog(jQuery.jgrid.errors.errcap,e.message,jQuery.jgrid.edit.bClose);} } 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]= $("option:selected",this).val(); extpost[this.name]= $("option:selected",this).text(); break; case "select-multiple": postdata[this.name]= $(this).val(); if(postdata[this.name]) {postdata[this.name] = postdata[this.name].join(",");} else {postdata[this.name] ="";} var selectedText = []; $("option:selected",this).each( function(i,selected){ selectedText[i] = $(selected).text(); } ); extpost[this.name]= selectedText.join(","); break; case "password": case "text": case "textarea": case "button": postdata[this.name] = $(this).val(); break; } if($t.p.autoencode) {postdata[this.name] = $.jgrid.htmlEncode(postdata[this.name]);} } }); return true; } function createData(rowid,obj,tb,maxcols){ var nm, hc,trdata, cnt=0,tmp, dc,elc, retpos=[], ind=false, tdtmpl = "  ", tmpl="", i; //*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') { if(ind === false) { tmp = ""; } else { if(nm == obj.p.ExpandColumn && obj.p.treeGrid === true) { tmp = $("td:eq("+i+")",obj.rows[ind]).text(); } else { try { tmp = $.unformat.call(obj, $("td:eq("+i+")",obj.rows[ind]),{rowId:rowid, colModel:this},i); } catch (_) { tmp = (this.edittype && this.edittype == "textarea") ? $("td:eq("+i+")",obj.rows[ind]).text() : $("td:eq("+i+")",obj.rows[ind]).html(); } if(!tmp || tmp == " " || tmp == " " || (tmp.length==1 && tmp.charCodeAt(0)==160) ) {tmp='';} } } var opt = $.extend({}, this.editoptions || {} ,{id:nm,name:nm}), 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 = $.isFunction(opt.defaultValue) ? opt.defaultValue() : opt.defaultValue; } if(!this.edittype) {this.edittype = "text";} if($t.p.autoencode) {tmp = $.jgrid.htmlDecode(tmp);} elc = $.jgrid.createEl(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(rp_ge[$t.p.id].checkOnSubmit || rp_ge[$t.p.id].checkOnUpdate) {rp_ge[$t.p.id]._savedData[nm] = tmp;} $(elc).addClass("FormElement"); if(this.edittype == 'text' || this.edittype == 'textarea') { $(elc).addClass("ui-widget-content ui-corner-all"); } trdata = $(tb).find("tr[rowpos="+rp+"]"); if(frmopt.rowabove) { var newdata = $(""+frmopt.rowcontent+""); $(tb).append(newdata); newdata[0].rp = rp; } if ( trdata.length===0 ) { trdata = $("").addClass("FormData").attr("id","tr_"+nm); $(trdata).append(tmpl); $(tb).append(trdata); trdata[0].rp = rp; } $("td:eq("+(cp-2)+")",trdata[0]).html( typeof frmopt.label === 'undefined' ? obj.p.colNames[i]: frmopt.label); $("td:eq("+(cp-1)+")",trdata[0]).append(frmopt.elmprefix).append(elc).append(frmopt.elmsuffix); retpos[cnt] = i; cnt++; } }); if( cnt > 0) { var idrow = $(""); idrow[0].rp = cnt+999; $(tb).append(idrow); if(rp_ge[$t.p.id].checkOnSubmit || rp_ge[$t.p.id].checkOnUpdate) {rp_ge[$t.p.id]._savedData[obj.p.id+"_id"] = rowid;} } return retpos; } function fillData(rowid,obj,fmid){ var nm,cnt=0,tmp, fld,opt,vl,vlc; if(rp_ge[$t.p.id].checkOnSubmit || rp_ge[$t.p.id].checkOnUpdate) {rp_ge[$t.p.id]._savedData = {};rp_ge[$t.p.id]._savedData[obj.p.id+"_id"]=rowid;} var cm = obj.p.colModel; if(rowid == '_empty') { $(cm).each(function(){ nm = this.name; opt = $.extend({}, this.editoptions || {} ); fld = $("#"+$.jgrid.jqID(nm),"#"+fmid); if(fld && fld.length && fld[0] !== null) { vl = ""; if(opt.defaultValue ) { vl = $.isFunction(opt.defaultValue) ? opt.defaultValue() : opt.defaultValue; if(fld[0].type=='checkbox') { vlc = vl.toLowerCase(); if(vlc.search(/(false|0|no|off|undefined)/i)<0 && vlc!=="") { fld[0].checked = true; fld[0].defaultChecked = true; fld[0].value = vl; } else { fld[0].checked = false; fld[0].defaultChecked = false; } } else {fld.val(vl);} } else { if( fld[0].type=='checkbox' ) { fld[0].checked = false; fld[0].defaultChecked = false; vl = $(fld).attr("offval"); } else if (fld[0].type && fld[0].type.substr(0,6)=='select') { fld[0].selectedIndex = 0; } else { fld.val(vl); } } if(rp_ge[$t.p.id].checkOnSubmit===true || rp_ge[$t.p.id].checkOnUpdate) {rp_ge[$t.p.id]._savedData[nm] = vl;} } }); $("#id_g","#"+fmid).val(rowid); return; } var tre = $(obj).jqGrid("getInd",rowid,true); if(!tre) {return;} $('td[role="gridcell"]',tre).each( function(i) { nm = cm[i].name; // hidden fields are included in the form if ( nm !== 'cb' && nm !== 'subgrid' && nm !== 'rn' && cm[i].editable===true) { if(nm == obj.p.ExpandColumn && obj.p.treeGrid === true) { tmp = $(this).text(); } else { try { tmp = $.unformat.call(obj, $(this),{rowId:rowid, colModel:cm[i]},i); } catch (_) { tmp = cm[i].edittype=="textarea" ? $(this).text() : $(this).html(); } } if($t.p.autoencode) {tmp = $.jgrid.htmlDecode(tmp);} if(rp_ge[$t.p.id].checkOnSubmit===true || rp_ge[$t.p.id].checkOnUpdate) {rp_ge[$t.p.id]._savedData[nm] = tmp;} nm = $.jgrid.jqID(nm); switch (cm[i].edittype) { case "password": case "text": case "button" : case "image": case "textarea": if(tmp == " " || tmp == " " || (tmp.length==1 && tmp.charCodeAt(0)==160) ) {tmp='';} $("#"+nm,"#"+fmid).val(tmp); break; case "select": var opv = tmp.split(","); opv = $.map(opv,function(n){return $.trim(n);}); $("#"+nm+" option","#"+fmid).each(function(){ if (!cm[i].editoptions.multiple && ($.trim(tmp) == $.trim($(this).text()) || opv[0] == $.trim($(this).text()) || opv[0] == $.trim($(this).val())) ){ this.selected= true; } else if (cm[i].editoptions.multiple){ if( $.inArray($.trim($(this).text()), opv ) > -1 || $.inArray($.trim($(this).val()), opv ) > -1 ){ this.selected = true; }else{ this.selected = false; } } else { this.selected = false; } }); break; case "checkbox": tmp = tmp+""; if(cm[i].editoptions && cm[i].editoptions.value) { var cb = cm[i].editoptions.value.split(":"); if(cb[0] == tmp) { $("#"+nm,"#"+fmid)[$t.p.useProp ? 'prop': 'attr']("checked",true); $("#"+nm,"#"+fmid)[$t.p.useProp ? 'prop': 'attr']("defaultChecked",true); //ie } else { $("#"+nm,"#"+fmid)[$t.p.useProp ? 'prop': 'attr']("checked", false); $("#"+nm,"#"+fmid)[$t.p.useProp ? 'prop': 'attr']("defaultChecked", false); //ie } } else { tmp = tmp.toLowerCase(); if(tmp.search(/(false|0|no|off|undefined)/i)<0 && tmp!=="") { $("#"+nm,"#"+fmid)[$t.p.useProp ? 'prop': 'attr']("checked",true); $("#"+nm,"#"+fmid)[$t.p.useProp ? 'prop': 'attr']("defaultChecked",true); //ie } else { $("#"+nm,"#"+fmid)[$t.p.useProp ? 'prop': 'attr']("checked", false); $("#"+nm,"#"+fmid)[$t.p.useProp ? 'prop': 'attr']("defaultChecked", false); //ie } } break; case 'custom' : try { if(cm[i].editoptions && $.isFunction(cm[i].editoptions.custom_value)) { cm[i].editoptions.custom_value.call($t, $("#"+nm,"#"+fmid),'set',tmp); } else {throw "e1";} } catch (e) { if (e=="e1") {$.jgrid.info_dialog(jQuery.jgrid.errors.errcap,"function 'custom_value' "+$.jgrid.edit.msg.nodefined,jQuery.jgrid.edit.bClose);} else {$.jgrid.info_dialog(jQuery.jgrid.errors.errcap,e.message,jQuery.jgrid.edit.bClose);} } break; } cnt++; } }); if(cnt>0) {$("#id_g",frmtb).val(rowid);} } function setNulls() { $.each($t.p.colModel, function(i,n){ if(n.editoptions && n.editoptions.NullIfEmpty === true) { if(postdata.hasOwnProperty(n.name) && postdata[n.name] === "") { postdata[n.name] = 'null'; } } }); } function postIt() { var copydata, ret=[true,"",""], onCS = {}, opers = $t.p.prmNames, idname, oper, key, selr, i; var retvals = $($t).triggerHandler("jqGridAddEditBeforeCheckValues", [$("#"+frmgr), frmoper]); if(retvals && typeof(retvals) === 'object') {postdata = retvals;} if($.isFunction(rp_ge[$t.p.id].beforeCheckValues)) { retvals = rp_ge[$t.p.id].beforeCheckValues.call($t, postdata,$("#"+frmgr),postdata[$t.p.id+"_id"] == "_empty" ? opers.addoper : opers.editoper); if(retvals && typeof(retvals) === 'object') {postdata = retvals;} } for( key in postdata ){ if(postdata.hasOwnProperty(key)) { ret = $.jgrid.checkValues(postdata[key],key,$t); if(ret[0] === false) {break;} } } setNulls(); if(ret[0]) { onCS = $($t).triggerHandler("jqGridAddEditClickSubmit", [rp_ge[$t.p.id], postdata, frmoper]); if( onCS === undefined && $.isFunction( rp_ge[$t.p.id].onclickSubmit)) { onCS = rp_ge[$t.p.id].onclickSubmit.call($t, rp_ge[$t.p.id], postdata) || {}; } ret = $($t).triggerHandler("jqGridAddEditBeforeSubmit", [postdata, $("#"+frmgr), frmoper]); if(ret === undefined) { ret = [true,"",""]; } if( ret[0] && $.isFunction(rp_ge[$t.p.id].beforeSubmit)) { ret = rp_ge[$t.p.id].beforeSubmit(postdata,$("#"+frmgr)); } } if(ret[0] && !rp_ge[$t.p.id].processing) { rp_ge[$t.p.id].processing = true; $("#sData", frmtb+"_2").addClass('ui-state-active'); oper = opers.oper; idname = opers.id; // we add to pos data array the action - the name is oper postdata[oper] = ($.trim(postdata[$t.p.id+"_id"]) == "_empty") ? opers.addoper : opers.editoper; if(postdata[oper] != opers.addoper) { postdata[idname] = postdata[$t.p.id+"_id"]; } else { // check to see if we have allredy this field in the form and if yes lieve it if( postdata[idname] === undefined ) {postdata[idname] = postdata[$t.p.id+"_id"];} } delete postdata[$t.p.id+"_id"]; postdata = $.extend(postdata,rp_ge[$t.p.id].editData,onCS); if($t.p.treeGrid === true) { if(postdata[oper] == opers.addoper) { selr = $($t).jqGrid("getGridParam", 'selrow'); var tr_par_id = $t.p.treeGridModel == 'adjacency' ? $t.p.treeReader.parent_id_field : 'parent_id'; postdata[tr_par_id] = selr; } for(i in $t.p.treeReader){ if($t.p.treeReader.hasOwnProperty(i)) { var itm = $t.p.treeReader[i]; if(postdata.hasOwnProperty(itm)) { if(postdata[oper] == opers.addoper && i === 'parent_id_field') {continue;} delete postdata[itm]; } } } } postdata[idname] = $.jgrid.stripPref($t.p.idPrefix, postdata[idname]); var ajaxOptions = $.extend({ url: rp_ge[$t.p.id].url ? rp_ge[$t.p.id].url : $($t).jqGrid('getGridParam','editurl'), type: rp_ge[$t.p.id].mtype, data: $.isFunction(rp_ge[$t.p.id].serializeEditData) ? rp_ge[$t.p.id].serializeEditData(postdata) : postdata, complete:function(data,Status){ postdata[idname] = $t.p.idPrefix + postdata[idname]; if(Status != "success") { ret[0] = false; ret[1] = $($t).triggerHandler("jqGridAddEditErrorTextFormat", [data, frmoper]); if ($.isFunction(rp_ge[$t.p.id].errorTextFormat)) { ret[1] = rp_ge[$t.p.id].errorTextFormat.call($t, data); } else { ret[1] = Status + " Status: '" + data.statusText + "'. Error code: " + data.status; } } else { // data is posted successful // execute aftersubmit with the returned data from server ret = $($t).triggerHandler("jqGridAddEditAfterSubmit", [data, postdata, frmoper]); if(ret === undefined) { ret = [true,"",""]; } if( ret[0] && $.isFunction(rp_ge[$t.p.id].afterSubmit) ) { ret = rp_ge[$t.p.id].afterSubmit.call($t, data,postdata); } } if(ret[0] === false) { $("#FormError>td",frmtb).html(ret[1]); $("#FormError",frmtb).show(); } else { // remove some values if formattaer select or checkbox $.each($t.p.colModel, function(){ if(extpost[this.name] && this.formatter && this.formatter=='select') { try {delete extpost[this.name];} catch (e) {} } }); postdata = $.extend(postdata,extpost); if($t.p.autoencode) { $.each(postdata,function(n,v){ postdata[n] = $.jgrid.htmlDecode(v); }); } //rp_ge[$t.p.id].reloadAfterSubmit = rp_ge[$t.p.id].reloadAfterSubmit && $t.p.datatype != "local"; // the action is add if(postdata[oper] == opers.addoper ) { //id processing // user not set the id ret[2] if(!ret[2]) {ret[2] = $.jgrid.randId();} postdata[idname] = ret[2]; if(rp_ge[$t.p.id].closeAfterAdd) { if(rp_ge[$t.p.id].reloadAfterSubmit) {$($t).trigger("reloadGrid");} else { if($t.p.treeGrid === true){ $($t).jqGrid("addChildNode",ret[2],selr,postdata ); } else { $($t).jqGrid("addRowData",ret[2],postdata,p.addedrow); $($t).jqGrid("setSelection",ret[2]); } } $.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:"#gbox_"+$.jgrid.jqID(gID),jqm:p.jqModal,onClose: rp_ge[$t.p.id].onClose}); } else if (rp_ge[$t.p.id].clearAfterAdd) { if(rp_ge[$t.p.id].reloadAfterSubmit) {$($t).trigger("reloadGrid");} else { if($t.p.treeGrid === true){ $($t).jqGrid("addChildNode",ret[2],selr,postdata ); } else { $($t).jqGrid("addRowData",ret[2],postdata,p.addedrow); } } fillData("_empty",$t,frmgr); } else { if(rp_ge[$t.p.id].reloadAfterSubmit) {$($t).trigger("reloadGrid");} else { if($t.p.treeGrid === true){ $($t).jqGrid("addChildNode",ret[2],selr,postdata ); } else { $($t).jqGrid("addRowData",ret[2],postdata,p.addedrow); } } } } else { // the action is update if(rp_ge[$t.p.id].reloadAfterSubmit) { $($t).trigger("reloadGrid"); if( !rp_ge[$t.p.id].closeAfterEdit ) {setTimeout(function(){$($t).jqGrid("setSelection",postdata[idname]);},1000);} } else { if($t.p.treeGrid === true) { $($t).jqGrid("setTreeRow", postdata[idname],postdata); } else { $($t).jqGrid("setRowData", postdata[idname],postdata); } } if(rp_ge[$t.p.id].closeAfterEdit) {$.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:"#gbox_"+$.jgrid.jqID(gID),jqm:p.jqModal,onClose: rp_ge[$t.p.id].onClose});} } if($.isFunction(rp_ge[$t.p.id].afterComplete)) { copydata = data; setTimeout(function(){ $($t).triggerHandler("jqGridAddEditAfterComplete", [copydata, postdata, $("#"+frmgr), frmoper]); rp_ge[$t.p.id].afterComplete.call($t, copydata, postdata, $("#"+frmgr)); copydata=null; },500); } if(rp_ge[$t.p.id].checkOnSubmit || rp_ge[$t.p.id].checkOnUpdate) { $("#"+frmgr).data("disabled",false); if(rp_ge[$t.p.id]._savedData[$t.p.id+"_id"] !="_empty"){ for(var key in rp_ge[$t.p.id]._savedData) { if(postdata[key]) { rp_ge[$t.p.id]._savedData[key] = postdata[key]; } } } } } rp_ge[$t.p.id].processing=false; $("#sData", frmtb+"_2").removeClass('ui-state-active'); try{$(':input:visible',"#"+frmgr)[0].focus();} catch (e){} } }, $.jgrid.ajaxOptions, rp_ge[$t.p.id].ajaxEditOptions ); if (!ajaxOptions.url && !rp_ge[$t.p.id].useDataProxy) { if ($.isFunction($t.p.dataProxy)) { rp_ge[$t.p.id].useDataProxy = true; } else { ret[0]=false;ret[1] += " "+$.jgrid.errors.nourl; } } if (ret[0]) { if (rp_ge[$t.p.id].useDataProxy) { var dpret = $t.p.dataProxy.call($t, ajaxOptions, "set_"+$t.p.id); if(typeof(dpret) == "undefined") { dpret = [true, ""]; } if(dpret[0] === false ) { ret[0] = false; ret[1] = dpret[1] || "Error deleting the selected row!" ; } else { if(ajaxOptions.data.oper == opers.addoper && rp_ge[$t.p.id].closeAfterAdd ) { $.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:"#gbox_"+$.jgrid.jqID(gID),jqm:p.jqModal, onClose: rp_ge[$t.p.id].onClose}); } if(ajaxOptions.data.oper == opers.editoper && rp_ge[$t.p.id].closeAfterEdit ) { $.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:"#gbox_"+$.jgrid.jqID(gID),jqm:p.jqModal, onClose: rp_ge[$t.p.id].onClose}); } } } else { $.ajax(ajaxOptions); } } } if(ret[0] === false) { $("#FormError>td",frmtb).html(ret[1]); $("#FormError",frmtb).show(); // return; } } function compareData(nObj, oObj ) { var ret = false,key; for (key in nObj) { if(nObj[key] != oObj[key]) { ret = true; break; } } return ret; } function checkUpdates () { var stat = true; $("#FormError",frmtb).hide(); if(rp_ge[$t.p.id].checkOnUpdate) { postdata = {};extpost={}; getFormData(); newData = $.extend({},postdata,extpost); diff = compareData(newData,rp_ge[$t.p.id]._savedData); if(diff) { $("#"+frmgr).data("disabled",true); $(".confirm","#"+IDs.themodal).show(); stat = false; } } return stat; } function restoreInline() { if (rowid !== "_empty" && typeof($t.p.savedRow) !== "undefined" && $t.p.savedRow.length > 0 && $.isFunction($.fn.jqGrid.restoreRow)) { for (var i=0;i<$t.p.savedRow.length;i++) { if ($t.p.savedRow[i].id == rowid) { $($t).jqGrid('restoreRow',rowid); break; } } } } function updateNav(cr,totr){ if (cr===0) {$("#pData",frmtb+"_2").addClass('ui-state-disabled');} else {$("#pData",frmtb+"_2").removeClass('ui-state-disabled');} if (cr==totr) {$("#nData",frmtb+"_2").addClass('ui-state-disabled');} else {$("#nData",frmtb+"_2").removeClass('ui-state-disabled');} } function getCurrPos() { var rowsInGrid = $($t).jqGrid("getDataIDs"), selrow = $("#id_g",frmtb).val(), pos = $.inArray(selrow,rowsInGrid); return [pos,rowsInGrid]; } if ( $("#"+$.jgrid.jqID(IDs.themodal)).html() !== null ) { showFrm = $($t).triggerHandler("jqGridAddEditBeforeInitData", [$("#"+$.jgrid.jqID(frmgr))]); if(typeof(showFrm) == "undefined") { showFrm = true; } if(showFrm && onBeforeInit) { showFrm = onBeforeInit.call($t, $("#"+frmgr)); } if(showFrm === false) {return;} restoreInline(); $(".ui-jqdialog-title","#"+$.jgrid.jqID(IDs.modalhead)).html(p.caption); $("#FormError",frmtb).hide(); if(rp_ge[$t.p.id].topinfo) { $(".topinfo",frmtb).html(rp_ge[$t.p.id].topinfo); $(".tinfo",frmtb).show(); } else { $(".tinfo",frmtb).hide(); } if(rp_ge[$t.p.id].bottominfo) { $(".bottominfo",frmtb+"_2").html(rp_ge[$t.p.id].bottominfo); $(".binfo",frmtb+"_2").show(); } else { $(".binfo",frmtb+"_2").hide(); } // filldata fillData(rowid,$t,frmgr); /// if(rowid=="_empty" || !rp_ge[$t.p.id].viewPagerButtons) { $("#pData, #nData",frmtb+"_2").hide(); } else { $("#pData, #nData",frmtb+"_2").show(); } if(rp_ge[$t.p.id].processing===true) { rp_ge[$t.p.id].processing=false; $("#sData", frmtb+"_2").removeClass('ui-state-active'); } if($("#"+frmgr).data("disabled")===true) { $(".confirm","#"+$.jgrid.jqID(IDs.themodal)).hide(); $("#"+frmgr).data("disabled",false); } $($t).triggerHandler("jqGridAddEditBeforeShowForm", [$("#"+frmgr), frmoper]); if(onBeforeShow) { onBeforeShow.call($t, $("#"+frmgr)); } $("#"+$.jgrid.jqID(IDs.themodal)).data("onClose",rp_ge[$t.p.id].onClose); $.jgrid.viewModal("#"+$.jgrid.jqID(IDs.themodal),{gbox:"#gbox_"+$.jgrid.jqID(gID),jqm:p.jqModal, jqM: false, overlay: p.overlay, modal:p.modal}); if(!closeovrl) { $(".jqmOverlay").click(function(){ if(!checkUpdates()) {return false;} $.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:"#gbox_"+$.jgrid.jqID(gID),jqm:p.jqModal, onClose: rp_ge[$t.p.id].onClose}); return false; }); } $($t).triggerHandler("jqGridAddEditAfterShowForm", [$("#"+frmgr), frmoper]); if(onAfterShow) { onAfterShow.call($t, $("#"+frmgr)); } } else { var dh = isNaN(p.dataheight) ? p.dataheight : p.dataheight+"px", frm = $("
").data("disabled",false), tbl = $("
"); showFrm = $($t).triggerHandler("jqGridAddEditBeforeInitData", [$("#"+frmgr), frmoper]); if(typeof(showFrm) == "undefined") { showFrm = true; } if(showFrm && onBeforeInit) { showFrm = onBeforeInit.call($t, $("#"+frmgr)); } if(showFrm === false) {return;} restoreInline(); $($t.p.colModel).each( function() { var fmto = this.formoptions; maxCols = Math.max(maxCols, fmto ? fmto.colpos || 0 : 0 ); maxRows = Math.max(maxRows, fmto ? fmto.rowpos || 0 : 0 ); }); $(frm).append(tbl); var flr = $(""); flr[0].rp = 0; $(tbl).append(flr); //topinfo flr = $(""+rp_ge[$t.p.id].topinfo+""); flr[0].rp = 0; $(tbl).append(flr); // set the id. // use carefull only to change here colproperties. // create data var rtlb = $t.p.direction == "rtl" ? true :false, bp = rtlb ? "nData" : "pData", bn = rtlb ? "pData" : "nData"; createData(rowid,$t,tbl,maxCols); // buttons at footer var bP = "", bN = "", bS =""+p.bSubmit+"", bC =""+p.bCancel+""; var bt = ""; bt += ""; bt += "

"+bS+bC+"
"; if(maxRows > 0) { var sd=[]; $.each($(tbl)[0].rows,function(i,r){ sd[i] = r; }); sd.sort(function(a,b){ if(a.rp > b.rp) {return 1;} if(a.rp < b.rp) {return -1;} return 0; }); $.each(sd, function(index, row) { $('tbody',tbl).append(row); }); } p.gbox = "#gbox_"+$.jgrid.jqID(gID); var cle = false; if(p.closeOnEscape===true){ p.closeOnEscape = false; cle = true; } var tms = $("").append(frm).append(bt); $.jgrid.createModal(IDs,tms,p,"#gview_"+$.jgrid.jqID($t.p.id),$("#gbox_"+$.jgrid.jqID($t.p.id))[0]); if(rtlb) { $("#pData, #nData",frmtb+"_2").css("float","right"); $(".EditButton",frmtb+"_2").css("text-align","left"); } if(rp_ge[$t.p.id].topinfo) {$(".tinfo",frmtb).show();} if(rp_ge[$t.p.id].bottominfo) {$(".binfo",frmtb+"_2").show();} tms = null;bt=null; $("#"+$.jgrid.jqID(IDs.themodal)).keydown( function( e ) { var wkey = e.target; if ($("#"+frmgr).data("disabled")===true ) {return false;}//?? if(rp_ge[$t.p.id].savekey[0] === true && e.which == rp_ge[$t.p.id].savekey[1]) { // save if(wkey.tagName != "TEXTAREA") { $("#sData", frmtb+"_2").trigger("click"); return false; } } if(e.which === 27) { if(!checkUpdates()) {return false;} if(cle) {$.jgrid.hideModal(this,{gb:p.gbox,jqm:p.jqModal, onClose: rp_ge[$t.p.id].onClose});} return false; } if(rp_ge[$t.p.id].navkeys[0]===true) { if($("#id_g",frmtb).val() == "_empty") {return true;} if(e.which == rp_ge[$t.p.id].navkeys[1]){ //up $("#pData", frmtb+"_2").trigger("click"); return false; } if(e.which == rp_ge[$t.p.id].navkeys[2]){ //down $("#nData", frmtb+"_2").trigger("click"); return false; } } }); if(p.checkOnUpdate) { $("a.ui-jqdialog-titlebar-close span","#"+$.jgrid.jqID(IDs.themodal)).removeClass("jqmClose"); $("a.ui-jqdialog-titlebar-close","#"+$.jgrid.jqID(IDs.themodal)).unbind("click") .click(function(){ if(!checkUpdates()) {return false;} $.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:"#gbox_"+$.jgrid.jqID(gID),jqm:p.jqModal,onClose: rp_ge[$t.p.id].onClose}); return false; }); } p.saveicon = $.extend([true,"left","ui-icon-disk"],p.saveicon); p.closeicon = $.extend([true,"left","ui-icon-close"],p.closeicon); // beforeinitdata after creation of the form if(p.saveicon[0]===true) { $("#sData",frmtb+"_2").addClass(p.saveicon[1] == "right" ? 'fm-button-icon-right' : 'fm-button-icon-left') .append(""); } if(p.closeicon[0]===true) { $("#cData",frmtb+"_2").addClass(p.closeicon[1] == "right" ? 'fm-button-icon-right' : 'fm-button-icon-left') .append(""); } if(rp_ge[$t.p.id].checkOnSubmit || rp_ge[$t.p.id].checkOnUpdate) { bS =""+p.bYes+""; bN =""+p.bNo+""; bC =""+p.bExit+""; var ii, zI = p.zIndex || 999;zI ++; if ($.browser.msie && $.browser.version ==6) { ii = ''; } else {ii="";} $("
"+p.saveData+"

"+bS+bN+bC+"
").insertAfter("#"+frmgr); $("#sNew","#"+$.jgrid.jqID(IDs.themodal)).click(function(){ postIt(); $("#"+frmgr).data("disabled",false); $(".confirm","#"+$.jgrid.jqID(IDs.themodal)).hide(); return false; }); $("#nNew","#"+$.jgrid.jqID(IDs.themodal)).click(function(){ $(".confirm","#"+$.jgrid.jqID(IDs.themodal)).hide(); $("#"+frmgr).data("disabled",false); setTimeout(function(){$(":input","#"+frmgr)[0].focus();},0); return false; }); $("#cNew","#"+$.jgrid.jqID(IDs.themodal)).click(function(){ $(".confirm","#"+$.jgrid.jqID(IDs.themodal)).hide(); $("#"+frmgr).data("disabled",false); $.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:"#gbox_"+$.jgrid.jqID(gID),jqm:p.jqModal,onClose: rp_ge[$t.p.id].onClose}); return false; }); } // here initform - only once $($t).triggerHandler("jqGridAddEditInitializeForm", [$("#"+frmgr), frmoper]); if(onInitializeForm) {onInitializeForm($("#"+frmgr));} if(rowid=="_empty" || !rp_ge[$t.p.id].viewPagerButtons) {$("#pData,#nData",frmtb+"_2").hide();} else {$("#pData,#nData",frmtb+"_2").show();} $($t).triggerHandler("jqGridAddEditBeforeShowForm", [$("#"+frmgr), frmoper]); if(onBeforeShow) { onBeforeShow.call($t, $("#"+frmgr));} $("#"+$.jgrid.jqID(IDs.themodal)).data("onClose",rp_ge[$t.p.id].onClose); $.jgrid.viewModal("#"+$.jgrid.jqID(IDs.themodal),{gbox:"#gbox_"+$.jgrid.jqID(gID),jqm:p.jqModal, overlay: p.overlay,modal:p.modal}); if(!closeovrl) { $(".jqmOverlay").click(function(){ if(!checkUpdates()) {return false;} $.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:"#gbox_"+$.jgrid.jqID(gID),jqm:p.jqModal, onClose: rp_ge[$t.p.id].onClose}); return false; }); } $($t).triggerHandler("jqGridAddEditAfterShowForm", [$("#"+frmgr), frmoper]); if(onAfterShow) { onAfterShow.call($t, $("#"+frmgr)); } $(".fm-button","#"+$.jgrid.jqID(IDs.themodal)).hover( function(){$(this).addClass('ui-state-hover');}, function(){$(this).removeClass('ui-state-hover');} ); $("#sData", frmtb+"_2").click(function(){ postdata = {};extpost={}; $("#FormError",frmtb).hide(); // all depend on ret array //ret[0] - succes //ret[1] - msg if not succes //ret[2] - the id that will be set if reload after submit false getFormData(); if(postdata[$t.p.id+"_id"] == "_empty") {postIt();} else if(p.checkOnSubmit===true ) { newData = $.extend({},postdata,extpost); diff = compareData(newData,rp_ge[$t.p.id]._savedData); if(diff) { $("#"+frmgr).data("disabled",true); $(".confirm","#"+$.jgrid.jqID(IDs.themodal)).show(); } else { postIt(); } } else { postIt(); } return false; }); $("#cData", frmtb+"_2").click(function(){ if(!checkUpdates()) {return false;} $.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:"#gbox_"+$.jgrid.jqID(gID),jqm:p.jqModal,onClose: rp_ge[$t.p.id].onClose}); return false; }); $("#nData", frmtb+"_2").click(function(){ if(!checkUpdates()) {return false;} $("#FormError",frmtb).hide(); var npos = getCurrPos(); npos[0] = parseInt(npos[0],10); if(npos[0] != -1 && npos[1][npos[0]+1]) { $($t).triggerHandler("jqGridAddEditClickPgButtons", ['next',$("#"+frmgr),npos[1][npos[0]]]); if($.isFunction(p.onclickPgButtons)) { p.onclickPgButtons.call($t, 'next',$("#"+frmgr),npos[1][npos[0]]); } fillData(npos[1][npos[0]+1],$t,frmgr); $($t).jqGrid("setSelection",npos[1][npos[0]+1]); $($t).triggerHandler("jqGridAddEditAfterClickPgButtons", ['next',$("#"+frmgr),npos[1][npos[0]]]); if($.isFunction(p.afterclickPgButtons)) { p.afterclickPgButtons.call($t, 'next',$("#"+frmgr),npos[1][npos[0]+1]); } updateNav(npos[0]+1,npos[1].length-1); } return false; }); $("#pData", frmtb+"_2").click(function(){ if(!checkUpdates()) {return false;} $("#FormError",frmtb).hide(); var ppos = getCurrPos(); if(ppos[0] != -1 && ppos[1][ppos[0]-1]) { $($t).triggerHandler("jqGridAddEditClickPgButtons", ['prev',$("#"+frmgr),ppos[1][ppos[0]]]); if($.isFunction(p.onclickPgButtons)) { p.onclickPgButtons.call($t, 'prev',$("#"+frmgr),ppos[1][ppos[0]]); } fillData(ppos[1][ppos[0]-1],$t,frmgr); $($t).jqGrid("setSelection",ppos[1][ppos[0]-1]); $($t).triggerHandler("jqGridAddEditAfterClickPgButtons", ['prev',$("#"+frmgr),ppos[1][ppos[0]]]); if($.isFunction(p.afterclickPgButtons)) { p.afterclickPgButtons.call($t, 'prev',$("#"+frmgr),ppos[1][ppos[0]-1]); } updateNav(ppos[0]-1,ppos[1].length-1); } return false; }); } var posInit =getCurrPos(); updateNav(posInit[0],posInit[1].length-1); }); }, viewGridRow : function(rowid, p){ p = $.extend({ top : 0, left: 0, width: 0, height: 'auto', dataheight: 'auto', modal: false, overlay: 30, drag: true, resize: true, jqModal: true, closeOnEscape : false, labelswidth: '30%', closeicon: [], navkeys: [false,38,40], onClose: null, beforeShowForm : null, beforeInitData : null, viewPagerButtons : true }, $.jgrid.view, p || {}); return this.each(function(){ var $t = this; if (!$t.grid || !rowid) {return;} var gID = $t.p.id, frmgr = "ViewGrid_"+$.jgrid.jqID( gID ), frmtb = "ViewTbl_" + $.jgrid.jqID( gID ), frmgr_id = "ViewGrid_"+gID, frmtb_id = "ViewTbl_"+gID, IDs = {themodal:'viewmod'+gID,modalhead:'viewhd'+gID,modalcontent:'viewcnt'+gID, scrollelm : frmgr}, onBeforeInit = $.isFunction(p.beforeInitData) ? p.beforeInitData : false, showFrm = true, maxCols = 1, maxRows=0; function focusaref(){ //Sfari 3 issues if(p.closeOnEscape===true || p.navkeys[0]===true) { setTimeout(function(){$(".ui-jqdialog-titlebar-close","#"+$.jgrid.jqID(IDs.modalhead)).focus();},0); } } function createData(rowid,obj,tb,maxcols){ var nm, hc,trdata, cnt=0,tmp, dc, retpos=[], ind=false, tdtmpl = "  ", tmpl="", tdtmpl2 = "  ", fmtnum = ['integer','number','currency'],max1 =0, max2=0 ,maxw,setme, viewfld; for (var i =1;i<=maxcols;i++) { tmpl += i == 1 ? tdtmpl : tdtmpl2; } // find max number align rigth with property formatter $(obj.p.colModel).each( function() { if(this.editrules && this.editrules.edithidden === true) { hc = false; } else { hc = this.hidden === true ? true : false; } if(!hc && this.align==='right') { if(this.formatter && $.inArray(this.formatter,fmtnum) !== -1 ) { max1 = Math.max(max1,parseInt(this.width,10)); } else { max2 = Math.max(max2,parseInt(this.width,10)); } } }); maxw = max1 !==0 ? max1 : max2 !==0 ? max2 : 0; ind = $(obj).jqGrid("getInd",rowid); $(obj.p.colModel).each( function(i) { nm = this.name; setme = false; // 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'" : ""; viewfld = (typeof this.viewable != 'boolean') ? true : this.viewable; if ( nm !== 'cb' && nm !== 'subgrid' && nm !== 'rn' && viewfld) { if(ind === false) { tmp = ""; } else { if(nm == obj.p.ExpandColumn && obj.p.treeGrid === true) { tmp = $("td:eq("+i+")",obj.rows[ind]).text(); } else { tmp = $("td:eq("+i+")",obj.rows[ind]).html(); } } setme = this.align === 'right' && maxw !==0 ? true : false; var opt = $.extend({}, this.editoptions || {} ,{id:nm,name:nm}), frmopt = $.extend({},{rowabove:false,rowcontent:''}, this.formoptions || {}), rp = parseInt(frmopt.rowpos,10) || cnt+1, cp = parseInt((parseInt(frmopt.colpos,10) || 1)*2,10); if(frmopt.rowabove) { var newdata = $(""+frmopt.rowcontent+""); $(tb).append(newdata); newdata[0].rp = rp; } trdata = $(tb).find("tr[rowpos="+rp+"]"); if ( trdata.length===0 ) { trdata = $("").addClass("FormData").attr("id","trv_"+nm); $(trdata).append(tmpl); $(tb).append(trdata); trdata[0].rp = rp; } $("td:eq("+(cp-2)+")",trdata[0]).html(''+ (typeof frmopt.label === 'undefined' ? obj.p.colNames[i]: frmopt.label)+''); $("td:eq("+(cp-1)+")",trdata[0]).append(""+tmp+"").attr("id","v_"+nm); if(setme){ $("td:eq("+(cp-1)+") span",trdata[0]).css({'text-align':'right',width:maxw+"px"}); } retpos[cnt] = i; cnt++; } }); if( cnt > 0) { var idrow = $(""); idrow[0].rp = cnt+99; $(tb).append(idrow); } return retpos; } function fillData(rowid,obj){ var nm, hc,cnt=0,tmp, opt,trv; trv = $(obj).jqGrid("getInd",rowid,true); if(!trv) {return;} $('td',trv).each( function(i) { nm = obj.p.colModel[i].name; // hidden fields are included in the form if(obj.p.colModel[i].editrules && obj.p.colModel[i].editrules.edithidden === true) { hc = false; } else { hc = obj.p.colModel[i].hidden === true ? true : false; } if ( nm !== 'cb' && nm !== 'subgrid' && nm !== 'rn') { if(nm == obj.p.ExpandColumn && obj.p.treeGrid === true) { tmp = $(this).text(); } else { tmp = $(this).html(); } opt = $.extend({},obj.p.colModel[i].editoptions || {}); nm = $.jgrid.jqID("v_"+nm); $("#"+nm+" span","#"+frmtb).html(tmp); if (hc) {$("#"+nm,"#"+frmtb).parents("tr:first").hide();} cnt++; } }); if(cnt>0) {$("#id_g","#"+frmtb).val(rowid);} } function updateNav(cr,totr){ if (cr===0) {$("#pData","#"+frmtb+"_2").addClass('ui-state-disabled');} else {$("#pData","#"+frmtb+"_2").removeClass('ui-state-disabled');} if (cr==totr) {$("#nData","#"+frmtb+"_2").addClass('ui-state-disabled');} else {$("#nData","#"+frmtb+"_2").removeClass('ui-state-disabled');} } function getCurrPos() { var rowsInGrid = $($t).jqGrid("getDataIDs"), selrow = $("#id_g","#"+frmtb).val(), pos = $.inArray(selrow,rowsInGrid); return [pos,rowsInGrid]; } if ( $("#"+$.jgrid.jqID(IDs.themodal)).html() !== null ) { if(onBeforeInit) { showFrm = onBeforeInit($("#"+frmgr)); if(typeof(showFrm) == "undefined") { showFrm = true; } } if(showFrm === false) {return;} $(".ui-jqdialog-title","#"+$.jgrid.jqID(IDs.modalhead)).html(p.caption); $("#FormError","#"+frmtb).hide(); fillData(rowid,$t); if($.isFunction(p.beforeShowForm)) {p.beforeShowForm($("#"+frmgr));} $.jgrid.viewModal("#"+$.jgrid.jqID(IDs.themodal),{gbox:"#gbox_"+$.jgrid.jqID(gID),jqm:p.jqModal, jqM: false, overlay: p.overlay, modal:p.modal}); focusaref(); } else { var dh = isNaN(p.dataheight) ? p.dataheight : p.dataheight+"px"; var frm = $("
"), tbl =$("
"); if(onBeforeInit) { showFrm = onBeforeInit($("#"+frmgr)); if(typeof(showFrm) == "undefined") { showFrm = true; } } if(showFrm === false) {return;} $($t.p.colModel).each( function() { var fmto = this.formoptions; maxCols = Math.max(maxCols, fmto ? fmto.colpos || 0 : 0 ); maxRows = Math.max(maxRows, fmto ? fmto.rowpos || 0 : 0 ); }); // set the id. $(frm).append(tbl); createData(rowid, $t, tbl, maxCols); var rtlb = $t.p.direction == "rtl" ? true :false, bp = rtlb ? "nData" : "pData", bn = rtlb ? "pData" : "nData", // buttons at footer bP = "", bN = "", bC =""+p.bClose+""; if(maxRows > 0) { var sd=[]; $.each($(tbl)[0].rows,function(i,r){ sd[i] = r; }); sd.sort(function(a,b){ if(a.rp > b.rp) {return 1;} if(a.rp < b.rp) {return -1;} return 0; }); $.each(sd, function(index, row) { $('tbody',tbl).append(row); }); } p.gbox = "#gbox_"+$.jgrid.jqID(gID); var cle = false; if(p.closeOnEscape===true){ p.closeOnEscape = false; cle = true; } var bt = $("").append(frm).append("
"+bC+"
"); $.jgrid.createModal(IDs,bt,p,"#gview_"+$.jgrid.jqID($t.p.id),$("#gview_"+$.jgrid.jqID($t.p.id))[0]); if(rtlb) { $("#pData, #nData","#"+frmtb+"_2").css("float","right"); $(".EditButton","#"+frmtb+"_2").css("text-align","left"); } if(!p.viewPagerButtons) {$("#pData, #nData","#"+frmtb+"_2").hide();} bt = null; $("#"+IDs.themodal).keydown( function( e ) { if(e.which === 27) { if(cle) {$.jgrid.hideModal(this,{gb:p.gbox,jqm:p.jqModal, onClose: p.onClose});} return false; } if(p.navkeys[0]===true) { if(e.which === p.navkeys[1]){ //up $("#pData", "#"+frmtb+"_2").trigger("click"); return false; } if(e.which === p.navkeys[2]){ //down $("#nData", "#"+frmtb+"_2").trigger("click"); return false; } } }); p.closeicon = $.extend([true,"left","ui-icon-close"],p.closeicon); if(p.closeicon[0]===true) { $("#cData","#"+frmtb+"_2").addClass(p.closeicon[1] == "right" ? 'fm-button-icon-right' : 'fm-button-icon-left') .append(""); } if($.isFunction(p.beforeShowForm)) {p.beforeShowForm($("#"+frmgr));} $.jgrid.viewModal("#"+$.jgrid.jqID(IDs.themodal),{gbox:"#gbox_"+$.jgrid.jqID(gID),jqm:p.jqModal, modal:p.modal}); $(".fm-button:not(.ui-state-disabled)","#"+frmtb+"_2").hover( function(){$(this).addClass('ui-state-hover');}, function(){$(this).removeClass('ui-state-hover');} ); focusaref(); $("#cData", "#"+frmtb+"_2").click(function(){ $.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:"#gbox_"+$.jgrid.jqID(gID),jqm:p.jqModal, onClose: p.onClose}); return false; }); $("#nData", "#"+frmtb+"_2").click(function(){ $("#FormError","#"+frmtb).hide(); var npos = getCurrPos(); npos[0] = parseInt(npos[0],10); if(npos[0] != -1 && npos[1][npos[0]+1]) { if($.isFunction(p.onclickPgButtons)) { p.onclickPgButtons('next',$("#"+frmgr),npos[1][npos[0]]); } fillData(npos[1][npos[0]+1],$t); $($t).jqGrid("setSelection",npos[1][npos[0]+1]); if($.isFunction(p.afterclickPgButtons)) { p.afterclickPgButtons('next',$("#"+frmgr),npos[1][npos[0]+1]); } updateNav(npos[0]+1,npos[1].length-1); } focusaref(); return false; }); $("#pData", "#"+frmtb+"_2").click(function(){ $("#FormError","#"+frmtb).hide(); var ppos = getCurrPos(); if(ppos[0] != -1 && ppos[1][ppos[0]-1]) { if($.isFunction(p.onclickPgButtons)) { p.onclickPgButtons('prev',$("#"+frmgr),ppos[1][ppos[0]]); } fillData(ppos[1][ppos[0]-1],$t); $($t).jqGrid("setSelection",ppos[1][ppos[0]-1]); if($.isFunction(p.afterclickPgButtons)) { p.afterclickPgButtons('prev',$("#"+frmgr),ppos[1][ppos[0]-1]); } updateNav(ppos[0]-1,ppos[1].length-1); } focusaref(); return false; }); } var posInit =getCurrPos(); updateNav(posInit[0],posInit[1].length-1); }); }, delGridRow : function(rowids,p) { p = $.extend({ top : 0, left: 0, width: 240, height: 'auto', dataheight : 'auto', modal: false, overlay: 30, drag: true, resize: true, url : '', mtype : "POST", reloadAfterSubmit: true, beforeShowForm: null, beforeInitData : null, afterShowForm: null, beforeSubmit: null, onclickSubmit: null, afterSubmit: null, jqModal : true, closeOnEscape : false, delData: {}, delicon : [], cancelicon : [], onClose : null, ajaxDelOptions : {}, processing : false, serializeDelData : null, useDataProxy : false }, $.jgrid.del, p ||{}); rp_ge[$(this)[0].p.id] = p; return this.each(function(){ var $t = this; if (!$t.grid ) {return;} if(!rowids) {return;} var onBeforeShow = $.isFunction( rp_ge[$t.p.id].beforeShowForm ), onAfterShow = $.isFunction( rp_ge[$t.p.id].afterShowForm ), onBeforeInit = $.isFunction(rp_ge[$t.p.id].beforeInitData) ? rp_ge[$t.p.id].beforeInitData : false, gID = $t.p.id, onCS = {}, showFrm = true, dtbl = "DelTbl_"+$.jgrid.jqID(gID),postd, idname, opers, oper, dtbl_id = "DelTbl_" + gID, IDs = {themodal:'delmod'+gID,modalhead:'delhd'+gID,modalcontent:'delcnt'+gID, scrollelm: dtbl}; if (jQuery.isArray(rowids)) {rowids = rowids.join();} if ( $("#"+$.jgrid.jqID(IDs.themodal)).html() !== null ) { if(onBeforeInit) { showFrm = onBeforeInit( $("#"+dtbl)); if(typeof(showFrm) == "undefined") { showFrm = true; } } if(showFrm === false) {return;} $("#DelData>td","#"+dtbl).text(rowids); $("#DelError","#"+dtbl).hide(); if( rp_ge[$t.p.id].processing === true) { rp_ge[$t.p.id].processing=false; $("#dData", "#"+dtbl).removeClass('ui-state-active'); } if(onBeforeShow) {rp_ge[$t.p.id].beforeShowForm($("#"+dtbl));} $.jgrid.viewModal("#"+$.jgrid.jqID(IDs.themodal),{gbox:"#gbox_"+$.jgrid.jqID(gID),jqm:rp_ge[$t.p.id].jqModal,jqM: false, overlay: rp_ge[$t.p.id].overlay, modal:rp_ge[$t.p.id].modal}); if(onAfterShow) {rp_ge[$t.p.id].afterShowForm($("#"+dtbl));} } else { var dh = isNaN(rp_ge[$t.p.id].dataheight) ? rp_ge[$t.p.id].dataheight : rp_ge[$t.p.id].dataheight+"px"; var tbl = "
"; tbl += ""; // error data tbl += ""; tbl += ""; tbl += ""; // buttons at footer tbl += "
"+rp_ge[$t.p.id].msg+"
 
"; var bS = ""+p.bSubmit+"", bC = ""+p.bCancel+""; tbl += "

"+bS+" "+bC+"
"; p.gbox = "#gbox_"+$.jgrid.jqID(gID); $.jgrid.createModal(IDs,tbl,p,"#gview_"+$.jgrid.jqID($t.p.id),$("#gview_"+$.jgrid.jqID($t.p.id))[0]); if(onBeforeInit) { showFrm = onBeforeInit( $("#"+dtbl) ); if(typeof(showFrm) == "undefined") { showFrm = true; } } if(showFrm === false) {return;} $(".fm-button","#"+dtbl+"_2").hover( function(){$(this).addClass('ui-state-hover');}, function(){$(this).removeClass('ui-state-hover');} ); p.delicon = $.extend([true,"left","ui-icon-scissors"],rp_ge[$t.p.id].delicon); p.cancelicon = $.extend([true,"left","ui-icon-cancel"],rp_ge[$t.p.id].cancelicon); if(p.delicon[0]===true) { $("#dData","#"+dtbl+"_2").addClass(p.delicon[1] == "right" ? 'fm-button-icon-right' : 'fm-button-icon-left') .append(""); } if(p.cancelicon[0]===true) { $("#eData","#"+dtbl+"_2").addClass(p.cancelicon[1] == "right" ? 'fm-button-icon-right' : 'fm-button-icon-left') .append(""); } $("#dData","#"+dtbl+"_2").click(function(){ var ret=[true,""];onCS = {}; var postdata = $("#DelData>td","#"+dtbl).text(); //the pair is name=val1,val2,... if( $.isFunction( rp_ge[$t.p.id].onclickSubmit ) ) {onCS = rp_ge[$t.p.id].onclickSubmit(rp_ge[$t.p.id], postdata) || {};} if( $.isFunction( rp_ge[$t.p.id].beforeSubmit ) ) {ret = rp_ge[$t.p.id].beforeSubmit(postdata);} if(ret[0] && !rp_ge[$t.p.id].processing) { rp_ge[$t.p.id].processing = true; opers = $t.p.prmNames; postd = $.extend({},rp_ge[$t.p.id].delData, onCS); oper = opers.oper; postd[oper] = opers.deloper; idname = opers.id; postdata = String(postdata).split(","); if(!postdata.length) { return false; } for( var pk in postdata) { if(postdata.hasOwnProperty(pk)) { postdata[pk] = $.jgrid.stripPref($t.p.idPrefix, postdata[pk]); } } postd[idname] = postdata.join(); $(this).addClass('ui-state-active'); var ajaxOptions = $.extend({ url: rp_ge[$t.p.id].url ? rp_ge[$t.p.id].url : $($t).jqGrid('getGridParam','editurl'), type: rp_ge[$t.p.id].mtype, data: $.isFunction(rp_ge[$t.p.id].serializeDelData) ? rp_ge[$t.p.id].serializeDelData(postd) : postd, complete:function(data,Status){ if(Status != "success") { ret[0] = false; if ($.isFunction(rp_ge[$t.p.id].errorTextFormat)) { ret[1] = rp_ge[$t.p.id].errorTextFormat(data); } else { ret[1] = Status + " Status: '" + data.statusText + "'. Error code: " + data.status; } } else { // data is posted successful // execute aftersubmit with the returned data from server if( $.isFunction( rp_ge[$t.p.id].afterSubmit ) ) { ret = rp_ge[$t.p.id].afterSubmit(data,postd); } } if(ret[0] === false) { $("#DelError>td","#"+dtbl).html(ret[1]); $("#DelError","#"+dtbl).show(); } else { if(rp_ge[$t.p.id].reloadAfterSubmit && $t.p.datatype != "local") { $($t).trigger("reloadGrid"); } else { if($t.p.treeGrid===true){ try {$($t).jqGrid("delTreeNode",$t.p.idPrefix+postdata[0]);} catch(e){} } else { for(var i=0;itd","#"+dtbl).html(ret[1]); $("#DelError","#"+dtbl).show(); } return false; }); $("#eData", "#"+dtbl+"_2").click(function(){ $.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:"#gbox_"+$.jgrid.jqID(gID),jqm:rp_ge[$t.p.id].jqModal, onClose: rp_ge[$t.p.id].onClose}); return false; }); if(onBeforeShow) {rp_ge[$t.p.id].beforeShowForm($("#"+dtbl));} $.jgrid.viewModal("#"+$.jgrid.jqID(IDs.themodal),{gbox:"#gbox_"+$.jgrid.jqID(gID),jqm:rp_ge[$t.p.id].jqModal, overlay: rp_ge[$t.p.id].overlay, modal:rp_ge[$t.p.id].modal}); if(onAfterShow) {rp_ge[$t.p.id].afterShowForm($("#"+dtbl));} } if(rp_ge[$t.p.id].closeOnEscape===true) { setTimeout(function(){$(".ui-jqdialog-titlebar-close","#"+$.jgrid.jqID(IDs.modalhead)).focus();},0); } }); }, navGrid : function (elem, o, pEdit,pAdd,pDel,pSearch, pView) { o = $.extend({ edit: true, editicon: "ui-icon-pencil", add: true, addicon:"ui-icon-plus", del: true, delicon:"ui-icon-trash", search: true, searchicon:"ui-icon-search", refresh: true, refreshicon:"ui-icon-refresh", refreshstate: 'firstpage', view: false, viewicon : "ui-icon-document", position : "left", closeOnEscape : true, beforeRefresh : null, afterRefresh : null, cloneToTop : false, alertwidth : 200, alertheight : 'auto', alerttop: null, alertleft: null, alertzIndex : null }, $.jgrid.nav, o ||{}); return this.each(function() { if(this.nav) {return;} var alertIDs = {themodal:'alertmod',modalhead:'alerthd',modalcontent:'alertcnt'}, $t = this, twd, tdw; if(!$t.grid || typeof elem != 'string') {return;} if ($("#"+alertIDs.themodal).html() === null) { if(!o.alerttop && !o.alertleft) { if (typeof window.innerWidth != 'undefined') { o.alertleft = window.innerWidth; o.alerttop = window.innerHeight; } else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth !== 0) { o.alertleft = document.documentElement.clientWidth; o.alerttop = document.documentElement.clientHeight; } else { o.alertleft=1024; o.alerttop=768; } o.alertleft = o.alertleft/2 - parseInt(o.alertwidth,10)/2; o.alerttop = o.alerttop/2-25; } $.jgrid.createModal(alertIDs,"
"+o.alerttext+"
",{gbox:"#gbox_"+$.jgrid.jqID($t.p.id),jqModal:true,drag:true,resize:true,caption:o.alertcap,top:o.alerttop,left:o.alertleft,width:o.alertwidth,height: o.alertheight,closeOnEscape:o.closeOnEscape, zIndex: o.alertzIndex},"","",true); } var clone = 1; if(o.cloneToTop && $t.p.toppager) {clone = 2;} for(var i = 0; i"), sep = "", pgid, elemids; if(i===0) { pgid = elem; elemids = $t.p.id; if(pgid == $t.p.toppager) { elemids += "_top"; clone = 1; } } else { pgid = $t.p.toppager; elemids = $t.p.id+"_top"; } if($t.p.direction == "rtl") {$(navtbl).attr("dir","rtl").css("float","right");} if (o.add) { pAdd = pAdd || {}; tbd = $(""); $(tbd).append("
"+o.addtext+"
"); $("tr",navtbl).append(tbd); $(tbd,navtbl) .attr({"title":o.addtitle || "",id : pAdd.id || "add_"+elemids}) .click(function(){ if (!$(this).hasClass('ui-state-disabled')) { if ($.isFunction( o.addfunc )) { o.addfunc.call($t); } else { $($t).jqGrid("editGridRow","new",pAdd); } } return false; }).hover( function () { if (!$(this).hasClass('ui-state-disabled')) { $(this).addClass("ui-state-hover"); } }, function () {$(this).removeClass("ui-state-hover");} ); tbd = null; } if (o.edit) { tbd = $(""); pEdit = pEdit || {}; $(tbd).append("
"+o.edittext+"
"); $("tr",navtbl).append(tbd); $(tbd,navtbl) .attr({"title":o.edittitle || "",id: pEdit.id || "edit_"+elemids}) .click(function(){ if (!$(this).hasClass('ui-state-disabled')) { var sr = $t.p.selrow; if (sr) { if($.isFunction( o.editfunc ) ) { o.editfunc.call($t, sr); } else { $($t).jqGrid("editGridRow",sr,pEdit); } } else { $.jgrid.viewModal("#"+alertIDs.themodal,{gbox:"#gbox_"+$.jgrid.jqID($t.p.id),jqm:true}); $("#jqg_alrt").focus(); } } return false; }).hover( function () { if (!$(this).hasClass('ui-state-disabled')) { $(this).addClass("ui-state-hover"); } }, function () {$(this).removeClass("ui-state-hover");} ); tbd = null; } if (o.view) { tbd = $(""); pView = pView || {}; $(tbd).append("
"+o.viewtext+"
"); $("tr",navtbl).append(tbd); $(tbd,navtbl) .attr({"title":o.viewtitle || "",id: pView.id || "view_"+elemids}) .click(function(){ if (!$(this).hasClass('ui-state-disabled')) { var sr = $t.p.selrow; if (sr) { if($.isFunction( o.viewfunc ) ) { o.viewfunc.call($t, sr); } else { $($t).jqGrid("viewGridRow",sr,pView); } } else { $.jgrid.viewModal("#"+alertIDs.themodal,{gbox:"#gbox_"+$.jgrid.jqID($t.p.id),jqm:true}); $("#jqg_alrt").focus(); } } return false; }).hover( function () { if (!$(this).hasClass('ui-state-disabled')) { $(this).addClass("ui-state-hover"); } }, function () {$(this).removeClass("ui-state-hover");} ); tbd = null; } if (o.del) { tbd = $(""); pDel = pDel || {}; $(tbd).append("
"+o.deltext+"
"); $("tr",navtbl).append(tbd); $(tbd,navtbl) .attr({"title":o.deltitle || "",id: pDel.id || "del_"+elemids}) .click(function(){ if (!$(this).hasClass('ui-state-disabled')) { var dr; if($t.p.multiselect) { dr = $t.p.selarrrow; if(dr.length===0) {dr = null;} } else { dr = $t.p.selrow; } if(dr){ if($.isFunction( o.delfunc )){ o.delfunc.call($t, dr); }else{ $($t).jqGrid("delGridRow",dr,pDel); } } else { $.jgrid.viewModal("#"+alertIDs.themodal,{gbox:"#gbox_"+$.jgrid.jqID($t.p.id),jqm:true});$("#jqg_alrt").focus(); } } return false; }).hover( function () { if (!$(this).hasClass('ui-state-disabled')) { $(this).addClass("ui-state-hover"); } }, function () {$(this).removeClass("ui-state-hover");} ); tbd = null; } if(o.add || o.edit || o.del || o.view) {$("tr",navtbl).append(sep);} if (o.search) { tbd = $(""); pSearch = pSearch || {}; $(tbd).append("
"+o.searchtext+"
"); $("tr",navtbl).append(tbd); $(tbd,navtbl) .attr({"title":o.searchtitle || "",id:pSearch.id || "search_"+elemids}) .click(function(){ if (!$(this).hasClass('ui-state-disabled')) { if($.isFunction( o.searchfunc )) { o.searchfunc.call($t, pSearch); } else { $($t).jqGrid("searchGrid",pSearch); } } return false; }).hover( function () { if (!$(this).hasClass('ui-state-disabled')) { $(this).addClass("ui-state-hover"); } }, function () {$(this).removeClass("ui-state-hover");} ); if (pSearch.showOnLoad && pSearch.showOnLoad === true) { $(tbd,navtbl).click(); } tbd = null; } if (o.refresh) { tbd = $(""); $(tbd).append("
"+o.refreshtext+"
"); $("tr",navtbl).append(tbd); $(tbd,navtbl) .attr({"title":o.refreshtitle || "",id: "refresh_"+elemids}) .click(function(){ if (!$(this).hasClass('ui-state-disabled')) { if($.isFunction(o.beforeRefresh)) {o.beforeRefresh();} $t.p.search = false; try { var gID = $t.p.id; $t.p.postData.filters =""; $("#fbox_"+$.jgrid.jqID(gID)).jqFilter('resetFilter'); if($.isFunction($t.clearToolbar)) {$t.clearToolbar(false);} } catch (e) {} switch (o.refreshstate) { case 'firstpage': $($t).trigger("reloadGrid", [{page:1}]); break; case 'current': $($t).trigger("reloadGrid", [{current:true}]); break; } if($.isFunction(o.afterRefresh)) {o.afterRefresh();} } return false; }).hover( function () { if (!$(this).hasClass('ui-state-disabled')) { $(this).addClass("ui-state-hover"); } }, function () {$(this).removeClass("ui-state-hover");} ); tbd = null; } tdw = $(".ui-jqgrid").css("font-size") || "11px"; $('body').append(""); twd = $(navtbl).clone().appendTo("#testpg2").width(); $("#testpg2").remove(); $(pgid+"_"+o.position,pgid).append(navtbl); if($t.p._nvtd) { if(twd > $t.p._nvtd[0] ) { $(pgid+"_"+o.position,pgid).width(twd); $t.p._nvtd[0] = twd; } $t.p._nvtd[1] = twd; } tdw =null;twd=null;navtbl =null; this.nav = true; } }); }, navButtonAdd : function (elem, p) { p = $.extend({ caption : "newButton", title: '', buttonicon : 'ui-icon-newwin', onClickButton: null, position : "last", cursor : 'pointer' }, p ||{}); return this.each(function() { if( !this.grid) {return;} if( typeof elem === "string" && elem.indexOf("#") !== 0) {elem = "#"+$.jgrid.jqID(elem);} var findnav = $(".navtable",elem)[0], $t = this; if (findnav) { if( p.id && $("#"+$.jgrid.jqID(p.id), findnav).html() !== null ) {return;} var tbd = $(""); if(p.buttonicon.toString().toUpperCase() == "NONE") { $(tbd).addClass('ui-pg-button ui-corner-all').append("
"+p.caption+"
"); } else { $(tbd).addClass('ui-pg-button ui-corner-all').append("
"+p.caption+"
"); } if(p.id) {$(tbd).attr("id",p.id);} if(p.position=='first'){ if(findnav.rows[0].cells.length ===0 ) { $("tr",findnav).append(tbd); } else { $("tr td:eq(0)",findnav).before(tbd); } } else { $("tr",findnav).append(tbd); } $(tbd,findnav) .attr("title",p.title || "") .click(function(e){ if (!$(this).hasClass('ui-state-disabled')) { if ($.isFunction(p.onClickButton) ) {p.onClickButton.call($t,e);} } return false; }) .hover( function () { if (!$(this).hasClass('ui-state-disabled')) { $(this).addClass('ui-state-hover'); } }, function () {$(this).removeClass("ui-state-hover");} ); } }); }, navSeparatorAdd:function (elem,p) { p = $.extend({ sepclass : "ui-separator", sepcontent: '' }, p ||{}); return this.each(function() { if( !this.grid) {return;} if( typeof elem === "string" && elem.indexOf("#") !== 0) {elem = "#"+$.jgrid.jqID(elem);} var findnav = $(".navtable",elem)[0]; if(findnav) { var sep = ""+p.sepcontent+""; $("tr",findnav).append(sep); } }); }, GridToForm : function( rowid, formid ) { return this.each(function(){ var $t = this; if (!$t.grid) {return;} var rowdata = $($t).jqGrid("getRowData",rowid); if (rowdata) { for(var i in rowdata) { if ( $("[name="+$.jgrid.jqID(i)+"]",formid).is("input:radio") || $("[name="+$.jgrid.jqID(i)+"]",formid).is("input:checkbox")) { $("[name="+$.jgrid.jqID(i)+"]",formid).each( function() { if( $(this).val() == rowdata[i] ) { $(this)[$t.p.useProp ? 'prop': 'attr']("checked",true); } else { $(this)[$t.p.useProp ? 'prop': 'attr']("checked", false); } }); } else { // this is very slow on big table and form. $("[name="+$.jgrid.jqID(i)+"]",formid).val(rowdata[i]); } } } }); }, FormToGrid : function(rowid, formid, mode, position){ return this.each(function() { var $t = this; if(!$t.grid) {return;} if(!mode) {mode = 'set';} if(!position) {position = 'first';} var fields = $(formid).serializeArray(); var griddata = {}; $.each(fields, function(i, field){ griddata[field.name] = field.value; }); if(mode=='add') {$($t).jqGrid("addRowData",rowid,griddata, position);} else if(mode=='set') {$($t).jqGrid("setRowData",rowid,griddata);} }); } }); })(jQuery); // Grouping module ;(function($){ "use strict"; $.jgrid.extend({ groupingSetup : function () { return this.each(function (){ var $t = this, grp = $t.p.groupingView; if(grp !== null && ( (typeof grp === 'object') || $.isFunction(grp) ) ) { if(!grp.groupField.length) { $t.p.grouping = false; } else { if ( typeof(grp.visibiltyOnNextGrouping) == 'undefined') { grp.visibiltyOnNextGrouping = []; } for(var i=0;i"; try { gv = $t.formatter(hid, grp.sortnames[0][i], cp, grp.sortitems[0] ); } catch (egv) { gv = grp.sortnames[0][i]; } str += ""+icon+$.jgrid.format(grp.groupText[0], gv, grdata[n].length)+""; for(var kk=0;kk"; var fdata = grp.summaryval[0][n], cm = $t.p.colModel, vv, grlen = grdata[n].length; for(var k=0; k ", tplfld = "{0}"; $.each(fdata,function(){ if(this.nm == cm[k].name) { if(cm[k].summaryTpl) { tplfld = cm[k].summaryTpl; } if(this.st == 'avg') { if(this.v && grlen > 0) { this.v = (this.v/grlen); } } try { vv = $t.formatter('', this.v, k, this); } catch (ef) { vv = this.v; } tmpdata= ""+$.jgrid.format(tplfld,vv)+ ""; return false; } }); str += tmpdata; } str += ""; } }); $("#"+$.jgrid.jqID($t.p.id)+" tbody:first").append(str); // free up memory str = null; }); }, groupingGroupBy : function (name, options ) { return this.each(function(){ var $t = this; if(typeof(name) == "string") { name = [name]; } var grp = $t.p.groupingView; $t.p.grouping = true; //Set default, in case visibilityOnNextGrouping is undefined if (typeof grp.visibiltyOnNextGrouping == "undefined") { grp.visibiltyOnNextGrouping = []; } var i; // show previous hidden groups if they are hidden and weren't removed yet for(i=0;i