// ==ClosureCompiler== // @compilation_level SIMPLE_OPTIMIZATIONS /** * @license jqGrid 4.5.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: 2013-05-21 */ //jsHint options /*jshint evil:true, eqeqeq:false, eqnull:true, devel:true */ /*global jQuery */ (function ($) { "use strict"; $.jgrid = $.jgrid || {}; $.extend($.jgrid,{ version : "4.5.2", 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==null) { format = ""; } return format.replace(/\{(\d+)\}/g, function(m, i){ return args[i]; }); }, msie : navigator.appName === 'Microsoft Internet Explorer', msiever : function () { var rv = -1; var ua = navigator.userAgent; var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})"); if (re.exec(ua) != null) { rv = parseFloat( RegExp.$1 ); } return rv; }, 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 ($.jgrid.msie) { return $.inArray(c, c.parentNode.cells); } return c.cellIndex; }, stripHtml : function(v) { v = String(v); var regexp = /<("[^"]*"|'[^']*'|[^'">])*>/gi; if (v) { v = v.replace(regexp,""); return (v && v !== ' ' && v !== ' ') ? v.replace(/\"/g,"'") : ""; } 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; }, 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, newformat, opts) { var token = /\\.|[dDjlNSwzWFmMntLoYyaABgGhHisueIOPTZcrU]/g, timezone = /\b(?:[PMCEA][SDP]T|(?:Pacific|Mountain|Central|Eastern|Atlantic) (?:Standard|Daylight|Prevailing) Time|(?:GMT|UTC)(?:[-+]\d{4})?)\b/g, timezoneClip = /[^-+\dA-Z]/g, msDateRegExp = new RegExp("^\/Date\\((([-+])?[0-9]+)(([-+])([0-9]{2})([0-9]{2}))?\\)\/$"), msMatch = ((typeof date === 'string') ? date.match(msDateRegExp): null), pad = function (value, length) { value = String(value); length = parseInt(length,10) || 2; while (value.length < length) { value = '0' + value; } return value; }, ts = {m : 1, d : 1, y : 1970, h : 0, i : 0, s : 0, u:0}, timestamp=0, dM, k,hl, h12to24 = function(ampm, h){ if (ampm === 0){ if (h === 12) { h = 0;} } else { if (h !== 12) { h += 12; } } return h; }; if(opts === undefined) { opts = $.jgrid.formatter.date; } // old lang files if(opts.parseRe === undefined ) { opts.parseRe = /[Tt\\\/:_;.,\t\s-]/; } if( opts.masks.hasOwnProperty(format) ) { format = opts.masks[format]; } if(date && date != null) { if( !isNaN( date - 0 ) && String(format).toLowerCase() === "u") { //Unix timestamp timestamp = new Date( parseFloat(date)*1000 ); } else if(date.constructor === Date) { timestamp = date; // Microsoft date format support } else if( msMatch !== null ) { timestamp = new Date(parseInt(msMatch[1], 10)); if (msMatch[3]) { var offset = Number(msMatch[5]) * 60 + Number(msMatch[6]); offset *= ((msMatch[4] === '-') ? 1 : -1); offset -= timestamp.getTimezoneOffset(); timestamp.setTime(Number(Number(timestamp) + (offset * 60 * 1000))); } } else { date = String(date).replace(/\\T/g,"T").replace(/\\t/,"t").split(opts.parseRe); format = format.replace(/\\T/g,"T").replace(/\\t/,"t").split(opts.parseRe); // parsing for month names for(k=0,hl=format.length;k 11){date[k] = dM+1-12; ts.m = date[k];} } if(format[k] === 'a') { dM = $.inArray(date[k],opts.AmPm); if(dM !== -1 && dM < 2 && date[k] === opts.AmPm[dM]){ date[k] = dM; ts.h = h12to24(date[k], ts.h); } } if(format[k] === 'A') { dM = $.inArray(date[k],opts.AmPm); if(dM !== -1 && dM > 1 && date[k] === opts.AmPm[dM]){ date[k] = dM-2; ts.h = h12to24(date[k], ts.h); } } if (format[k] === 'g') { ts.h = parseInt(date[k], 10); } if(date[k] !== undefined) { ts[format[k].toLowerCase()] = parseInt(date[k],10); } } if(ts.f) {ts.m = ts.f;} if( ts.m === 0 && ts.y === 0 && ts.d === 0) { return " " ; } ts.m = parseInt(ts.m,10)-1; var ty = ts.y; if (ty >= 70 && ty <= 99) {ts.y = 1900+ts.y;} else if (ty >=0 && ty <=69) {ts.y= 2000+ts.y;} timestamp = new Date(ts.y, ts.m, ts.d, ts.h, ts.i, ts.s, ts.u); } } else { timestamp = new Date(ts.y, ts.m, ts.d, ts.h, ts.i, ts.s, ts.u); } if( newformat === undefined ) { return timestamp; } if( opts.masks.hasOwnProperty(newformat) ) { newformat = opts.masks[newformat]; } else if ( !newformat ) { newformat = 'Y-m-d'; } var G = timestamp.getHours(), i = timestamp.getMinutes(), j = timestamp.getDate(), n = timestamp.getMonth() + 1, o = timestamp.getTimezoneOffset(), s = timestamp.getSeconds(), u = timestamp.getMilliseconds(), w = timestamp.getDay(), Y = timestamp.getFullYear(), N = (w + 6) % 7 + 1, z = (new Date(Y, n - 1, j) - new Date(Y, 0, 1)) / 86400000, flags = { // Day d: pad(j), D: opts.dayNames[w], j: j, l: opts.dayNames[w + 7], N: N, S: opts.S(j), //j < 11 || j > 13 ? ['st', 'nd', 'rd', 'th'][Math.min((j - 1) % 10, 3)] : 'th', w: w, z: z, // Week W: N < 5 ? Math.floor((z + N - 1) / 7) + 1 : Math.floor((z + N - 1) / 7) || ((new Date(Y - 1, 0, 1).getDay() + 6) % 7 < 4 ? 53 : 52), // Month F: opts.monthNames[n - 1 + 12], m: pad(n), M: opts.monthNames[n - 1], n: n, t: '?', // Year L: '?', o: '?', Y: Y, y: String(Y).substring(2), // Time a: G < 12 ? opts.AmPm[0] : opts.AmPm[1], A: G < 12 ? opts.AmPm[2] : opts.AmPm[3], B: '?', g: G % 12 || 12, G: G, h: pad(G % 12 || 12), H: pad(G), i: pad(i), s: pad(s), u: u, // Timezone e: '?', I: '?', O: (o > 0 ? "-" : "+") + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4), P: '?', T: (String(timestamp).match(timezone) || [""]).pop().replace(timezoneClip, ""), Z: '?', // Full Date/Time c: '?', r: '?', U: Math.floor(timestamp / 1000) }; return newformat.replace(token, function ($0) { return flags.hasOwnProperty($0) ? flags[$0] : $0.substring(1); }); }, jqID : function(sid){ return String(sid).replace(/[!"#$%&'()*+,.\/:; <=>?@\[\\\]\^`{|}~]/g,"\\$&"); }, guid : 1, uidPref: 'jqg', randId : function( prefix ) { return (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]); } 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; }, cellWidth : function () { var $testDiv = $("
"), testCell = $testDiv.appendTo("body") .find("td") .width(); $testDiv.remove(); return testCell !== 5; }, cell_width : true, 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()"; } return""; }; this._group=function(f,u){ return({field:f.toString(),unique:u,items:[]}); }; this._toStr=function(phrase){ if(_trim){ phrase=$.trim(phrase); } phrase=phrase.toString().replace(/\\/g,'\\\\').replace(/\"/g,'\\"'); return _usecase ? phrase : phrase.toLowerCase(); }; 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); b=String(b); } 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), results=[], i, j, sorted; for(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==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==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 == null ? "a" :$.trim(dir.toString().toLowerCase()); if(stype == null) { stype = "text"; } if(dfmt == null) { 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); }, getMethod: function (name) { return this.getAccessor($.fn.jqGrid, name); }, 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 = $.jgrid.getMethod(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, onInitGrid : 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:[], summary:[],summaryval:[], plusicon: 'ui-icon-circlesmall-plus', minusicon: 'ui-icon-circlesmall-minus', displayField: []}, ignoreCase : false, cmTemplate : {}, idPrefix : "", multiSort : false }, $.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(ts,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(ts,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.call(table[0], 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"), isMSIE = $.jgrid.msie; 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).removeClass("scroll").appendTo(gv); var eg = $("
"); $(eg).attr({"id" : "gbox_"+this.id,"dir":dir}).insertBefore(gv); $(gv).attr("id","gview_"+this.id).appendTo(eg); $("
").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 || 0;} 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 == null || val === "" ? " " : (ts.p.autoencode ? $.jgrid.htmlEncode(val) : String(val)); }, formatter = function (rowId, cellval , colpos, rwdat, _act){ var cm = ts.p.colModel[colpos],v; if(cm.formatter !== undefined) { rowId = String(ts.p.idPrefix) !== "" ? $.jgrid.stripPref(ts.p.idPrefix, rowId) : rowId; 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, rdata) { var v,prp; v = formatter(rowId,cell,pos,srvr,'add'); prp = formatCol( pos,irow, v, srvr, rowId, rdata); return ""+v+""; }, addMulti = function(rowid,pos,irow,checked){ 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; i 0 ? this.rows[0] : null; $(this.firstChild).empty().append(firstrow); } if (scroll && this.p.scroll) { $(this.grid.bDiv.firstChild).css({height: "auto"}); $(this.grid.bDiv.firstChild.firstChild).css({height: 0, display: "none"}); if (this.grid.bDiv.scrollTop !== 0) { this.grid.bDiv.scrollTop = 0; } } if(locdata === true && this.p.treeGrid) { this.p.data = []; this.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); if (val === undefined) { val=String(i+1); } ts.p._index[val] = i; } }, constructTr = function(id, hide, altClass, rd, cur, selected) { var tabindex = '-1', restAttr = '', attrName, style = hide ? 'display:none;' : '', classes = 'ui-widget-content jqgrow ui-row-' + ts.p.direction + (altClass ? ' ' + altClass : '') + (selected ? ' ui-state-highlight' : ''), rowAttrObj = $(ts).triggerHandler("jqGridRowAttr", [rd, cur, id]); if( typeof rowAttrObj !== "object" ) { rowAttrObj = $.isFunction(ts.p.rowattr) ? ts.p.rowattr.call(ts, rd, cur, id) :{}; } 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.call(ts, false, true); rcnt=1; } else { rcnt = rcnt > 1 ? rcnt :1; } } else { return; } var self= $(ts), i,fpos,ir=0,v,gi=ts.p.multiselect===true?1:0,si=0,addSubGridCell,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(ts.p.subGrid===true) { si = 1; addSubGridCell = $.jgrid.getMethod("addSubGridCell"); } 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( String(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 ) || ts.p.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), br=ts.p.scroll?$.jgrid.randId():1, altr; if (gl > 0 && ts.p.page <= 0) { ts.p.page = 1; } if(gxml && gl){ if (adjust) { rn *= adjust+1; } var afterInsRow = $.isFunction(ts.p.afterInsertRow), hiderow=false, groupingPrepare; if(ts.p.grouping) { hiderow = ts.p.groupingView.groupCollapse === true; groupingPrepare = $.jgrid.getMethod("groupingPrepare"); } while (j"); if(ts.p.grouping) { grpdata = groupingPrepare.call(self,rowData, grpdata, rd, j); rowData = []; } if(locdata || ts.p.treeGrid === true) { rd[xmlid] = $.jgrid.stripPref(ts.p.idPrefix, rid); ts.p.data.push(rd); ts.p._index[rd[xmlid]] = ts.p.data.length-1; } if(ts.p.gridview === false ) { $("tbody:first",t).append(rowData.join('')); self.triggerHandler("jqGridAfterInsertRow", [rid, rd, xmlr]); if(afterInsRow) {ts.p.afterInsertRow.call(ts,rid,rd,xmlr);} rowData=[]; } rd={}; ir++; j++; if(ir===rn) {break;} } } if(ts.p.gridview === true) { fpos = ts.p.treeANode > -1 ? ts.p.treeANode: 0; if(ts.p.grouping) { self.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 {self.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 {self.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) { self.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 self = $(ts), ir=0,v,i,j,f=[],cur,gi=ts.p.multiselect?1:0,si=ts.p.subGrid===true?1:0,addSubGridCell,ni=ts.p.rownumbers===true?1:0,arrayReader=orderedCols(gi+si+ni),objectReader=reader(frd),rowReader,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) || ts.p.page || 0; lp = $.jgrid.getAccessor(data,dReader.total); if(si) { addSubGridCell = $.jgrid.getMethod("addSubGridCell"); } 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( ts.p.keyIndex===false ) { idn = $.isFunction(dReader.id) ? dReader.id.call(ts, data) : dReader.id; } else { idn = ts.p.keyIndex; } if(!dReader.repeatitems) { f = objectReader; 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 == null && $.isArray(data)) { drows = data; } 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, selected=false, selr; if (adjust) { rn *= adjust+1; } if(ts.p.datatype === "local" && !ts.p.deselectAfterSort) { selected = true; } var afterInsRow = $.isFunction(ts.p.afterInsertRow), grpdata=[],hiderow=false, groupingPrepare; if(ts.p.grouping) { hiderow = ts.p.groupingView.groupCollapse === true; groupingPrepare = $.jgrid.getMethod("groupingPrepare"); } while (i" ); if(ts.p.grouping) { grpdata = groupingPrepare.call(self,rowData, grpdata, rd, i); rowData = []; } if(locdata || ts.p.treeGrid===true) { rd[locid] = $.jgrid.stripPref(ts.p.idPrefix, idr); ts.p.data.push(rd); ts.p._index[rd[locid]] = ts.p.data.length-1; } if(ts.p.gridview === false ) { $("#"+$.jgrid.jqID(ts.p.id)+" tbody:first").append(rowData.join('')); self.triggerHandler("jqGridAfterInsertRow", [idr, rd, cur]); if(afterInsRow) {ts.p.afterInsertRow.call(ts,idr,rd,cur);} rowData=[];//ari=0; } rd={}; ir++; i++; if(ir===rn) { break; } } if(ts.p.gridview === true ) { fpos = ts.p.treeANode > -1 ? ts.p.treeANode: 0; if(ts.p.grouping) { self.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 { self.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 {self.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) { self.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 != null) { //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) { for(gin=0; gin 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"}); if (ts.grid.bDiv.scrollTop == 0 && ts.p.page > 1) { ts.grid.bDiv.scrollTop = ts.p.rowNum * (ts.p.page - 1) * rh; } } ts.grid.bDiv.scrollLeft = ts.grid.hDiv.scrollLeft; } pgboxes = 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'); var grp = ts.p.groupingView, gi, gs=""; for(gi=0;gi1,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; } beginReq(); } },$.jgrid.ajaxOptions, ts.p.ajaxGridOptions)); break; case "xmlstring": beginReq(); dstr = typeof ts.p.datastr !== 'string' ? ts.p.datastr : $.parseXML(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() { if(!clearVals('records')) { return false; } 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); } 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(!clearVals(this.id)) { return false; } 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) { populate(); } return false; }); } if(ts.p.pginput===true) { $('input.ui-pg-input',"#"+pgcnt).keypress( function(e) { var key = e.charCode || e.keyCode || 0; if(key === 13) { if(!clearVals('user')) { return false; } $(this).val( intNum( $(this).val(), 1)); ts.p.page = ($(this).val()>0) ? $(this).val():ts.p.page; populate(); return false; } return this; }); } }, multiSort = function(iCol, obj ) { var splas, sort="", cm = ts.p.colModel, fs=false, ls, selTh = ts.p.frozenColumns ? obj : ts.grid.headers[iCol].el, so=""; $("span.ui-grid-ico-sort",selTh).addClass('ui-state-disabled'); $(selTh).attr("aria-selected","false"); if(cm[iCol].lso) { if(cm[iCol].lso==="asc") { cm[iCol].lso += "-desc"; so = "desc"; } else if(cm[iCol].lso==="desc") { cm[iCol].lso += "-asc"; so = "asc"; } else if(cm[iCol].lso==="asc-desc" || cm[iCol].lso==="desc-asc") { cm[iCol].lso=""; } } else { cm[iCol].lso = so = cm.firstsortorder || 'asc'; } if( so ) { $("span.s-ico",selTh).show(); $("span.ui-icon-"+so,selTh).removeClass('ui-state-disabled'); $(selTh).attr("aria-selected","true"); } else { if(!ts.p.viewsortcols[0]) { $("span.s-ico",selTh).hide(); } } ts.p.sortorder = ""; $.each(cm, function(i){ if(this.lso) { if(i>0 && fs) { sort += ", "; } splas = this.lso.split("-"); sort += cm[i].index || cm[i].name; sort += " "+splas[splas.length-1]; fs = true; ts.p.sortorder = splas[splas.length-1]; } }); ls = sort.lastIndexOf(ts.p.sortorder); sort = sort.substring(0, ls); ts.p.sortname = sort; }, sortData = function (index, idxcol,reload,sor, obj){ 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(ts.p.multiSort) { multiSort( idxcol, obj); } else { if(sor) { if(ts.p.lastsort === idxcol && ts.p.sortorder === sor && !reload) { return; } ts.p.sortorder = sor; } var previousSelectedTh = ts.grid.headers[ts.p.lastsort].el, newSelectedTh = ts.p.frozenColumns ? obj : ts.grid.headers[idxcol].el; $("span.ui-grid-ico-sort",previousSelectedTh).addClass('ui-state-disabled'); $(previousSelectedTh).attr("aria-selected","false"); if(ts.p.frozenColumns) { ts.grid.fhDiv.find("span.ui-grid-ico-sort").addClass('ui-state-disabled'); ts.grid.fhDiv.find("th").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) { if(ts.p.frozenColumns){ ts.grid.fhDiv.find("span.s-ico").hide(); } $("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.call(ts, 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=$.jgrid.cell_width? 0: intNum(ts.p.cellLayout,0), vc=0, lvc, scw=intNum(ts.p.scrollOffset,0),cw,hs=false,aw,gw=0,cr; $.each(ts.p.colModel, function() { if(this.hidden === undefined) {this.hidden=false;} if(ts.p.grouping && ts.p.autowidth) { var ind = $.inArray(this.name, ts.p.groupingView.groupField); if(ind >= 0 && ts.p.groupingView.groupColumnShow.length > ind) { this.hidden = !ts.p.groupingView.groupColumnShow[ind]; } } this.widthOrg = cw = intNum(this.width,0); if(this.hidden===false){ initwidth += cw+brd; if(this.fixed) { gw += cw+brd; } else { vc++; } } }); if(isNaN(ts.p.width)) { ts.p.width = initwidth + ((ts.p.shrinkToFit ===false && !isNaN(ts.p.height)) ? scw : 0); } 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:$.jgrid.cell_width ? 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="",sortarr=[], sortord=[], sotmp=[]; 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 = ""; if(ts.p.multiSort) { sortarr = ts.p.sortname.split(","); 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; } ts.p.colModel[i].lso = ""; if (idn === ts.p.sortname) { ts.p.lastsort = i; } if(ts.p.multiSort) { sotmp = $.inArray(idn,sortarr); if( sotmp !== -1 ) { ts.p.colModel[i].lso = sortord[sotmp]; } } 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(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) .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.multiSort) { if(ts.p.viewsortcols[0]) { $("div span.s-ico",this).show(); if(ts.p.colModel[j].lso){ $("div span.ui-icon-"+ts.p.colModel[j].lso,this).removeClass("ui-state-disabled"); } } else if( ts.p.colModel[j].lso) { $("div span.s-ico",this).show(); $("div span.ui-icon-"+ts.p.colModel[j].lso,this).removeClass("ui-state-disabled"); } } else { 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; if(ts.p.frozenColumns) { var tid = $(this)[0].id.substring(5); $(ts.p.colModel).each(function(i){ if (this.name === tid) { ci = i;return false; } }); } else { ci = getColumnHeaderIndex(this); } if (!ts.p.viewsortcols[2]) { r=true;d=t.attr("sort"); } if(ci != null){ sortData( $('div',this)[0].id, ci, r, d, this); } 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"}).addClass('ui-state-default ui-jqgrid-pager ui-corner-bottom').appendTo(eg); 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.call(ts, 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(); } if(ts.p._inlinenav===true) {$(ts).jqGrid('showAddEditButtons');} 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(ts.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(ts.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( !$.support.tbody ) { //IE if( $("tbody",this).length === 2 ) { $("tbody:gt(0)",this).remove();} } if(ts.p.multikey){ if( $.jgrid.msie) { $(grid.bDiv).bind("selectstart",function(){return false;}); } else { $(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).addClass("ui-userdata ui-state-default").attr("id","t_"+this.id).insertBefore(grid.hDiv); $(grid.ubDiv).addClass("ui-userdata ui-state-default").attr("id","tb_"+this.id).insertAfter(grid.hDiv); 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).addClass('ui-state-default ui-jqgrid-toppager').width(grid.width).insertBefore(grid.hDiv); setPager(ts.p.toppager,'_t'); } if(ts.p.footerrow) { grid.sDiv = $("
")[0]; hb = $("
"); $(grid.sDiv).append(hb).width(grid.width).insertAfter(grid.hDiv); $(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.constructTr = constructTr; 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; $(ts).triggerHandler("jqGridInitGrid"); if ($.isFunction( ts.p.onInitGrid )) { ts.p.onInitGrid.call(ts); } populate();ts.p.hiddengrid=false; }); }; $.jgrid.extend({ getGridParam : function(pName) { var $t = this[0]; if (!$t || !$t.grid) {return;} if (!pName) { return $t.p; } return $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]).position().top, 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; if( onsr ) { $($t).triggerHandler("jqGridSelectRow", [pt.id, stat, e]); if( $t.p.onSelectRow) { $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); } if( onsr ) { $($t).triggerHandler("jqGridSelectRow", [pt.id, stat, e]); if( $t.p.onSelectRow) { $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(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(rowid === undefined) { getall = true; resall = []; len = $t.rows.length; } else { ind = $t.rows.namedItem(rowid); if(!ind) { return res; } len = 2; } while(j 0) { $t.p.selrow = $t.p.selarrrow[$t.p.selarrrow.length-1]; } else { $t.p.selrow = null; } if($t.p.datatype === 'local') { var id = $.jgrid.stripPref($t.p.idPrefix, rowid), pos = $t.p._index[id]; if(pos !== undefined) { $t.p.data.splice(pos,1); $t.refreshIndex(); } } if( $t.p.altRows === true && success ) { var cn = $t.p.altclass; $($t.rows).each(function(i){ if(i % 2 === 1) { $(this).addClass(cn); } else { $(this).removeClass(cn); } }); } }); return success; }, setRowData : function(rowid, data, cssp) { var nm, success=true, title; this.each(function(){ if(!this.grid) {return false;} var t = this, vl, ind, cp = typeof cssp, lcdata={}; ind = t.rows.namedItem(rowid); if(!ind) { return false; } if( data ) { try { $(this.p.colModel).each(function(i){ nm = this.name; var dval =$.jgrid.getAccessor(data,nm); if( dval !== undefined) { lcdata[nm] = this.formatter && typeof this.formatter === 'string' && this.formatter === 'date' ? $.unformat.date.call(t,dval,this) : dval; vl = t.formatter( rowid, dval, i, data, 'edit'); title = this.title ? {"title":$.jgrid.stripHtml(vl)} : {}; if(t.p.treeGrid===true && nm === t.p.ExpandColumn) { $("td[role='gridcell']:eq("+i+") > span:first",ind).html(vl).attr(title); } else { $("td[role='gridcell']: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], key; if(t.p.treeGrid) { for(key in t.p.treeReader){ if(t.p.treeReader.hasOwnProperty(key)) { delete lcdata[t.p.treeReader[key]]; } } } if(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(rowid !== undefined) { rowid = String(rowid);} else { rowid = $.jgrid.randId(); if(t.p.keyIndex !== false) { cnm = t.p.colModel[t.p.keyIndex+gi+si+ni].name; if(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]; if(rowid===undefined) { rowid = $.jgrid.randId(); } } 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[row.length] = "0"; } if(gi) { v = ""; prp = t.formatCol(ni,1,'', null, rowid, true); row[row.length] = ""+v+""; } if(si) { row[row.length] = $(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] = data[nm]; v = t.formatter( rowid, $.jgrid.getAccessor(data,nm), i, data ); prp = t.formatCol(i,1,v, data, rowid, lcdata); row[row.length] = ""+v+""; } row.unshift( t.constructTr(rowid, false, cna, lcdata, data, false ) ); row[row.length] = ""; if(t.rows.length === 0){ $("table:first",t.grid.bDiv).append(row.join('')); } else { switch (pos) { case 'last': $(t.rows[t.rows.length-1]).after(row.join('')); sind = t.rows.length-1; break; case 'first': $(t.rows[0]).after(row.join('')); 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.join('')); } } sind++; break; case 'before': sind = t.rows.namedItem(src); if(sind) {$(sind).before(row.join(''));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) { var i; for(i in obj) { if (obj.hasOwnProperty(i)) { return false; } } return true; } if(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=$.jgrid.cell_width ? 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 = 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) { if($t.p.shrinkToFit === true && !isNaN($t.p.height)) { $t.p.tblwidth += parseInt($t.p.scrollOffset,10);} $($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=$.jgrid.cell_width ? 0: $t.p.cellLayout, lvc, vc=0, hs=false, scw=$t.p.scrollOffset, aw, gw=0, cr; if(typeof shrink !== 'boolean') { shrink=$t.p.shrinkToFit; } if(isNaN(nwidth)) {return;} 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; initwidth += cw+brd; if(this.fixed) { gw += cw+brd; } else { vc++; } } }); 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; 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(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[$.jgrid.stripPref($t.p.idPrefix, rowid)]; if(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(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); /*jshint eqeqeq:false */ /*global 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 **/ "use strict"; $.jgrid.extend({ getColProp : function(colname){ var ret ={}, $t = this[0]; if ( !$t.grid ) { return false; } var cM = $t.p.colModel, i; for ( i=0;i","ge":">=","bw":"^","bn":"!^","in":"=","ni":"!=","ew":"|","en":"!@","cn":"~","nc":"!~","nu":"#","nn":"!#"} }, $.jgrid.search , p || {}); return this.each(function(){ var $t = this; if(this.ftoolbar) { return; } var triggerToolbar = function() { var sdata={}, j=0, v, nm, sopt={},so; $.each($t.p.colModel,function(){ var $elem = $("#gs_"+$.jgrid.jqID(this.name), (this.frozen===true && $t.p.frozenColumns === true) ? $t.grid.fhDiv : $t.grid.hDiv); nm = this.index || this.name; if(p.searchOperators ) { so = $elem.parent().prev().children("a").attr("soper") || p.defaultSearch; } else { so = (this.searchoptions && this.searchoptions.sopt) ? this.searchoptions.sopt[0] : this.stype==='select'? 'eq' : p.defaultSearch; } v = this.stype === "custom" && $.isFunction(this.searchoptions.custom_value) && $elem.length > 0 && $elem[0].nodeName.toUpperCase() === "SPAN" ? this.searchoptions.custom_value.call($t, $elem.children(".customelement:first"), "get") : $elem.val(); if(v || so==="nu" || so==="nn") { sdata[nm] = v; sopt[nm] = so; j++; } else { try { delete $t.p.postData[nm]; } catch (z) {} } }); 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\":\"" + 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.call($t);} }, clearToolbar = function(trigger){ var sdata={}, j=0, nm; trigger = (typeof trigger !== 'boolean') ? true : trigger; $.each($t.p.colModel,function(){ var v, $elem = $("#gs_"+$.jgrid.jqID(this.name),(this.frozen===true && $t.p.frozenColumns === true) ? $t.grid.fhDiv : $t.grid.hDiv); if(this.searchoptions && this.searchoptions.defaultValue !== undefined) { v = this.searchoptions.defaultValue; } nm = this.index || this.name; switch (this.stype) { case 'select' : $elem.find("option").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': $elem.val(v); if(v !== undefined) { sdata[nm] = v; j++; } else { try { delete $t.p.postData[nm]; } catch (y){} } break; case 'custom': if ($.isFunction(this.searchoptions.custom_value) && $elem.length > 0 && $elem[0].nodeName.toUpperCase() === "SPAN") { this.searchoptions.custom_value.call($t, $elem.children(".customelement:first"), "set", v); } 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();} }, 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(); } } }, buildRuleMenu = function( elem, left, top ){ $("#sopt_menu").remove(); left=parseInt(left,10); top=parseInt(top,10) + 18; var fs = $('.ui-jqgrid-view').css('font-size') || '11px'; var str = '
"; $('body').append(str); $("#sopt_menu").addClass("ui-menu ui-widget ui-widget-content ui-corner-all"); $("#sopt_menu > li > a").hover( function(){ $(this).addClass("ui-state-hover"); }, function(){ $(this).removeClass("ui-state-hover"); } ).click(function( e ){ var v = $(this).attr("value"), oper = $(this).attr("oper"); $($t).triggerHandler("jqGridToolbarSelectOper", [v, oper, elem]); $("#sopt_menu").hide(); $(elem).text(oper).attr("soper",v); if(p.autosearch===true){ var inpelm = $(elem).parent().next().children()[0]; if( $(inpelm).val() || v==="nu" || v ==="nn") { triggerToolbar(); } } }); }; // create the row var tr = $(""); var timeoutHnd; $.each($t.p.colModel,function(){ var cm=this, soptions, surl, self, select = "", sot="=", so, i, th = $(""), thd = $("
"), stbl = $("
"); if(this.hidden===true) { $(th).css("display","none");} this.search = this.search === false ? false : true; if(this.stype === undefined) {this.stype='text';} soptions = $.extend({},this.searchoptions || {}); if(this.search){ if(p.searchOperators) { so = (soptions.sopt) ? soptions.sopt[0] : cm.stype==='select' ? 'eq' : p.defaultSearch; for(i = 0;i"+sot+""; } $("td:eq(0)",stbl).append(select); 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) { $("td:eq(1)",stbl).append(d); $(self).append(stbl); } } else { $("td:eq(1)",stbl).append(res); $(self).append(stbl); } 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 $.jgrid.bindEv.call($t, $("select",self)[0], soptions); 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 sv, ov, key, k; if(typeof oSv === "string") { so = oSv.split(delim); for(k=0; k"); $(thd).append(stbl); if(soptions.attr) {$("input",thd).attr(soptions.attr);} $.jgrid.bindEv.call($t, $("input",thd)[0], soptions); if(p.autosearch===true){ if(p.searchOnEnter) { $("input",thd).keypress(function(e){ var key = e.charCode || 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; case "custom": $("td:eq(1)",stbl).append(""); $(thd).append(stbl); try { if($.isFunction(soptions.custom_element)) { var celm = soptions.custom_element.call($t,soptions.defaultValue !== undefined ? soptions.defaultValue: "",soptions); if(celm) { celm = $(celm).addClass("customelement"); $(thd).find(">span").append(celm); } else { throw "e2"; } } else { throw "e1"; } } catch (e) { if (e === "e1") { $.jgrid.info_dialog($.jgrid.errors.errcap,"function 'custom_element' "+$.jgrid.edit.msg.nodefined,$.jgrid.edit.bClose);} if (e === "e2") { $.jgrid.info_dialog($.jgrid.errors.errcap,"function 'custom_element' "+$.jgrid.edit.msg.novalue,$.jgrid.edit.bClose);} else { $.jgrid.info_dialog($.jgrid.errors.errcap,typeof e==="string"?e:e.message,$.jgrid.edit.bClose); } } break; } } $(th).append(thd); $(tr).append(th); if(!p.searchOperators) { $("td:eq(0)",stbl).hide(); } }); $("table thead",$t.grid.hDiv).append(tr); if(p.searchOperators) { $(".soptclass").click(function(e){ var offset = $(this).offset(), left = ( offset.left ), top = ( offset.top); buildRuleMenu(this, left, top ); e.stopPropagation(); }); $("body").on('click', function(e){ if(e.target.className !== "soptclass") { $("#sopt_menu").hide(); } }); } this.ftoolbar = true; this.triggerToolbar = triggerToolbar; this.clearToolbar = clearToolbar; this.toggleToolbar = toggleToolbar; }); }, destroyFilterToolbar: function () { return this.each(function () { if (!this.ftoolbar) { return; } this.triggerToolbar = null; this.clearToolbar = null; this.toggleToolbar = null; this.ftoolbar = false; $(this.grid.hDiv).find("table thead tr.ui-search-toolbar").remove(); }); }, destroyGroupHeader : function(nullHeader) { if(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[0] === undefined) { $firstHeaderRow = $('', {role: "row", "aria-hidden": "true"}).addClass("jqg-first-row-header").css("height", "auto"); } else { $firstHeaderRow.empty(); } var $firstRow, inColumnHeader = function (text, columnHeaders) { var length = columnHeaders.length, i; for (i = 0; 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, cs, rs; $("tr.jqg-second-row-header th", htbl).each(function(){ cs= parseInt($(this).attr("colspan"),10); rs= parseInt($(this).attr("rowspan"),10); if(rs) { swapfroz++; fdel++; } 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 (e, 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); $($t.grid.bDiv).scroll(function () { $($t.grid.fbDiv).scrollTop($(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(); $($t.grid.fbDiv).height($($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); /* * jqModal - Minimalist Modaling with jQuery * (http://dev.iceburg.net/jquery/jqmodal/) * * Copyright (c) 2007,2008 Brice Burgess * Dual licensed under the MIT and GPL licenses: * http://www.opensource.org/licenses/mit-license.php * http://www.gnu.org/licenses/gpl.html * * $Version: 07/06/2008 +r13 */ (function($) { $.fn.jqm=function(o){ var p={ overlay: 50, closeoverlay : true, overlayClass: 'jqmOverlay', closeClass: 'jqmClose', trigger: '.jqModal', ajax: F, ajaxText: '', target: F, modal: F, toTop: F, onShow: F, onHide: F, onLoad: F }; return this.each(function(){if(this._jqm)return H[this._jqm].c=$.extend({},H[this._jqm].c,o);s++;this._jqm=s; H[s]={c:$.extend(p,$.jqm.params,o),a:F,w:$(this).addClass('jqmID'+s),s:s}; if(p.trigger)$(this).jqmAddTrigger(p.trigger); });}; $.fn.jqmAddClose=function(e){return hs(this,e,'jqmHide');}; $.fn.jqmAddTrigger=function(e){return hs(this,e,'jqmShow');}; $.fn.jqmShow=function(t){return this.each(function(){$.jqm.open(this._jqm,t);});}; $.fn.jqmHide=function(t){return this.each(function(){$.jqm.close(this._jqm,t)});}; $.jqm = { hash:{}, open:function(s,t){var h=H[s],c=h.c,cc='.'+c.closeClass,z=(parseInt(h.w.css('z-index')));z=(z>0)?z:3000;var o=$('
').css({height:'100%',width:'100%',position:'fixed',left:0,top:0,'z-index':z-1,opacity:c.overlay/100});if(h.a)return F;h.t=t;h.a=true;h.w.css('z-index',z); if(c.modal) {if(!A[0])setTimeout(function(){L('bind');},1);A.push(s);} else if(c.overlay > 0) {if(c.closeoverlay) h.w.jqmAddClose(o);} else o=F; h.o=(o)?o.addClass(c.overlayClass).prependTo('body'):F; if(c.ajax) {var r=c.target||h.w,u=c.ajax;r=(typeof r == 'string')?$(r,h.w):$(r);u=(u.substr(0,1) == '@')?$(t).attr(u.substring(1)):u; r.html(c.ajaxText).load(u,function(){if(c.onLoad)c.onLoad.call(this,h);if(cc)h.w.jqmAddClose($(cc,h.w));e(h);});} else if(cc)h.w.jqmAddClose($(cc,h.w)); if(c.toTop&&h.o)h.w.before('').insertAfter(h.o); (c.onShow)?c.onShow(h):h.w.show();e(h);return F; }, close:function(s){var h=H[s];if(!h.a)return F;h.a=F; if(A[0]){A.pop();if(!A[0])L('unbind');} if(h.c.toTop&&h.o)$('#jqmP'+h.w[0]._jqm).after(h.w).remove(); if(h.c.onHide)h.c.onHide(h);else{h.w.hide();if(h.o)h.o.remove();} return F; }, params:{}}; var s=0,H=$.jqm.hash,A=[],F=false, e=function(h){f(h);}, f=function(h){try{$(':input:visible',h.w)[0].focus();}catch(_){}}, L=function(t){$(document)[t]("keypress",m)[t]("keydown",m)[t]("mousedown",m);}, m=function(e){var h=H[A[A.length-1]],r=(!$(e.target).parents('.jqmID'+h.s)[0]);if(r){$('.jqmID'+h.s).each(function(){var $self=$(this),offset=$self.offset();if(offset.top<=e.pageY && e.pageY<=offset.top+$self.height() && offset.left<=e.pageX && e.pageX<=offset.left+$self.width()){r=false;return false;}});f(h);}return !r;}, hs=function(w,t,c){return w.each(function(){var s=this._jqm;$(t).each(function() { if(!this[c]){this[c]=[];$(this).click(function(){for(var i in {jqmShow:1,jqmHide:1})for(var s in this[i])if(H[this[i][s]])H[this[i][s]].w[i](this);return F;});}this[c].push(s);});});}; })(jQuery);/* * jqDnR - Minimalistic Drag'n'Resize for jQuery. * * Copyright (c) 2007 Brice Burgess , http://www.iceburg.net * Licensed under the MIT License: * http://www.opensource.org/licenses/mit-license.php * * $Version: 2007.08.19 +r2 */ (function($){ $.fn.jqDrag=function(h){return i(this,h,'d');}; $.fn.jqResize=function(h,ar){return i(this,h,'r',ar);}; $.jqDnR={ dnr:{}, e:0, drag:function(v){ if(M.k == 'd'){E.css({left:M.X+v.pageX-M.pX,top:M.Y+v.pageY-M.pY});} else { E.css({width:Math.max(v.pageX-M.pX+M.W,0),height:Math.max(v.pageY-M.pY+M.H,0)}); if(M1){E1.css({width:Math.max(v.pageX-M1.pX+M1.W,0),height:Math.max(v.pageY-M1.pY+M1.H,0)});} } return false; }, stop:function(){ //E.css('opacity',M.o); $(document).unbind('mousemove',J.drag).unbind('mouseup',J.stop); } }; var J=$.jqDnR,M=J.dnr,E=J.e,E1,M1, i=function(e,h,k,aR){ return e.each(function(){ h=(h)?$(h,e):e; h.bind('mousedown',{e:e,k:k},function(v){ var d=v.data,p={};E=d.e;E1 = aR ? $(aR) : false; // attempt utilization of dimensions plugin to fix IE issues if(E.css('position') != 'relative'){try{E.position(p);}catch(e){}} M={ X:p.left||f('left')||0, Y:p.top||f('top')||0, W:f('width')||E[0].scrollWidth||0, H:f('height')||E[0].scrollHeight||0, pX:v.pageX, pY:v.pageY, k:d.k //o:E.css('opacity') }; // also resize if(E1 && d.k != 'd'){ M1={ X:p.left||f1('left')||0, Y:p.top||f1('top')||0, W:E1[0].offsetWidth||f1('width')||0, H:E1[0].offsetHeight||f1('height')||0, pX:v.pageX, pY:v.pageY, k:d.k }; } else {M1 = false;} //E.css({opacity:0.8}); if($("input.hasDatepicker",E[0])[0]) { try {$("input.hasDatepicker",E[0]).datepicker('hide');}catch (dpe){} } $(document).mousemove($.jqDnR.drag).mouseup($.jqDnR.stop); return false; }); }); }, f=function(k){return parseInt(E.css(k),10)||false;}, f1=function(k){return parseInt(E1.css(k),10)||false;}; })(jQuery);/* The below work is licensed under Creative Commons GNU LGPL License. Original work: License: http://creativecommons.org/licenses/LGPL/2.1/ Author: Stefan Goessner/2006 Web: http://goessner.net/ Modifications made: Version: 0.9-p5 Description: Restructured code, JSLint validated (no strict whitespaces), added handling of empty arrays, empty strings, and int/floats values. Author: Michael Schøler/2008-01-29 Web: http://michael.hinnerup.net/blog/2008/01/26/converting-json-to-xml-and-xml-to-json/ Description: json2xml added support to convert functions as CDATA so it will be easy to write characters that cause some problems when convert Author: Tony Tomov */ /*global alert */ var xmlJsonClass = { // Param "xml": Element or document DOM node. // Param "tab": Tab or indent string for pretty output formatting omit or use empty string "" to supress. // Returns: JSON string xml2json: function(xml, tab) { if (xml.nodeType === 9) { // document node xml = xml.documentElement; } var nws = this.removeWhite(xml); var obj = this.toObj(nws); var json = this.toJson(obj, xml.nodeName, "\t"); return "{\n" + tab + (tab ? json.replace(/\t/g, tab) : json.replace(/\t|\n/g, "")) + "\n}"; }, // Param "o": JavaScript object // Param "tab": tab or indent string for pretty output formatting omit or use empty string "" to supress. // Returns: XML string json2xml: function(o, tab) { var toXml = function(v, name, ind) { var xml = ""; var i, n; if (v instanceof Array) { if (v.length === 0) { xml += ind + "<"+name+">__EMPTY_ARRAY_\n"; } else { for (i = 0, n = v.length; i < n; i += 1) { var sXml = ind + toXml(v[i], name, ind+"\t") + "\n"; xml += sXml; } } } else if (typeof(v) === "object") { var hasChild = false; xml += ind + "<" + name; var m; for (m in v) if (v.hasOwnProperty(m)) { if (m.charAt(0) === "@") { xml += " " + m.substr(1) + "=\"" + v[m].toString() + "\""; } else { hasChild = true; } } xml += hasChild ? ">" : "/>"; if (hasChild) { for (m in v) if (v.hasOwnProperty(m)) { if (m === "#text") { xml += v[m]; } else if (m === "#cdata") { xml += ""; } else if (m.charAt(0) !== "@") { xml += toXml(v[m], m, ind+"\t"); } } xml += (xml.charAt(xml.length - 1) === "\n" ? ind : "") + ""; } } else if (typeof(v) === "function") { xml += ind + "<" + name + ">" + "" + ""; } else { if (v === undefined ) { v = ""; } if (v.toString() === "\"\"" || v.toString().length === 0) { xml += ind + "<" + name + ">__EMPTY_STRING_"; } else { xml += ind + "<" + name + ">" + v.toString() + ""; } } return xml; }; var xml = ""; var m; for (m in o) if (o.hasOwnProperty(m)) { xml += toXml(o[m], m, ""); } return tab ? xml.replace(/\t/g, tab) : xml.replace(/\t|\n/g, ""); }, // Internal methods toObj: function(xml) { var o = {}; var FuncTest = /function/i; if (xml.nodeType === 1) { // element node .. if (xml.attributes.length) { // element with attributes .. var i; for (i = 0; i < xml.attributes.length; i += 1) { o["@" + xml.attributes[i].nodeName] = (xml.attributes[i].nodeValue || "").toString(); } } if (xml.firstChild) { // element has child nodes .. var textChild = 0, cdataChild = 0, hasElementChild = false; var n; for (n = xml.firstChild; n; n = n.nextSibling) { if (n.nodeType === 1) { hasElementChild = true; } else if (n.nodeType === 3 && n.nodeValue.match(/[^ \f\n\r\t\v]/)) { // non-whitespace text textChild += 1; } else if (n.nodeType === 4) { // cdata section node cdataChild += 1; } } if (hasElementChild) { if (textChild < 2 && cdataChild < 2) { // structured element with evtl. a single text or/and cdata node .. this.removeWhite(xml); for (n = xml.firstChild; n; n = n.nextSibling) { if (n.nodeType === 3) { // text node o["#text"] = this.escape(n.nodeValue); } else if (n.nodeType === 4) { // cdata node if (FuncTest.test(n.nodeValue)) { o[n.nodeName] = [o[n.nodeName], n.nodeValue]; } else { o["#cdata"] = this.escape(n.nodeValue); } } else if (o[n.nodeName]) { // multiple occurence of element .. if (o[n.nodeName] instanceof Array) { o[n.nodeName][o[n.nodeName].length] = this.toObj(n); } else { o[n.nodeName] = [o[n.nodeName], this.toObj(n)]; } } else { // first occurence of element .. o[n.nodeName] = this.toObj(n); } } } else { // mixed content if (!xml.attributes.length) { o = this.escape(this.innerXml(xml)); } else { o["#text"] = this.escape(this.innerXml(xml)); } } } else if (textChild) { // pure text if (!xml.attributes.length) { o = this.escape(this.innerXml(xml)); if (o === "__EMPTY_ARRAY_") { o = "[]"; } else if (o === "__EMPTY_STRING_") { o = ""; } } else { o["#text"] = this.escape(this.innerXml(xml)); } } else if (cdataChild) { // cdata if (cdataChild > 1) { o = this.escape(this.innerXml(xml)); } else { for (n = xml.firstChild; n; n = n.nextSibling) { if(FuncTest.test(xml.firstChild.nodeValue)) { o = xml.firstChild.nodeValue; break; } else { o["#cdata"] = this.escape(n.nodeValue); } } } } } if (!xml.attributes.length && !xml.firstChild) { o = null; } } else if (xml.nodeType === 9) { // document.node o = this.toObj(xml.documentElement); } else { alert("unhandled node type: " + xml.nodeType); } return o; }, toJson: function(o, name, ind, wellform) { if(wellform === undefined) wellform = true; var json = name ? ("\"" + name + "\"") : "", tab = "\t", newline = "\n"; if(!wellform) { tab= ""; newline= ""; } if (o === "[]") { json += (name ? ":[]" : "[]"); } else if (o instanceof Array) { var n, i, ar=[]; for (i = 0, n = o.length; i < n; i += 1) { ar[i] = this.toJson(o[i], "", ind + tab, wellform); } json += (name ? ":[" : "[") + (ar.length > 1 ? (newline + ind + tab + ar.join(","+newline + ind + tab) + newline + ind) : ar.join("")) + "]"; } else if (o === null) { json += (name && ":") + "null"; } else if (typeof(o) === "object") { var arr = [], m; for (m in o) { if (o.hasOwnProperty(m)) { arr[arr.length] = this.toJson(o[m], m, ind + tab, wellform); } } json += (name ? ":{" : "{") + (arr.length > 1 ? (newline + ind + tab + arr.join(","+newline + ind + tab) + newline + ind) : arr.join("")) + "}"; } else if (typeof(o) === "string") { /* var objRegExp = /(^-?\d+\.?\d*$)/; var FuncTest = /function/i; var os = o.toString(); if (objRegExp.test(os) || FuncTest.test(os) || os==="false" || os==="true") { // int or float json += (name && ":") + "\"" +os + "\""; } else { */ json += (name && ":") + "\"" + o.replace(/\\/g,'\\\\').replace(/\"/g,'\\"') + "\""; //} } else { json += (name && ":") + o.toString(); } return json; }, innerXml: function(node) { var s = ""; if ("innerHTML" in node) { s = node.innerHTML; } else { var asXml = function(n) { var s = "", i; if (n.nodeType === 1) { s += "<" + n.nodeName; for (i = 0; i < n.attributes.length; i += 1) { s += " " + n.attributes[i].nodeName + "=\"" + (n.attributes[i].nodeValue || "").toString() + "\""; } if (n.firstChild) { s += ">"; for (var c = n.firstChild; c; c = c.nextSibling) { s += asXml(c); } s += ""; } else { s += "/>"; } } else if (n.nodeType === 3) { s += n.nodeValue; } else if (n.nodeType === 4) { s += ""; } return s; }; for (var c = node.firstChild; c; c = c.nextSibling) { s += asXml(c); } } return s; }, escape: function(txt) { return txt.replace(/[\\]/g, "\\\\").replace(/[\"]/g, '\\"').replace(/[\n]/g, '\\n').replace(/[\r]/g, '\\r'); }, removeWhite: function(e) { e.normalize(); var n; for (n = e.firstChild; n; ) { if (n.nodeType === 3) { // text node if (!n.nodeValue.match(/[^ \f\n\r\t\v]/)) { // pure whitespace text node var nxt = n.nextSibling; e.removeChild(n); n = nxt; } else { n = n.nextSibling; } } else if (n.nodeType === 1) { // element node this.removeWhite(n); n = n.nextSibling; } else { // any other node n = n.nextSibling; } } return e; } };/* ** * formatter for values but most of the values if for jqGrid * Some of this was inspired and based on how YUI does the table datagrid but in jQuery fashion * we are trying to keep it as light as possible * Joshua Burnett josh@9ci.com * http://www.greenbill.com * * Changes from 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 * **/ /*jshint eqeqeq:false */ /*global jQuery */ (function($) { "use strict"; $.fmatter = {}; //opts can be id:row id for the row, rowdata:the data for the row, colmodel:the column model for this column //example {id:1234,} $.extend($.fmatter,{ isBoolean : function(o) { return typeof o === 'boolean'; }, isObject : function(o) { return (o && (typeof o === 'object' || $.isFunction(o))) || false; }, isString : function(o) { return typeof o === 'string'; }, isNumber : function(o) { return typeof o === 'number' && isFinite(o); }, isValue : function (o) { return (this.isObject(o) || this.isString(o) || this.isNumber(o) || this.isBoolean(o)); }, isEmpty : function(o) { if(!this.isString(o) && this.isValue(o)) { return false; } if (!this.isValue(o)){ return true; } o = $.trim(o).replace(/\ \;/ig,'').replace(/\ \;/ig,''); return o===""; } }); $.fn.fmatter = function(formatType, cellval, opts, rwd, act) { // build main options before element iteration var v=cellval; opts = $.extend({}, $.jgrid.formatter, opts); try { v = $.fn.fmatter[formatType].call(this, cellval, opts, rwd, act); } catch(fe){} return v; }; $.fmatter.util = { // Taken from YAHOO utils NumberFormat : function(nData,opts) { if(!$.fmatter.isNumber(nData)) { nData *= 1; } if($.fmatter.isNumber(nData)) { var bNegative = (nData < 0); var sOutput = String(nData); var sDecimalSeparator = opts.decimalSeparator || "."; var nDotIndex; if($.fmatter.isNumber(opts.decimalPlaces)) { // Round to the correct decimal place var nDecimalPlaces = opts.decimalPlaces; var nDecimal = Math.pow(10, nDecimalPlaces); sOutput = String(Math.round(nData*nDecimal)/nDecimal); nDotIndex = sOutput.lastIndexOf("."); if(nDecimalPlaces > 0) { // Add the decimal separator if(nDotIndex < 0) { sOutput += sDecimalSeparator; nDotIndex = sOutput.length-1; } // Replace the "." else if(sDecimalSeparator !== "."){ sOutput = sOutput.replace(".",sDecimalSeparator); } // Add missing zeros while((sOutput.length - 1 - nDotIndex) < nDecimalPlaces) { sOutput += "0"; } } } if(opts.thousandsSeparator) { var sThousandsSeparator = opts.thousandsSeparator; nDotIndex = sOutput.lastIndexOf(sDecimalSeparator); nDotIndex = (nDotIndex > -1) ? nDotIndex : sOutput.length; var sNewOutput = sOutput.substring(nDotIndex); var nCount = -1, i; for (i=nDotIndex; i>0; i--) { nCount++; if ((nCount%3 === 0) && (i !== nDotIndex) && (!bNegative || (i > 1))) { sNewOutput = sThousandsSeparator + sNewOutput; } sNewOutput = sOutput.charAt(i-1) + sNewOutput; } sOutput = sNewOutput; } // Prepend prefix sOutput = (opts.prefix) ? opts.prefix + sOutput : sOutput; // Append suffix sOutput = (opts.suffix) ? sOutput + opts.suffix : sOutput; return sOutput; } return nData; } }; $.fn.fmatter.defaultFormat = function(cellval, opts) { return ($.fmatter.isValue(cellval) && cellval!=="" ) ? cellval : opts.defaultValue || " "; }; $.fn.fmatter.email = function(cellval, opts) { if(!$.fmatter.isEmpty(cellval)) { return "" + cellval + ""; } return $.fn.fmatter.defaultFormat(cellval,opts ); }; $.fn.fmatter.checkbox =function(cval, opts) { var op = $.extend({},opts.checkbox), ds; if(opts.colModel !== undefined && opts.colModel.formatoptions !== undefined) { op = $.extend({},op,opts.colModel.formatoptions); } if(op.disabled===true) {ds = "disabled=\"disabled\"";} else {ds="";} if($.fmatter.isEmpty(cval) || cval === undefined ) {cval = $.fn.fmatter.defaultFormat(cval,op);} cval=String(cval); cval=cval.toLowerCase(); var bchk = cval.search(/(false|f|0|no|n|off|undefined)/i)<0 ? " checked='checked' " : ""; return ""; }; $.fn.fmatter.link = function(cellval, opts) { var op = {target:opts.target}; var target = ""; if(opts.colModel !== undefined && opts.colModel.formatoptions !== undefined) { op = $.extend({},op,opts.colModel.formatoptions); } if(op.target) {target = 'target=' + op.target;} if(!$.fmatter.isEmpty(cellval)) { return "" + cellval + ""; } return $.fn.fmatter.defaultFormat(cellval,opts); }; $.fn.fmatter.showlink = function(cellval, opts) { var op = {baseLinkUrl: opts.baseLinkUrl,showAction:opts.showAction, addParam: opts.addParam || "", target: opts.target, idName: opts.idName}, target = "", idUrl; if(opts.colModel !== undefined && opts.colModel.formatoptions !== undefined) { op = $.extend({},op,opts.colModel.formatoptions); } if(op.target) {target = 'target=' + op.target;} idUrl = op.baseLinkUrl+op.showAction + '?'+ op.idName+'='+opts.rowId+op.addParam; if($.fmatter.isString(cellval) || $.fmatter.isNumber(cellval)) { //add this one even if its blank string return "" + cellval + ""; } return $.fn.fmatter.defaultFormat(cellval,opts); }; $.fn.fmatter.integer = function(cellval, opts) { var op = $.extend({},opts.integer); if(opts.colModel !== undefined && opts.colModel.formatoptions !== undefined) { op = $.extend({},op,opts.colModel.formatoptions); } if($.fmatter.isEmpty(cellval)) { return op.defaultValue; } return $.fmatter.util.NumberFormat(cellval,op); }; $.fn.fmatter.number = function (cellval, opts) { var op = $.extend({},opts.number); if(opts.colModel !== undefined && opts.colModel.formatoptions !== undefined) { op = $.extend({},op,opts.colModel.formatoptions); } if($.fmatter.isEmpty(cellval)) { return op.defaultValue; } return $.fmatter.util.NumberFormat(cellval,op); }; $.fn.fmatter.currency = function (cellval, opts) { var op = $.extend({},opts.currency); if(opts.colModel !== undefined && opts.colModel.formatoptions !== undefined) { op = $.extend({},op,opts.colModel.formatoptions); } if($.fmatter.isEmpty(cellval)) { return op.defaultValue; } return $.fmatter.util.NumberFormat(cellval,op); }; $.fn.fmatter.date = function (cellval, opts, rwd, act) { var op = $.extend({},opts.date); if(opts.colModel !== undefined && opts.colModel.formatoptions !== undefined) { op = $.extend({},op,opts.colModel.formatoptions); } if(!op.reformatAfterEdit && act === 'edit'){ return $.fn.fmatter.defaultFormat(cellval, opts); } if(!$.fmatter.isEmpty(cellval)) { return $.jgrid.parseDate(op.srcformat,cellval,op.newformat,op); } return $.fn.fmatter.defaultFormat(cellval, opts); }; $.fn.fmatter.select = function (cellval,opts) { // jqGrid specific cellval = String(cellval); var oSelect = false, ret=[], sep, delim; if(opts.colModel.formatoptions !== undefined){ oSelect= opts.colModel.formatoptions.value; sep = opts.colModel.formatoptions.separator === undefined ? ":" : opts.colModel.formatoptions.separator; delim = opts.colModel.formatoptions.delimiter === undefined ? ";" : opts.colModel.formatoptions.delimiter; } else if(opts.colModel.editoptions !== undefined){ oSelect= opts.colModel.editoptions.value; sep = opts.colModel.editoptions.separator === undefined ? ":" : opts.colModel.editoptions.separator; delim = opts.colModel.editoptions.delimiter === undefined ? ";" : opts.colModel.editoptions.delimiter; } if (oSelect) { var msl = opts.colModel.editoptions.multiple === true ? true : false, scell = [], sv; if(msl) {scell = cellval.split(",");scell = $.map(scell,function(n){return $.trim(n);});} if ($.fmatter.isString(oSelect)) { // mybe here we can use some caching with care ???? var so = oSelect.split(delim), j=0, i; for(i=0; i 2 ) { sv[1] = $.map(sv,function(n,i){if(i>0) {return n;}}).join(sep); } if(msl) { if($.inArray(sv[0],scell)>-1) { ret[j] = sv[1]; j++; } } else if($.trim(sv[0]) === $.trim(cellval)) { ret[0] = sv[1]; break; } } } else if($.fmatter.isObject(oSelect)) { // this is quicker if(msl) { ret = $.map(scell, function(n){ return oSelect[n]; }); } else { ret[0] = oSelect[cellval] || ""; } } } cellval = ret.join(", "); return cellval === "" ? $.fn.fmatter.defaultFormat(cellval,opts) : cellval; }; $.fn.fmatter.rowactions = function(act) { var $tr = $(this).closest("tr.jqgrow"), rid = $tr.attr("id"), $id = $(this).closest("table.ui-jqgrid-btable").attr('id').replace(/_frozen([^_]*)$/,'$1'), $grid = $("#"+$id), $t = $grid[0], p = $t.p, cm = p.colModel[$.jgrid.getCellIndex(this)], $actionsDiv = cm.frozen ? $("tr#"+rid+" td:eq("+$.jgrid.getCellIndex(this)+") > div",$grid) :$(this).parent(), op = { keys: false, onEdit: null, onSuccess: null, afterSave: null, onError: null, afterRestore: null, extraparam: {}, url: null, restoreAfterError: true, mtype: "POST", delOptions: {}, editOptions: {} }, saverow = function(rowid, res) { if($.isFunction(op.afterSave)) { op.afterSave.call($t, rowid, res); } $actionsDiv.find("div.ui-inline-edit,div.ui-inline-del").show(); $actionsDiv.find("div.ui-inline-save,div.ui-inline-cancel").hide(); }, restorerow = function(rowid) { if($.isFunction(op.afterRestore)) { op.afterRestore.call($t, rowid); } $actionsDiv.find("div.ui-inline-edit,div.ui-inline-del").show(); $actionsDiv.find("div.ui-inline-save,div.ui-inline-cancel").hide(); }; if (cm.formatoptions !== undefined) { op = $.extend(op,cm.formatoptions); } if (p.editOptions !== undefined) { op.editOptions = p.editOptions; } if (p.delOptions !== undefined) { op.delOptions = p.delOptions; } if ($tr.hasClass("jqgrid-new-row")){ op.extraparam[p.prmNames.oper] = p.prmNames.addoper; } var actop = { keys: op.keys, oneditfunc: op.onEdit, successfunc: op.onSuccess, url: op.url, extraparam: op.extraparam, aftersavefunc: saverow, errorfunc: op.onError, afterrestorefunc: restorerow, restoreAfterError: op.restoreAfterError, mtype: op.mtype }; switch(act) { case 'edit': $grid.jqGrid('editRow', rid, actop); $actionsDiv.find("div.ui-inline-edit,div.ui-inline-del").hide(); $actionsDiv.find("div.ui-inline-save,div.ui-inline-cancel").show(); $grid.triggerHandler("jqGridAfterGridComplete"); break; case 'save': if ($grid.jqGrid('saveRow', rid, actop)) { $actionsDiv.find("div.ui-inline-edit,div.ui-inline-del").show(); $actionsDiv.find("div.ui-inline-save,div.ui-inline-cancel").hide(); $grid.triggerHandler("jqGridAfterGridComplete"); } break; case 'cancel' : $grid.jqGrid('restoreRow', rid, restorerow); $actionsDiv.find("div.ui-inline-edit,div.ui-inline-del").show(); $actionsDiv.find("div.ui-inline-save,div.ui-inline-cancel").hide(); $grid.triggerHandler("jqGridAfterGridComplete"); break; case 'del': $grid.jqGrid('delGridRow', rid, op.delOptions); break; case 'formedit': $grid.jqGrid('setSelection', rid); $grid.jqGrid('editGridRow', rid, op.editOptions); break; } }; $.fn.fmatter.actions = function(cellval,opts) { var op={keys:false, editbutton:true, delbutton:true, editformbutton: false}, rowid=opts.rowId, str="",ocl; if(opts.colModel.formatoptions !== undefined) { op = $.extend(op,opts.colModel.formatoptions); } if(rowid === undefined || $.fmatter.isEmpty(rowid)) {return "";} if(op.editformbutton){ ocl = "id='jEditButton_"+rowid+"' onclick=jQuery.fn.fmatter.rowactions.call(this,'formedit'); onmouseover=jQuery(this).addClass('ui-state-hover'); onmouseout=jQuery(this).removeClass('ui-state-hover'); "; str += "
"; } else if(op.editbutton){ ocl = "id='jEditButton_"+rowid+"' onclick=jQuery.fn.fmatter.rowactions.call(this,'edit'); onmouseover=jQuery(this).addClass('ui-state-hover'); onmouseout=jQuery(this).removeClass('ui-state-hover') "; str += "
"; } if(op.delbutton) { ocl = "id='jDeleteButton_"+rowid+"' onclick=jQuery.fn.fmatter.rowactions.call(this,'del'); onmouseover=jQuery(this).addClass('ui-state-hover'); onmouseout=jQuery(this).removeClass('ui-state-hover'); "; str += "
"; } ocl = "id='jSaveButton_"+rowid+"' onclick=jQuery.fn.fmatter.rowactions.call(this,'save'); onmouseover=jQuery(this).addClass('ui-state-hover'); onmouseout=jQuery(this).removeClass('ui-state-hover'); "; str += ""; ocl = "id='jCancelButton_"+rowid+"' onclick=jQuery.fn.fmatter.rowactions.call(this,'cancel'); onmouseover=jQuery(this).addClass('ui-state-hover'); onmouseout=jQuery(this).removeClass('ui-state-hover'); "; str += ""; return "
" + str + "
"; }; $.unformat = function (cellval,options,pos,cnt) { // specific for jqGrid only var ret, formatType = options.colModel.formatter, op =options.colModel.formatoptions || {}, sep, re = /([\.\*\_\'\(\)\{\}\+\?\\])/g, unformatFunc = options.colModel.unformat||($.fn.fmatter[formatType] && $.fn.fmatter[formatType].unformat); if(unformatFunc !== undefined && $.isFunction(unformatFunc) ) { ret = unformatFunc.call(this, $(cellval).text(), options, cellval); } else if(formatType !== undefined && $.fmatter.isString(formatType) ) { var opts = $.jgrid.formatter || {}, stripTag; switch(formatType) { case 'integer' : op = $.extend({},opts.integer,op); sep = op.thousandsSeparator.replace(re,"\\$1"); stripTag = new RegExp(sep, "g"); ret = $(cellval).text().replace(stripTag,''); break; case 'number' : op = $.extend({},opts.number,op); sep = op.thousandsSeparator.replace(re,"\\$1"); stripTag = new RegExp(sep, "g"); ret = $(cellval).text().replace(stripTag,"").replace(op.decimalSeparator,'.'); break; case 'currency': op = $.extend({},opts.currency,op); sep = op.thousandsSeparator.replace(re,"\\$1"); stripTag = new RegExp(sep, "g"); ret = $(cellval).text(); if (op.prefix && op.prefix.length) { ret = ret.substr(op.prefix.length); } if (op.suffix && op.suffix.length) { ret = ret.substr(0, ret.length - op.suffix.length); } ret = ret.replace(stripTag,'').replace(op.decimalSeparator,'.'); break; case 'checkbox': var cbv = (options.colModel.editoptions) ? options.colModel.editoptions.value.split(":") : ["Yes","No"]; ret = $('input',cellval).is(":checked") ? cbv[0] : cbv[1]; break; case 'select' : ret = $.unformat.select(cellval,options,pos,cnt); break; case 'actions': return ""; default: ret= $(cellval).text(); } } return ret !== undefined ? ret : cnt===true ? $(cellval).text() : $.jgrid.htmlDecode($(cellval).html()); }; $.unformat.select = function (cellval,options,pos,cnt) { // Spacial case when we have local data and perform a sort // cnt is set to true only in sortDataArray var ret = []; var cell = $(cellval).text(); if(cnt===true) {return cell;} var op = $.extend({}, options.colModel.formatoptions !== undefined ? options.colModel.formatoptions: options.colModel.editoptions), sep = op.separator === undefined ? ":" : op.separator, delim = op.delimiter === undefined ? ";" : op.delimiter; if(op.value){ var oSelect = op.value, msl = op.multiple === true ? true : false, scell = [], sv; if(msl) {scell = cell.split(",");scell = $.map(scell,function(n){return $.trim(n);});} if ($.fmatter.isString(oSelect)) { var so = oSelect.split(delim), j=0, i; for(i=0; i 2 ) { sv[1] = $.map(sv,function(n,i){if(i>0) {return n;}}).join(sep); } if(msl) { if($.inArray(sv[1],scell)>-1) { ret[j] = sv[0]; j++; } } else if($.trim(sv[1]) === $.trim(cell)) { ret[0] = sv[0]; break; } } } else if($.fmatter.isObject(oSelect) || $.isArray(oSelect) ){ if(!msl) {scell[0] = cell;} ret = $.map(scell, function(n){ var rv; $.each(oSelect, function(i,val){ if (val === n) { rv = i; return false; } }); if( rv !== undefined ) {return rv;} }); } return ret.join(", "); } return cell || ""; }; $.unformat.date = function (cellval, opts) { var op = $.jgrid.formatter.date || {}; if(opts.formatoptions !== undefined) { op = $.extend({},op,opts.formatoptions); } if(!$.fmatter.isEmpty(cellval)) { return $.jgrid.parseDate(op.newformat,cellval,op.srcformat,op); } return $.fn.fmatter.defaultFormat(cellval, opts); }; })(jQuery); /*jshint eqeqeq:false */ /*global 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 */ "use strict"; $.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.gb && typeof o.gb === "string" && o.gb.substr(0,6) === "#gbox_" ? o.onClose.call($("#" + o.gb.substr(6))[0], selector) : 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) { p = $.extend(true, {}, $.jgrid.jqModal || {}, p); 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(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 = $.jgrid.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(p.drag === undefined) { p.drag=true;} if(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("#"+$.jgrid.jqID(aIDs.themodal),{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: $.jgrid.showModal, onHide: $.jgrid.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, 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(true, mopt, $.jgrid.jqModal || {}, {caption:""+caption+""}, modalopt || {}); var jm = mopt.jqModal, self = this; if($.fn.jqm && !jm) { jm = false; } // in case there is no jqModal var buttstr ="", i; if(mopt.buttons.length > 0) { for(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") { $.jgrid.hideModal("#info_dialog",{jqm:jm}); } $("#info_dialog").remove(); } catch (e){} $.jgrid.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, onClose: $("#info_dialog").data("onClose") || mopt.onClose, gb: $("#info_dialog").data("gbox") || mopt.gbox }); 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(); } $.jgrid.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){} }, bindEv: function (el, opt) { var $t = this; if($.isFunction(opt.dataInit)) { opt.dataInit.call($t,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); } }); } }, // Form Functions createEl : function(eltype,options,vl,autowidth, ajaxso) { var elem = "", $t = this; function setAttributes(elm, atr, exl ) { var exclude = ['dataInit','dataEvents','dataUrl', 'buildSelect','sopt', 'searchhidden', 'defaultValue', 'attr', 'custom_element', 'custom_value']; if(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); $(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|f|0|no|n|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']); $(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(options.dataUrl !== undefined) { var rowid = options.name ? String(options.id).substring(0, String(options.id).length - String(options.name).length - 1) : String(options.id), postData = options.postData || ajaxso.postData; if ($t.p && $t.p.idPrefix) { rowid = $.jgrid.stripPref($t.p.idPrefix, rowid); } else { postData = undefined; // don't use postData for searching from jqFilter. One can implement the feature in the future if required. } $.ajax($.extend({ url: options.dataUrl, type : "GET", dataType: "html", data: $.isFunction(postData) ? postData.call($t, rowid, vl, String(options.name)) : postData, context: {elem:elem, options:options, vl:vl}, success: function(data){ var ovm = [], elem = this.elem, vl = this.vl, options = $.extend({},this.options), msl = options.multiple===true, a = $.isFunction(options.buildSelect) ? options.buildSelect.call($t,data) : data; if(typeof a === 'string') { a = $( $.trim( a ) ).html(); } if(a) { $(elem).append(a); setAttributes(elem, options); if(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(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, key; for (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']); } 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); 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); break; case "custom" : elem = document.createElement("span"); try { if($.isFunction(options.custom_element)) { var celm = options.custom_element.call($t,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") { $.jgrid.info_dialog($.jgrid.errors.errcap,"function 'custom_element' "+$.jgrid.edit.msg.nodefined, $.jgrid.edit.bClose);} if (e==="e2") { $.jgrid.info_dialog($.jgrid.errors.errcap,"function 'custom_element' "+$.jgrid.edit.msg.novalue,$.jgrid.edit.bClose);} else { $.jgrid.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 ); }, 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, i; for(i=0;i12){ return false; } if(dln === -1) { return false; } 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; } return false; }, checkTime : function(time){ // checks only hh:ss (and optional am/pm) var re = /^(\d{1,2}):(\d{2})([apAP][Mm])?$/,regs; if(!$.jgrid.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, customobject, nam) { var edtrul,i, nm, dft, len, g = this, cm = g.p.colModel; if(customobject === undefined) { if(typeof valref==='string'){ for( i =0, len=cm.length;i=0) { edtrul = cm[valref].editrules; } } else { edtrul = customobject; nm = nam===undefined ? "_" : nam; } if(edtrul) { if(!nm) { nm = g.p.colNames != null ? g.p.colNames[valref] : cm[valref].label; } if(edtrul.required === true) { if( $.jgrid.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 && $.jgrid.isEmpty(val)) ) { if(isNaN(val)) { return [false,nm+": "+$.jgrid.edit.msg.number,""]; } } } if(edtrul.minValue !== undefined && !isNaN(edtrul.minValue)) { if (parseFloat(val) < parseFloat(edtrul.minValue) ) { return [false,nm+": "+$.jgrid.edit.msg.minValue+" "+edtrul.minValue,""];} } if(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 && $.jgrid.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 && $.jgrid.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 && $.jgrid.isEmpty(val)) ) { if(cm[valref].formatoptions && cm[valref].formatoptions.newformat) { dft = cm[valref].formatoptions.newformat; if( $.jgrid.formatter.date.masks.hasOwnProperty(dft) ) { dft = $.jgrid.formatter.date.masks[dft]; } } else { dft = cm[valref].datefmt || "Y-m-d"; } if(!$.jgrid.checkDate (dft, val)) { return [false,nm+": "+$.jgrid.edit.msg.date+" - "+dft,""]; } } } if(edtrul.time === true) { if( !(rqfield === false && $.jgrid.isEmpty(val)) ) { if(!$.jgrid.checkTime (val)) { return [false,nm+": "+$.jgrid.edit.msg.date+" - hh:mm (am/pm)",""]; } } } if(edtrul.url === true) { if( !(rqfield === false && $.jgrid.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 && $.jgrid.isEmpty(val)) ) { if($.isFunction(edtrul.custom_func)) { var ret = edtrul.custom_func.call(g,val,nm,valref); return $.isArray(ret) ? ret : [false,$.jgrid.edit.msg.customarray,""]; } return [false,$.jgrid.edit.msg.customfcheck,""]; } } } return [true,"",""]; } }); })(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"} ] } */ /*jshint eqeqeq:false, eqnull:true, devel:true */ /*global jQuery */ (function ($) { "use strict"; $.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 : [], operands : 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'], strarr : ['text', 'string', 'blob'], groupOps : [{ op: "AND", text: "AND" }, { op: "OR", text: "OR" }], groupButton : true, ruleButtons : true, direction : "ltr" }, $.jgrid.filter, 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 this.p.initFilter = $.extend(true,{},this.p.filter); // set default values for the columns if they are not set if( !len ) {return;} for(i=0; i < len; i++) { cl = this.p.columns[i]; if( cl.stype ) { // grid compatibility cl.inputtype = cl.stype; } else if(!cl.inputtype) { cl.inputtype = 'text'; } if( cl.sorttype ) { // grid compatibility cl.searchtype = cl.sorttype; } else if (!cl.searchtype) { cl.searchtype = 'string'; } if(cl.hidden === undefined) { // jqGrid compatibility cl.hidden = false; } if(!cl.label) { cl.label = cl.name; } if(cl.index) { cl.name = cl.index; } if(!cl.hasOwnProperty('searchoptions')) { cl.searchoptions = {}; } if(!cl.hasOwnProperty('searchrules')) { cl.searchrules = {}; } } if(this.p.showQuery) { $(this).append("
"); } var getGrid = function () { return $("#" + $.jgrid.jqID(p.id))[0] || null; }; /* *Perform checking. * */ var checkData = function(val, colModelItem) { var ret = [true,""], $t = getGrid(); if($.isFunction(colModelItem.searchrules)) { ret = colModelItem.searchrules.call($t, val, colModelItem); } else if($.jgrid && $.jgrid.checkValues) { try { ret = $.jgrid.checkValues.call($t, val, -1, 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 = (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 ( $.inArray(cm.searchtype, that.p.strarr) !== -1 ) {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, $t = getGrid(), 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].text+""; so++; } } $(".selectopts",trpar).empty().append( s ); $(".selectopts",trpar)[0].selectedIndex = 0; if( $.jgrid.msie && $.jgrid.msiever() < 9) { var sw = parseInt($("select.selectopts",trpar)[0].offsetWidth, 10) + 1; $(".selectopts",trpar).width( sw ); $(".selectopts",trpar).css("width","auto"); } // data $(".data",trpar).empty().append( elm ); $.jgrid.bindEv.call($t, elm, cm.searchoptions); $(".input-elm",trpar).bind('change',function( e ) { var tmo = $(this).hasClass("ui-autocomplete-input") ? 200 :0; setTimeout(function(){ var elem = e.target; rule.data = elem.nodeName.toUpperCase() === "SPAN" && cm.searchoptions && $.isFunction(cm.searchoptions.custom_value) ? cm.searchoptions.custom_value.call($t, $(elem).children(".customelement:first"), 'get') : elem.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 = (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.call($t, cm.inputtype,cm.searchoptions, rule.data, true, that.p.ajaxSelectOptions, true); if(rule.op === 'nu' || rule.op === 'nn') { $(ruleDataInput).attr('readonly','true'); $(ruleDataInput).attr('disabled','true'); } //retain the state of disabled text fields in case of null ops // 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 ($.inArray(cm.searchtype, that.p.strarr) !== -1) {op = that.p.stropts;} else {op = that.p.numopts;} str=""; $.each(that.p.ops, function() { aoprs.push(this.oper); }); for ( i = 0; i < op.length; i++) { ina = $.inArray(op[i],aoprs); if(ina !== -1) { selected = rule.op === that.p.ops[ina].oper ? " 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); $.jgrid.bindEv.call($t, ruleDataInput, cm.searchoptions); $(ruleDataInput) .addClass("input-elm") .bind('change', function() { rule.data = cm.inputtype === 'custom' ? cm.searchoptions.custom_value.call($t, $(this).children(".customelement:first"),'get') : $(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 } 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].oper === rule.op) { opUF = this.p.operands.hasOwnProperty(rule.op) ? this.p.operands[rule.op] : ""; opC = this.p.ops[i].oper; 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 } 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 = $.jgrid.parse( pfilter ); } this.each(function(){ this.p.filter = pfilter; this.reDraw(); this.onchange(); }); } }); })(jQuery); /*jshint eqeqeq:false, eqnull:true, devel:true */ /*global xmlJsonClass, 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"; var rp_ge = {}; $.jgrid.extend({ searchGrid : function (p) { p = $.extend(true, { 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, afterChange: null, closeAfterSearch : false, closeAfterReset: false, closeOnEscape : false, searchOnEnter : 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, sopt: null, stringResult: undefined, onClose : null, onSearch : null, onReset : null, toTop : true, overlay : 30, columns : [], tmplNames : null, tmplFilters : null, tmplLabel : ' Template: ', showOnLoad: false, layer: null, operands : { "eq" :"=", "ne":"<>","lt":"<","le":"<=","gt":">","ge":">=","bw":"LIKE","bn":"NOT LIKE","in":"IN","ni":"NOT IN","ew":"LIKE","en":"NOT LIKE","cn":"LIKE","nc":"NOT LIKE","nu":"IS NULL","nn":"ISNOT 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]; if(typeof defaultFilters === "string") { defaultFilters = $.jgrid.parse( defaultFilters ); } if(p.recreateFilter === true) { $("#"+$.jgrid.jqID(IDs.themodal)).remove(); } function showFilter(_filter) { showFrm = $($t).triggerHandler("jqGridFilterBeforeShow", [_filter]); if(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))[0] !== undefined ) { showFilter($("#fbox_"+$.jgrid.jqID(+$t.p.id))); } 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 = (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; cmi = 0; colnm = columns[0].index || columns[0].name; } // 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, ops : p.odata, operands : p.operands, ajaxSelectOptions: $t.p.ajaxSelectOptions, groupOps: p.groupOps, onChange : function() { if(this.p.showQuery) { $('.query',this).html(this.toUserFriendlyString()); } if ($.isFunction(p.afterChange)) { p.afterChange.call($t, $("#"+fid), p); } }, direction : $t.p.direction, id: $t.p.id }); 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 (p.searchOnEnter || p.closeOnEscape) { $("#"+$.jgrid.jqID(IDs.themodal)).keydown(function (e) { var $target = $(e.target); if (p.searchOnEnter && e.which === 13 && // 13 === $.ui.keyCode.ENTER !$target.hasClass('add-group') && !$target.hasClass('add-rule') && !$target.hasClass('delete-group') && !$target.hasClass('delete-rule') && (!$target.hasClass("fm-button") || !$target.is("[id$=_query]"))) { $("#"+fid+"_search").focus().click(); return false; } if (p.closeOnEscape && e.which === 27) { // 27 === $.ui.keyCode.ESCAPE $("#"+$.jgrid.jqID(IDs.modalhead)).find(".ui-jqdialog-titlebar-close").focus().click(); return false; } }); } 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($("#"+fid)); $(".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(true, { top : 0, left: 0, width: 300, datawidth: 'auto', 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, overlayClass : 'ui-widget-overlay' }, $.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, 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))[0] !== undefined) { $("#"+$.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($.jgrid.errors.errcap,"function 'custom_value' "+$.jgrid.edit.msg.novalue,$.jgrid.edit.bClose);} else {$.jgrid.info_dialog($.jgrid.errors.errcap,e.message,$.jgrid.edit.bClose);} } 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(); 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(); } ); 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[role='gridcell']:eq("+i+")",obj.rows[ind]).text(); } else { try { tmp = $.unformat.call(obj, $("td[role='gridcell']:eq("+i+")",obj.rows[ind]),{rowId:rowid, colModel:this},i); } catch (_) { tmp = (this.edittype && this.edittype === "textarea") ? $("td[role='gridcell']:eq("+i+")",obj.rows[ind]).text() : $("td[role='gridcell']: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.call($t) : opt.defaultValue; } if(!this.edittype) {this.edittype = "text";} if($t.p.autoencode) {tmp = $.jgrid.htmlDecode(tmp);} elc = $.jgrid.createEl.call($t,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( $.inArray(this.edittype, ['text','textarea','password','select']) > -1) { $(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(frmopt.label === undefined ? obj.p.colNames[i]: frmopt.label); $("td:eq("+(cp-1)+")",trdata[0]).append(frmopt.elmprefix).append(elc).append(frmopt.elmsuffix); if($.isFunction(opt.custom_value) && rowid !== "_empty" ) { opt.custom_value.call($t, $("#"+nm,"#"+frmgr),'set',tmp); } $.jgrid.bindEv.call($t, elc, opt); 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.call($t) : opt.defaultValue; if(fld[0].type==='checkbox') { vlc = vl.toLowerCase(); if(vlc.search(/(false|f|0|no|n|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 = String(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, "defaultChecked" : true}); } else { $("#"+nm,"#"+fmid)[$t.p.useProp ? 'prop': 'attr']({"checked":false, "defaultChecked" : false}); } } else { tmp = tmp.toLowerCase(); if(tmp.search(/(false|f|0|no|n|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($.jgrid.errors.errcap,"function 'custom_value' "+$.jgrid.edit.msg.nodefined,$.jgrid.edit.bClose);} else {$.jgrid.info_dialog($.jgrid.errors.errcap,e.message,$.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),frmoper); if(retvals && typeof retvals === 'object') {postdata = retvals;} } for( key in postdata ){ if(postdata.hasOwnProperty(key)) { ret = $.jgrid.checkValues.call($t,postdata[key],key); 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, frmoper) || {}; } 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.call($t,postdata,$("#"+frmgr), frmoper); } } 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 || $($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.call($t,postdata) : postdata, complete:function(data,status){ var key; postdata[idname] = $t.p.idPrefix + postdata[idname]; if(data.status >= 300 && data.status !== 304) { 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, frmoper); } 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, frmoper); } } if(ret[0] === false) { $("#FormError>td",frmtb).html(ret[1]); $("#FormError",frmtb).show(); } else { 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].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); } } if(rp_ge[$t.p.id].closeAfterAdd) { if($t.p.treeGrid !== true){ $($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) { fillData("_empty",$t,frmgr); } } 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), frmoper); 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(key in rp_ge[$t.p.id]._savedData) { if(rp_ge[$t.p.id]._savedData.hasOwnProperty(key) && 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(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.hasOwnProperty(key) && 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 = {}; getFormData(); diff = compareData(postdata,rp_ge[$t.p.id]._savedData); if(diff) { $("#"+frmgr).data("disabled",true); $(".confirm","#"+IDs.themodal).show(); stat = false; } } return stat; } function restoreInline() { var i; if (rowid !== "_empty" && $t.p.savedRow !== undefined && $t.p.savedRow.length > 0 && $.isFunction($.fn.jqGrid.restoreRow)) { for (i=0;i<$t.p.savedRow.length;i++) { if ($t.p.savedRow[i].id == rowid) { $($t).jqGrid('restoreRow',rowid); break; } } } } function updateNav(cr, posarr){ var totr = posarr[1].length-1; if (cr===0) { $("#pData",frmtb+"_2").addClass('ui-state-disabled'); } else if( posarr[1][cr-1] !== undefined && $("#"+$.jgrid.jqID(posarr[1][cr-1])).hasClass('ui-state-disabled')) { $("#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 if( posarr[1][cr+1] !== undefined && $("#"+$.jgrid.jqID(posarr[1][cr+1])).hasClass('ui-state-disabled')) { $("#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))[0] !== undefined ) { showFrm = $($t).triggerHandler("jqGridAddEditBeforeInitData", [$("#"+$.jgrid.jqID(frmgr)), frmoper]); if(showFrm === undefined) { showFrm = true; } if(showFrm && onBeforeInit) { showFrm = onBeforeInit.call($t,$("#"+frmgr), frmoper); } 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), frmoper); } $("#"+$.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, overlayClass : p.overlayClass}); if(!closeovrl) { $("." + $.jgrid.jqID(p.overlayClass)).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), frmoper); } } else { var dh = isNaN(p.dataheight) ? p.dataheight : p.dataheight+"px", dw = isNaN(p.datawidth) ? p.datawidth : p.datawidth+"px", frm = $("
").data("disabled",false), tbl = $("
"); showFrm = $($t).triggerHandler("jqGridAddEditBeforeInitData", [$("#"+frmgr), frmoper]); if(showFrm === undefined) { showFrm = true; } if(showFrm && onBeforeInit) { showFrm = onBeforeInit.call($t,$("#"+frmgr,frmoper)); } 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("#"+$.jgrid.jqID(IDs.themodal),{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 zI = p.zIndex || 999;zI ++; $("
"+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:visible","#"+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.call($t,$("#"+frmgr), frmoper);} 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), frmoper);} $("#"+$.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, overlayClass: p.overlayClass}); if(!closeovrl) { $("." + $.jgrid.jqID(p.overlayClass)).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), frmoper); } $(".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 = {}; $("#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 ) { diff = compareData(postdata,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]]]); var nposret; if($.isFunction(p.onclickPgButtons)) { nposret = p.onclickPgButtons.call($t, 'next',$("#"+frmgr),npos[1][npos[0]]); if( nposret !== undefined && nposret === false ) {return false;} } if( $("#"+$.jgrid.jqID(npos[1][npos[0]+1])).hasClass('ui-state-disabled')) {return false;} 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); } 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]]]); var pposret; if($.isFunction(p.onclickPgButtons)) { pposret = p.onclickPgButtons.call($t, 'prev',$("#"+frmgr),ppos[1][ppos[0]]); if( pposret !== undefined && pposret === false ) {return false;} } if( $("#"+$.jgrid.jqID(ppos[1][ppos[0]-1])).hasClass('ui-state-disabled')) {return false;} 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); } return false; }); } var posInit =getCurrPos(); updateNav(posInit[0],posInit); }); }, viewGridRow : function(rowid, p){ p = $.extend(true, { top : 0, left: 0, width: 0, datawidth: 'auto', 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, recreateForm : false }, $.jgrid.view, 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 = "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(rp_ge[$t.p.id].beforeInitData) ? rp_ge[$t.p.id].beforeInitData : false, showFrm = true, maxCols = 1, maxRows=0; if(p.recreateForm===true && $("#"+$.jgrid.jqID(IDs.themodal))[0] !== undefined) { $("#"+$.jgrid.jqID(IDs.themodal)).remove(); } function focusaref(){ //Sfari 3 issues if(rp_ge[$t.p.id].closeOnEscape===true || rp_ge[$t.p.id].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, i, tdtmpl = "  ", tmpl="", tdtmpl2 = "  ", fmtnum = ['integer','number','currency'],max1 =0, max2=0 ,maxw,setme, viewfld; for (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 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(''+ (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,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(); } 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,posarr){ var totr = posarr[1].length-1; if (cr===0) { $("#pData","#"+frmtb+"_2").addClass('ui-state-disabled'); } else if( posarr[1][cr-1] !== undefined && $("#"+$.jgrid.jqID(posarr[1][cr-1])).hasClass('ui-state-disabled')) { $("#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 if( posarr[1][cr+1] !== undefined && $("#"+$.jgrid.jqID(posarr[1][cr+1])).hasClass('ui-state-disabled')) { $("#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))[0] !== undefined ) { if(onBeforeInit) { showFrm = onBeforeInit.call($t,$("#"+frmgr)); if(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(rp_ge[$t.p.id].beforeShowForm)) {rp_ge[$t.p.id].beforeShowForm.call($t,$("#"+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", dw = isNaN(p.datawidth) ? p.datawidth : p.datawidth+"px", frm = $("
"), tbl =$("
"); if(onBeforeInit) { showFrm = onBeforeInit.call($t,$("#"+frmgr)); if(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 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(rp_ge[$t.p.id].closeOnEscape) {$.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{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.call($t,$("#"+frmgr));} $.jgrid.viewModal("#"+$.jgrid.jqID(IDs.themodal),{gbox:"#gbox_"+$.jgrid.jqID(gID),jqm:p.jqModal,overlay: p.overlay, 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.call($t,'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.call($t,'next',$("#"+frmgr),npos[1][npos[0]+1]); } updateNav(npos[0]+1,npos); } 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.call($t,'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.call($t,'prev',$("#"+frmgr),ppos[1][ppos[0]-1]); } updateNav(ppos[0]-1,ppos); } focusaref(); return false; }); } var posInit =getCurrPos(); updateNav(posInit[0],posInit); }); }, delGridRow : function(rowids,p) { p = $.extend(true, { 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 ($.isArray(rowids)) {rowids = rowids.join();} if ( $("#"+$.jgrid.jqID(IDs.themodal))[0] !== undefined ) { if(onBeforeInit) { showFrm = onBeforeInit.call($t,$("#"+dtbl)); if(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.call($t,$("#"+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.call($t,$("#"+dtbl));} } else { var dh = isNaN(rp_ge[$t.p.id].dataheight) ? rp_ge[$t.p.id].dataheight : rp_ge[$t.p.id].dataheight+"px", dw = isNaN(p.datawidth) ? p.datawidth : p.datawidth+"px", 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.call($t,$("#"+dtbl)); if(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,""], pk, postdata = $("#DelData>td","#"+dtbl).text(); //the pair is name=val1,val2,... onCS = {}; if( $.isFunction( rp_ge[$t.p.id].onclickSubmit ) ) {onCS = rp_ge[$t.p.id].onclickSubmit.call($t,rp_ge[$t.p.id], postdata) || {};} if( $.isFunction( rp_ge[$t.p.id].beforeSubmit ) ) {ret = rp_ge[$t.p.id].beforeSubmit.call($t,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(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 || $($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.call($t,postd) : postd, complete:function(data,status){ var i; if(data.status >= 300 && data.status !== 304) { ret[0] = false; 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 if( $.isFunction( rp_ge[$t.p.id].afterSubmit ) ) { ret = rp_ge[$t.p.id].afterSubmit.call($t,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(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.call($t,$("#"+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.call($t,$("#"+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_' + this.p.id, modalhead: 'alerthd_' + this.p.id,modalcontent: 'alertcnt_' + this.p.id}, $t = this, twd, tdw; if(!$t.grid || typeof elem !== 'string') {return;} if ($("#"+alertIDs.themodal)[0] === undefined) { if(!o.alerttop && !o.alertleft) { if (window.innerWidth !== undefined) { o.alertleft = window.innerWidth; o.alerttop = window.innerHeight; } else if (document.documentElement !== undefined && 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 }, "#gview_"+$.jgrid.jqID($t.p.id), $("#gbox_"+$.jgrid.jqID($t.p.id))[0], true ); } var clone = 1, i, onHoverIn = function () { if (!$(this).hasClass('ui-state-disabled')) { $(this).addClass("ui-state-hover"); } }, onHoverOut = function () { $(this).removeClass("ui-state-hover"); }; if(o.cloneToTop && $t.p.toppager) {clone = 2;} for(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(onHoverIn, onHoverOut); 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(onHoverIn, onHoverOut); 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(onHoverIn, onHoverOut); 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(onHoverIn, onHoverOut); 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(onHoverIn, onHoverOut); 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.call($t);} $t.p.search = false; try { var gID = $t.p.id; $t.p.postData.filters =""; try { $("#fbox_"+$.jgrid.jqID(gID)).jqFilter('resetFilter'); } catch(ef) {} if($.isFunction($t.clearToolbar)) {$t.clearToolbar.call($t,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.call($t);} } return false; }).hover(onHoverIn, onHoverOut); 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)[0] !== undefined ) {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: '', position : "last" }, 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+""; if (p.position === 'first') { if (findnav.rows[0].cells.length === 0) { $("tr", findnav).append(sep); } else { $("tr td:eq(0)", findnav).before(sep); } } else { $("tr", findnav).append(sep); } } }); }, GridToForm : function( rowid, formid ) { return this.each(function(){ var $t = this, i; if (!$t.grid) {return;} var rowdata = $($t).jqGrid("getRowData",rowid); if (rowdata) { for(i in rowdata) { if(rowdata.hasOwnProperty(i)) { 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); /*jshint eqeqeq:false, eqnull:true, devel:true */ /*global jQuery */ (function($){ /** * jqGrid extension for manipulating Grid Data * Tony Tomov tony@trirand.com * http://trirand.com/blog/ * Dual licensed under the MIT and GPL licenses: * http://www.opensource.org/licenses/mit-license.php * http://www.gnu.org/licenses/gpl-2.0.html **/ "use strict"; $.jgrid.inlineEdit = $.jgrid.inlineEdit || {}; $.jgrid.extend({ //Editing editRow : function(rowid,keys,oneditfunc,successfunc, url, extraparam, aftersavefunc,errorfunc, afterrestorefunc) { // Compatible mode old versions var o={}, args = $.makeArray(arguments).slice(1); if( $.type(args[0]) === "object" ) { o = args[0]; } else { if (keys !== undefined) { o.keys = keys; } if ($.isFunction(oneditfunc)) { o.oneditfunc = oneditfunc; } if ($.isFunction(successfunc)) { o.successfunc = successfunc; } if (url !== undefined) { o.url = url; } if (extraparam !== undefined) { o.extraparam = extraparam; } if ($.isFunction(aftersavefunc)) { o.aftersavefunc = aftersavefunc; } if ($.isFunction(errorfunc)) { o.errorfunc = errorfunc; } if ($.isFunction(afterrestorefunc)) { o.afterrestorefunc = afterrestorefunc; } // last two not as param, but as object (sorry) //if (restoreAfterError !== undefined) { o.restoreAfterError = restoreAfterError; } //if (mtype !== undefined) { o.mtype = mtype || "POST"; } } o = $.extend(true, { keys : false, oneditfunc: null, successfunc: null, url: null, extraparam: {}, aftersavefunc: null, errorfunc: null, afterrestorefunc: null, restoreAfterError: true, mtype: "POST" }, $.jgrid.inlineEdit, o ); // End compatible return this.each(function(){ var $t = this, nm, tmp, editable, cnt=0, focus=null, svr={}, ind,cm; if (!$t.grid ) { return; } ind = $($t).jqGrid("getInd",rowid,true); if( ind === false ) {return;} editable = $(ind).attr("editable") || "0"; if (editable === "0" && !$(ind).hasClass("not-editable-row")) { cm = $t.p.colModel; $('td[role="gridcell"]',ind).each( function(i) { nm = cm[i].name; var treeg = $t.p.treeGrid===true && nm === $t.p.ExpandColumn; if(treeg) { tmp = $("span:first",this).html();} else { try { tmp = $.unformat.call($t,this,{rowId:rowid, colModel:cm[i]},i); } catch (_) { tmp = ( cm[i].edittype && cm[i].edittype === 'textarea' ) ? $(this).text() : $(this).html(); } } if ( nm !== 'cb' && nm !== 'subgrid' && nm !== 'rn') { if($t.p.autoencode) { tmp = $.jgrid.htmlDecode(tmp); } svr[nm]=tmp; if(cm[i].editable===true) { if(focus===null) { focus = i; } if (treeg) { $("span:first",this).html(""); } else { $(this).html(""); } var opt = $.extend({},cm[i].editoptions || {},{id:rowid+"_"+nm,name:nm}); if(!cm[i].edittype) { cm[i].edittype = "text"; } if(tmp === " " || tmp === " " || (tmp.length===1 && tmp.charCodeAt(0)===160) ) {tmp='';} var elc = $.jgrid.createEl.call($t,cm[i].edittype,opt,tmp,true,$.extend({},$.jgrid.ajaxOptions,$t.p.ajaxSelectOptions || {})); $(elc).addClass("editable"); if(treeg) { $("span:first",this).append(elc); } else { $(this).append(elc); } $.jgrid.bindEv.call($t, elc, opt); //Again IE if(cm[i].edittype === "select" && cm[i].editoptions!==undefined && cm[i].editoptions.multiple===true && cm[i].editoptions.dataUrl===undefined && $.jgrid.msie) { $(elc).width($(elc).width()); } cnt++; } } }); if(cnt > 0) { svr.id = rowid; $t.p.savedRow.push(svr); $(ind).attr("editable","1"); $("td:eq("+focus+") input",ind).focus(); if(o.keys===true) { $(ind).bind("keydown",function(e) { if (e.keyCode === 27) { $($t).jqGrid("restoreRow",rowid, o.afterrestorefunc); if($t.p._inlinenav) { try { $($t).jqGrid('showAddEditButtons'); } catch (eer1) {} } return false; } if (e.keyCode === 13) { var ta = e.target; if(ta.tagName === 'TEXTAREA') { return true; } if( $($t).jqGrid("saveRow", rowid, o ) ) { if($t.p._inlinenav) { try { $($t).jqGrid('showAddEditButtons'); } catch (eer2) {} } } return false; } }); } $($t).triggerHandler("jqGridInlineEditRow", [rowid, o]); if( $.isFunction(o.oneditfunc)) { o.oneditfunc.call($t, rowid); } } } }); }, saveRow : function(rowid, successfunc, url, extraparam, aftersavefunc,errorfunc, afterrestorefunc) { // Compatible mode old versions var args = $.makeArray(arguments).slice(1), o = {}; if( $.type(args[0]) === "object" ) { o = args[0]; } else { if ($.isFunction(successfunc)) { o.successfunc = successfunc; } if (url !== undefined) { o.url = url; } if (extraparam !== undefined) { o.extraparam = extraparam; } if ($.isFunction(aftersavefunc)) { o.aftersavefunc = aftersavefunc; } if ($.isFunction(errorfunc)) { o.errorfunc = errorfunc; } if ($.isFunction(afterrestorefunc)) { o.afterrestorefunc = afterrestorefunc; } } o = $.extend(true, { successfunc: null, url: null, extraparam: {}, aftersavefunc: null, errorfunc: null, afterrestorefunc: null, restoreAfterError: true, mtype: "POST" }, $.jgrid.inlineEdit, o ); // End compatible var success = false; var $t = this[0], nm, tmp={}, tmp2={}, tmp3= {}, editable, fr, cv, ind; if (!$t.grid ) { return success; } ind = $($t).jqGrid("getInd",rowid,true); if(ind === false) {return success;} editable = $(ind).attr("editable"); o.url = o.url || $t.p.editurl; if (editable==="1") { var cm; $('td[role="gridcell"]',ind).each(function(i) { cm = $t.p.colModel[i]; nm = cm.name; if ( nm !== 'cb' && nm !== 'subgrid' && cm.editable===true && nm !== 'rn' && !$(this).hasClass('not-editable-cell')) { switch (cm.edittype) { case "checkbox": var cbv = ["Yes","No"]; if(cm.editoptions ) { cbv = cm.editoptions.value.split(":"); } tmp[nm]= $("input",this).is(":checked") ? cbv[0] : cbv[1]; break; case 'text': case 'password': case 'textarea': case "button" : tmp[nm]=$("input, textarea",this).val(); break; case 'select': if(!cm.editoptions.multiple) { tmp[nm] = $("select option:selected",this).val(); tmp2[nm] = $("select option:selected", this).text(); } else { var sel = $("select",this), selectedText = []; tmp[nm] = $(sel).val(); if(tmp[nm]) { tmp[nm]= tmp[nm].join(","); } else { tmp[nm] =""; } $("select option:selected",this).each( function(i,selected){ selectedText[i] = $(selected).text(); } ); tmp2[nm] = selectedText.join(","); } if(cm.formatter && cm.formatter === 'select') { tmp2={}; } break; case 'custom' : try { if(cm.editoptions && $.isFunction(cm.editoptions.custom_value)) { tmp[nm] = cm.editoptions.custom_value.call($t, $(".customelement",this),'get'); if (tmp[nm] === undefined) { throw "e2"; } } else { throw "e1"; } } catch (e) { if (e==="e1") { $.jgrid.info_dialog($.jgrid.errors.errcap,"function 'custom_value' "+$.jgrid.edit.msg.nodefined,$.jgrid.edit.bClose); } if (e==="e2") { $.jgrid.info_dialog($.jgrid.errors.errcap,"function 'custom_value' "+$.jgrid.edit.msg.novalue,$.jgrid.edit.bClose); } else { $.jgrid.info_dialog($.jgrid.errors.errcap,e.message,$.jgrid.edit.bClose); } } break; } cv = $.jgrid.checkValues.call($t,tmp[nm],i); if(cv[0] === false) { cv[1] = tmp[nm] + " " + cv[1]; return false; } if($t.p.autoencode) { tmp[nm] = $.jgrid.htmlEncode(tmp[nm]); } if(o.url !== 'clientArray' && cm.editoptions && cm.editoptions.NullIfEmpty === true) { if(tmp[nm] === "") { tmp3[nm] = 'null'; } } } }); if (cv[0] === false){ try { var tr = $t.rows.namedItem(rowid), positions = $.jgrid.findPos(tr); $.jgrid.info_dialog($.jgrid.errors.errcap,cv[1],$.jgrid.edit.bClose,{left:positions[0],top:positions[1]+$(tr).outerHeight()}); } catch (e) { alert(cv[1]); } return success; } var idname, opers = $t.p.prmNames, oldRowId = rowid; if ($t.p.keyIndex === false) { idname = opers.id; } else { idname = $t.p.colModel[$t.p.keyIndex + ($t.p.rownumbers === true ? 1 : 0) + ($t.p.multiselect === true ? 1 : 0) + ($t.p.subGrid === true ? 1 : 0)].name; } if(tmp) { tmp[opers.oper] = opers.editoper; if (tmp[idname] === undefined || tmp[idname]==="") { tmp[idname] = rowid; } else if (ind.id !== $t.p.idPrefix + tmp[idname]) { // rename rowid var oldid = $.jgrid.stripPref($t.p.idPrefix, rowid); if ($t.p._index[oldid] !== undefined) { $t.p._index[tmp[idname]] = $t.p._index[oldid]; delete $t.p._index[oldid]; } rowid = $t.p.idPrefix + tmp[idname]; $(ind).attr("id", rowid); if ($t.p.selrow === oldRowId) { $t.p.selrow = rowid; } if ($.isArray($t.p.selarrrow)) { var i = $.inArray(oldRowId, $t.p.selarrrow); if (i>=0) { $t.p.selarrrow[i] = rowid; } } if ($t.p.multiselect) { var newCboxId = "jqg_" + $t.p.id + "_" + rowid; $("input.cbox",ind) .attr("id", newCboxId) .attr("name", newCboxId); } // TODO: to test the case of frozen columns } if($t.p.inlineData === undefined) { $t.p.inlineData ={}; } tmp = $.extend({},tmp,$t.p.inlineData,o.extraparam); } if (o.url === 'clientArray') { tmp = $.extend({},tmp, tmp2); if($t.p.autoencode) { $.each(tmp,function(n,v){ tmp[n] = $.jgrid.htmlDecode(v); }); } var k, resp = $($t).jqGrid("setRowData",rowid,tmp); $(ind).attr("editable","0"); for(k=0;k<$t.p.savedRow.length;k++) { if( String($t.p.savedRow[k].id) === String(oldRowId)) {fr = k; break;} } if(fr >= 0) { $t.p.savedRow.splice(fr,1); } $($t).triggerHandler("jqGridInlineAfterSaveRow", [rowid, resp, tmp, o]); if( $.isFunction(o.aftersavefunc) ) { o.aftersavefunc.call($t, rowid,resp, o); } success = true; $(ind).removeClass("jqgrid-new-row").unbind("keydown"); } else { $("#lui_"+$.jgrid.jqID($t.p.id)).show(); tmp3 = $.extend({},tmp,tmp3); tmp3[idname] = $.jgrid.stripPref($t.p.idPrefix, tmp3[idname]); $.ajax($.extend({ url:o.url, data: $.isFunction($t.p.serializeRowData) ? $t.p.serializeRowData.call($t, tmp3) : tmp3, type: o.mtype, async : false, //?!? complete: function(res,stat){ $("#lui_"+$.jgrid.jqID($t.p.id)).hide(); if (stat === "success"){ var ret = true, sucret, k; sucret = $($t).triggerHandler("jqGridInlineSuccessSaveRow", [res, rowid, o]); if (!$.isArray(sucret)) {sucret = [true, tmp];} if (sucret[0] && $.isFunction(o.successfunc)) {sucret = o.successfunc.call($t, res);} if($.isArray(sucret)) { // expect array - status, data, rowid ret = sucret[0]; tmp = sucret[1] || tmp; } else { ret = sucret; } if (ret===true) { if($t.p.autoencode) { $.each(tmp,function(n,v){ tmp[n] = $.jgrid.htmlDecode(v); }); } tmp = $.extend({},tmp, tmp2); $($t).jqGrid("setRowData",rowid,tmp); $(ind).attr("editable","0"); for(k=0;k<$t.p.savedRow.length;k++) { if( String($t.p.savedRow[k].id) === String(rowid)) {fr = k; break;} } if(fr >= 0) { $t.p.savedRow.splice(fr,1); } $($t).triggerHandler("jqGridInlineAfterSaveRow", [rowid, res, tmp, o]); if( $.isFunction(o.aftersavefunc) ) { o.aftersavefunc.call($t, rowid,res); } success = true; $(ind).removeClass("jqgrid-new-row").unbind("keydown"); } else { $($t).triggerHandler("jqGridInlineErrorSaveRow", [rowid, res, stat, null, o]); if($.isFunction(o.errorfunc) ) { o.errorfunc.call($t, rowid, res, stat, null); } if(o.restoreAfterError === true) { $($t).jqGrid("restoreRow",rowid, o.afterrestorefunc); } } } }, error:function(res,stat,err){ $("#lui_"+$.jgrid.jqID($t.p.id)).hide(); $($t).triggerHandler("jqGridInlineErrorSaveRow", [rowid, res, stat, err, o]); if($.isFunction(o.errorfunc) ) { o.errorfunc.call($t, rowid, res, stat, err); } else { var rT = res.responseText || res.statusText; try { $.jgrid.info_dialog($.jgrid.errors.errcap,'
'+ rT +'
', $.jgrid.edit.bClose,{buttonalign:'right'}); } catch(e) { alert(rT); } } if(o.restoreAfterError === true) { $($t).jqGrid("restoreRow",rowid, o.afterrestorefunc); } } }, $.jgrid.ajaxOptions, $t.p.ajaxRowOptions || {})); } } return success; }, restoreRow : function(rowid, afterrestorefunc) { // Compatible mode old versions var args = $.makeArray(arguments).slice(1), o={}; if( $.type(args[0]) === "object" ) { o = args[0]; } else { if ($.isFunction(afterrestorefunc)) { o.afterrestorefunc = afterrestorefunc; } } o = $.extend(true, {}, $.jgrid.inlineEdit, o ); // End compatible return this.each(function(){ var $t= this, fr, ind, ares={}, k; if (!$t.grid ) { return; } ind = $($t).jqGrid("getInd",rowid,true); if(ind === false) {return;} for(k=0;k<$t.p.savedRow.length;k++) { if( String($t.p.savedRow[k].id) === String(rowid)) {fr = k; break;} } if(fr >= 0) { if($.isFunction($.fn.datepicker)) { try { $("input.hasDatepicker","#"+$.jgrid.jqID(ind.id)).datepicker('hide'); } catch (e) {} } $.each($t.p.colModel, function(){ if(this.editable === true && $t.p.savedRow[fr].hasOwnProperty(this.name)) { ares[this.name] = $t.p.savedRow[fr][this.name]; } }); $($t).jqGrid("setRowData",rowid,ares); $(ind).attr("editable","0").unbind("keydown"); $t.p.savedRow.splice(fr,1); if($("#"+$.jgrid.jqID(rowid), "#"+$.jgrid.jqID($t.p.id)).hasClass("jqgrid-new-row")){ setTimeout(function(){ $($t).jqGrid("delRowData",rowid); $($t).jqGrid('showAddEditButtons'); },0); } } $($t).triggerHandler("jqGridInlineAfterRestoreRow", [rowid]); if ($.isFunction(o.afterrestorefunc)) { o.afterrestorefunc.call($t, rowid); } }); }, addRow : function ( p ) { p = $.extend(true, { rowID : null, initdata : {}, position :"first", useDefValues : true, useFormatter : false, addRowParams : {extraparam:{}} },p || {}); return this.each(function(){ if (!this.grid ) { return; } var $t = this; p.rowID = $.isFunction(p.rowID) ? p.rowID.call($t, p) : ( (p.rowID != null) ? p.rowID : $.jgrid.randId()); if(p.useDefValues === true) { $($t.p.colModel).each(function(){ if( this.editoptions && this.editoptions.defaultValue ) { var opt = this.editoptions.defaultValue, tmp = $.isFunction(opt) ? opt.call($t) : opt; p.initdata[this.name] = tmp; } }); } $($t).jqGrid('addRowData', p.rowID, p.initdata, p.position); p.rowID = $t.p.idPrefix + p.rowID; $("#"+$.jgrid.jqID(p.rowID), "#"+$.jgrid.jqID($t.p.id)).addClass("jqgrid-new-row"); if(p.useFormatter) { $("#"+$.jgrid.jqID(p.rowID)+" .ui-inline-edit", "#"+$.jgrid.jqID($t.p.id)).click(); } else { var opers = $t.p.prmNames, oper = opers.oper; p.addRowParams.extraparam[oper] = opers.addoper; $($t).jqGrid('editRow', p.rowID, p.addRowParams); $($t).jqGrid('setSelection', p.rowID); } }); }, inlineNav : function (elem, o) { o = $.extend(true,{ edit: true, editicon: "ui-icon-pencil", add: true, addicon:"ui-icon-plus", save: true, saveicon:"ui-icon-disk", cancel: true, cancelicon:"ui-icon-cancel", addParams : {addRowParams: {extraparam: {}}}, editParams : {}, restoreAfterSelect : true }, $.jgrid.nav, o ||{}); return this.each(function(){ if (!this.grid ) { return; } var $t = this, onSelect, gID = $.jgrid.jqID($t.p.id); $t.p._inlinenav = true; // detect the formatactions column if(o.addParams.useFormatter === true) { var cm = $t.p.colModel,i; for (i = 0; i 0 && $t.p._inlinenav===true && ( id !== $t.p.selrow && $t.p.selrow !==null) ) { if($t.p.selrow === o.addParams.rowID ) { $($t).jqGrid('delRowData', $t.p.selrow); } else { $($t).jqGrid('restoreRow', $t.p.selrow, o.editParams); } $($t).jqGrid('showAddEditButtons'); } if(onSelect) { ret = onSelect.call($t, id, stat); } return ret; }; } }); }, showAddEditButtons : function() { return this.each(function(){ if (!this.grid ) { return; } var gID = $.jgrid.jqID(this.p.id); $("#"+gID+"_ilsave").addClass('ui-state-disabled'); $("#"+gID+"_ilcancel").addClass('ui-state-disabled'); $("#"+gID+"_iladd").removeClass('ui-state-disabled'); $("#"+gID+"_iledit").removeClass('ui-state-disabled'); }); } //end inline edit }); })(jQuery); /*jshint eqeqeq:false */ /*global 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.call($t,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"); $.jgrid.bindEv.call($t, elc, opt); 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($.jgrid.errors.errcap,"function 'custom_value' "+$.jgrid.edit.msg.nodefined,$.jgrid.edit.bClose); } if (e==="e2") { $.jgrid.info_dialog($.jgrid.errors.errcap,"function 'custom_value' "+$.jgrid.edit.msg.novalue,$.jgrid.edit.bClose); } else {$.jgrid.info_dialog($.jgrid.errors.errcap,e.message,$.jgrid.edit.bClose); } } break; } // 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.call($t,v,iCol); 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); } } 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, i; if (!$t.grid || $t.p.cellEdit !== true) {return;} // try to find next editable cell for (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, i; if (!$t.grid || $t.p.cellEdit !== true) {return;} // try to find next editable cell for (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); /*jshint eqeqeq:false */ /*global jQuery */ (function($){ /** * jqGrid extension for SubGrid Data * Tony Tomov tony@trirand.com * http://trirand.com/blog/ * Dual licensed under the MIT and GPL licenses: * http://www.opensource.org/licenses/mit-license.php * http://www.gnu.org/licenses/gpl-2.0.html **/ "use strict"; $.jgrid.extend({ setSubGrid : function () { return this.each(function (){ var $t = this, cm, i, suboptions = { plusicon : "ui-icon-plus", minusicon : "ui-icon-minus", openicon: "ui-icon-carat-1-sw", expandOnLoad: false, delayOnLoad : 50, selectOnExpand : false, reloadOnExpand : true }; $t.p.subGridOptions = $.extend(suboptions, $t.p.subGridOptions || {}); $t.p.colNames.unshift(""); $t.p.colModel.unshift({name:'subgrid',width: $.jgrid.cell_width ? $t.p.subGridWidth+$t.p.cellLayout : $t.p.subGridWidth,sortable: false,resizable:false,hidedlg:true,search:false,fixed:true}); cm = $t.p.subGridModel; if(cm[0]) { cm[0].align = $.extend([],cm[0].align || []); for(i=0;i"; }, addSubGrid : function( pos, sind ) { return this.each(function(){ var ts = this; if (!ts.grid ) { return; } //------------------------- var subGridCell = function(trdiv,cell,pos) { var tddiv = $("").html(cell); $(trdiv).append(tddiv); }; var subGridXml = function(sjxml, sbid){ var tddiv, i, sgmap, dummy = $("
"), trdiv = $(""); for (i = 0; i"); $(tddiv).html(ts.p.subGridModel[0].name[i]); $(tddiv).width( ts.p.subGridModel[0].width[i]); $(trdiv).append(tddiv); } $(dummy).append(trdiv); if (sjxml){ sgmap = ts.p.xmlReader.subgrid; $(sgmap.root+" "+sgmap.row, sjxml).each( function(){ trdiv = $(""); if(sgmap.repeatitems === true) { $(sgmap.cell,this).each( function(i) { subGridCell(trdiv, $(this).text() || ' ',i); }); } else { var f = ts.p.subGridModel[0].mapping || ts.p.subGridModel[0].name; if (f) { for (i=0;i"), trdiv = $(""); for (i = 0; i"); $(tddiv).html(ts.p.subGridModel[0].name[i]); $(tddiv).width( ts.p.subGridModel[0].width[i]); $(trdiv).append(tddiv); } $(dummy).append(trdiv); if (sjxml){ sgmap = ts.p.jsonReader.subgrid; result = $.jgrid.getAccessor(sjxml, sgmap.root); if ( result !== undefined ) { for (i=0;i"); if(sgmap.repeatitems === true) { if(sgmap.cell) { cur=cur[sgmap.cell]; } for (j=0;j 0) { i = sind; len = sind+1; } while(i < len) { if($(ts.rows[i]).hasClass('jqgrow')) { $(ts.rows[i].cells[pos]).bind('click', function() { var tr = $(this).parent("tr")[0]; r = tr.nextSibling; if($(this).hasClass("sgcollapsed")) { pID = ts.p.id; _id = tr.id; if(ts.p.subGridOptions.reloadOnExpand === true || ( ts.p.subGridOptions.reloadOnExpand === false && !$(r).hasClass('ui-subgrid') ) ) { atd = pos >=1 ? " ":""; bfsc = $(ts).triggerHandler("jqGridSubGridBeforeExpand", [pID + "_" + _id, _id]); bfsc = (bfsc === false || bfsc === 'stop') ? false : true; if(bfsc && $.isFunction(ts.p.subGridBeforeExpand)) { bfsc = ts.p.subGridBeforeExpand.call(ts, pID+"_"+_id,_id); } if(bfsc === false) {return false;} $(tr).after( ""+atd+"
" ); $(ts).triggerHandler("jqGridSubGridRowExpanded", [pID + "_" + _id, _id]); if( $.isFunction(ts.p.subGridRowExpanded)) { ts.p.subGridRowExpanded.call(ts, pID+"_"+ _id,_id); } else { populatesubgrid(tr); } } else { $(r).show(); } $(this).html("").removeClass("sgcollapsed").addClass("sgexpanded"); if(ts.p.subGridOptions.selectOnExpand) { $(ts).jqGrid('setSelection',_id); } } else if($(this).hasClass("sgexpanded")) { bfsc = $(ts).triggerHandler("jqGridSubGridRowColapsed", [pID + "_" + _id, _id]); bfsc = (bfsc === false || bfsc === 'stop') ? false : true; if( bfsc && $.isFunction(ts.p.subGridRowColapsed)) { _id = tr.id; bfsc = ts.p.subGridRowColapsed.call(ts, pID+"_"+_id,_id ); } if(bfsc===false) {return false;} if(ts.p.subGridOptions.reloadOnExpand === true) { $(r).remove(".ui-subgrid"); } else if($(r).hasClass('ui-subgrid')) { // incase of dynamic deleting $(r).hide(); } $(this).html("").removeClass("sgexpanded").addClass("sgcollapsed"); } return false; }); } i++; } if(ts.p.subGridOptions.expandOnLoad === true) { $(ts.rows).filter('.jqgrow').each(function(index,row){ $(row.cells[0]).click(); }); } ts.subGridXml = function(xml,sid) {subGridXml(xml,sid);}; ts.subGridJson = function(json,sid) {subGridJson(json,sid);}; }); }, expandSubGridRow : function(rowid) { return this.each(function () { var $t = this; if(!$t.grid && !rowid) {return;} if($t.p.subGrid===true) { var rc = $(this).jqGrid("getInd",rowid,true); if(rc) { var sgc = $("td.sgcollapsed",rc)[0]; if(sgc) { $(sgc).trigger("click"); } } } }); }, collapseSubGridRow : function(rowid) { return this.each(function () { var $t = this; if(!$t.grid && !rowid) {return;} if($t.p.subGrid===true) { var rc = $(this).jqGrid("getInd",rowid,true); if(rc) { var sgc = $("td.sgexpanded",rc)[0]; if(sgc) { $(sgc).trigger("click"); } } } }); }, toggleSubGridRow : function(rowid) { return this.each(function () { var $t = this; if(!$t.grid && !rowid) {return;} if($t.p.subGrid===true) { var rc = $(this).jqGrid("getInd",rowid,true); if(rc) { var sgc = $("td.sgcollapsed",rc)[0]; if(sgc) { $(sgc).trigger("click"); } else { sgc = $("td.sgexpanded",rc)[0]; if(sgc) { $(sgc).trigger("click"); } } } } }); } }); })(jQuery); /** * jqGrid extension - Tree Grid * 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.html **/ /*jshint eqeqeq:false */ /*global jQuery */ (function($) { "use strict"; $.jgrid.extend({ setTreeNode : function(i, len){ return this.each(function(){ var $t = this; if( !$t.grid || !$t.p.treeGrid ) {return;} var expCol = $t.p.expColInd, expanded = $t.p.treeReader.expanded_field, isLeaf = $t.p.treeReader.leaf_field, level = $t.p.treeReader.level_field, icon = $t.p.treeReader.icon_field, loaded = $t.p.treeReader.loaded, lft, rgt, curLevel, ident,lftpos, twrap, ldat, lf; while(i"; twrap += "
").prepend(twrap); if(curLevel !== parseInt($t.p.tree_root_level,10)) { var pn = $($t).jqGrid('getNodeParent',ldat); expan = pn && pn.hasOwnProperty(expanded) ? pn[expanded] : true; if( !expan ){ $($t.rows[i]).css("display","none"); } } $($t.rows[i].cells[expCol]) .find("div.treeclick") .bind("click",function(e){ var target = e.target || e.srcElement, ind2 =$.jgrid.stripPref($t.p.idPrefix,$(target,$t.rows).closest("tr.jqgrow")[0].id), pos = $t.p._index[ind2]; if(!$t.p.data[pos][isLeaf]){ if($t.p.data[pos][expanded]){ $($t).jqGrid("collapseRow",$t.p.data[pos]); $($t).jqGrid("collapseNode",$t.p.data[pos]); } else { $($t).jqGrid("expandRow",$t.p.data[pos]); $($t).jqGrid("expandNode",$t.p.data[pos]); } } return false; }); if($t.p.ExpandColClick === true) { $($t.rows[i].cells[expCol]) .find("span.cell-wrapper") .css("cursor","pointer") .bind("click",function(e) { var target = e.target || e.srcElement, ind2 =$.jgrid.stripPref($t.p.idPrefix,$(target,$t.rows).closest("tr.jqgrow")[0].id), pos = $t.p._index[ind2]; if(!$t.p.data[pos][isLeaf]){ if($t.p.data[pos][expanded]){ $($t).jqGrid("collapseRow",$t.p.data[pos]); $($t).jqGrid("collapseNode",$t.p.data[pos]); } else { $($t).jqGrid("expandRow",$t.p.data[pos]); $($t).jqGrid("expandNode",$t.p.data[pos]); } } $($t).jqGrid("setSelection",ind2); return false; }); } i++; } }); }, setTreeGrid : function() { return this.each(function (){ var $t = this, i=0, pico, ecol = false, nm, key, tkey, dupcols=[]; if(!$t.p.treeGrid) {return;} if(!$t.p.treedatatype ) {$.extend($t.p,{treedatatype: $t.p.datatype});} $t.p.subGrid = false;$t.p.altRows =false; $t.p.pgbuttons = false;$t.p.pginput = false; $t.p.gridview = true; if($t.p.rowTotal === null ) { $t.p.rowNum = 10000; } $t.p.multiselect = false;$t.p.rowList = []; $t.p.expColInd = 0; pico = 'ui-icon-triangle-1-' + ($t.p.direction==="rtl" ? 'w' : 'e'); $t.p.treeIcons = $.extend({plus:pico,minus:'ui-icon-triangle-1-s',leaf:'ui-icon-radio-off'},$t.p.treeIcons || {}); if($t.p.treeGridModel === 'nested') { $t.p.treeReader = $.extend({ level_field: "level", left_field:"lft", right_field: "rgt", leaf_field: "isLeaf", expanded_field: "expanded", loaded: "loaded", icon_field: "icon" },$t.p.treeReader); } else if($t.p.treeGridModel === 'adjacency') { $t.p.treeReader = $.extend({ level_field: "level", parent_id_field: "parent", leaf_field: "isLeaf", expanded_field: "expanded", loaded: "loaded", icon_field: "icon" },$t.p.treeReader ); } for ( key in $t.p.colModel){ if($t.p.colModel.hasOwnProperty(key)) { nm = $t.p.colModel[key].name; if( nm === $t.p.ExpandColumn && !ecol ) { ecol = true; $t.p.expColInd = i; } i++; // for(tkey in $t.p.treeReader) { if($t.p.treeReader.hasOwnProperty(tkey) && $t.p.treeReader[tkey] === nm) { dupcols.push(nm); } } } } $.each($t.p.treeReader,function(j,n){ if(n && $.inArray(n, dupcols) === -1){ if(j==='leaf_field') { $t.p._treeleafpos= i; } i++; $t.p.colNames.push(n); $t.p.colModel.push({name:n,width:1,hidden:true,sortable:false,resizable:false,hidedlg:true,editable:true,search:false}); } }); }); }, expandRow: function (record){ this.each(function(){ var $t = this; if(!$t.grid || !$t.p.treeGrid) {return;} var childern = $($t).jqGrid("getNodeChildren",record), //if ($($t).jqGrid("isVisibleNode",record)) { expanded = $t.p.treeReader.expanded_field, rows = $t.rows; $(childern).each(function(){ var id = $t.p.idPrefix + $.jgrid.getAccessor(this,$t.p.localReader.id); $(rows.namedItem(id)).css("display",""); if(this[expanded]) { $($t).jqGrid("expandRow",this); } }); //} }); }, collapseRow : function (record) { this.each(function(){ var $t = this; if(!$t.grid || !$t.p.treeGrid) {return;} var childern = $($t).jqGrid("getNodeChildren",record), expanded = $t.p.treeReader.expanded_field, rows = $t.rows; $(childern).each(function(){ var id = $t.p.idPrefix + $.jgrid.getAccessor(this,$t.p.localReader.id); $(rows.namedItem(id)).css("display","none"); if(this[expanded]){ $($t).jqGrid("collapseRow",this); } }); }); }, // NS ,adjacency models getRootNodes : function() { var result = []; this.each(function(){ var $t = this; if(!$t.grid || !$t.p.treeGrid) {return;} switch ($t.p.treeGridModel) { case 'nested' : var level = $t.p.treeReader.level_field; $($t.p.data).each(function(){ if(parseInt(this[level],10) === parseInt($t.p.tree_root_level,10)) { result.push(this); } }); break; case 'adjacency' : var parent_id = $t.p.treeReader.parent_id_field; $($t.p.data).each(function(){ if(this[parent_id] === null || String(this[parent_id]).toLowerCase() === "null") { result.push(this); } }); break; } }); return result; }, getNodeDepth : function(rc) { var ret = null; this.each(function(){ if(!this.grid || !this.p.treeGrid) {return;} var $t = this; switch ($t.p.treeGridModel) { case 'nested' : var level = $t.p.treeReader.level_field; ret = parseInt(rc[level],10) - parseInt($t.p.tree_root_level,10); break; case 'adjacency' : ret = $($t).jqGrid("getNodeAncestors",rc).length; break; } }); return ret; }, getNodeParent : function(rc) { var result = null; this.each(function(){ var $t = this; if(!$t.grid || !$t.p.treeGrid) {return;} switch ($t.p.treeGridModel) { case 'nested' : var lftc = $t.p.treeReader.left_field, rgtc = $t.p.treeReader.right_field, levelc = $t.p.treeReader.level_field, lft = parseInt(rc[lftc],10), rgt = parseInt(rc[rgtc],10), level = parseInt(rc[levelc],10); $(this.p.data).each(function(){ if(parseInt(this[levelc],10) === level-1 && parseInt(this[lftc],10) < lft && parseInt(this[rgtc],10) > rgt) { result = this; return false; } }); break; case 'adjacency' : var parent_id = $t.p.treeReader.parent_id_field, dtid = $t.p.localReader.id; $(this.p.data).each(function(){ if(this[dtid] === $.jgrid.stripPref($t.p.idPrefix, rc[parent_id]) ) { result = this; return false; } }); break; } }); return result; }, getNodeChildren : function(rc) { var result = []; this.each(function(){ var $t = this; if(!$t.grid || !$t.p.treeGrid) {return;} switch ($t.p.treeGridModel) { case 'nested' : var lftc = $t.p.treeReader.left_field, rgtc = $t.p.treeReader.right_field, levelc = $t.p.treeReader.level_field, lft = parseInt(rc[lftc],10), rgt = parseInt(rc[rgtc],10), level = parseInt(rc[levelc],10); $(this.p.data).each(function(){ if(parseInt(this[levelc],10) === level+1 && parseInt(this[lftc],10) > lft && parseInt(this[rgtc],10) < rgt) { result.push(this); } }); break; case 'adjacency' : var parent_id = $t.p.treeReader.parent_id_field, dtid = $t.p.localReader.id; $(this.p.data).each(function(){ if(this[parent_id] == $.jgrid.stripPref($t.p.idPrefix, rc[dtid])) { result.push(this); } }); break; } }); return result; }, getFullTreeNode : function(rc) { var result = []; this.each(function(){ var $t = this, len; if(!$t.grid || !$t.p.treeGrid) {return;} switch ($t.p.treeGridModel) { case 'nested' : var lftc = $t.p.treeReader.left_field, rgtc = $t.p.treeReader.right_field, levelc = $t.p.treeReader.level_field, lft = parseInt(rc[lftc],10), rgt = parseInt(rc[rgtc],10), level = parseInt(rc[levelc],10); $(this.p.data).each(function(){ if(parseInt(this[levelc],10) >= level && parseInt(this[lftc],10) >= lft && parseInt(this[lftc],10) <= rgt) { result.push(this); } }); break; case 'adjacency' : if(rc) { result.push(rc); var parent_id = $t.p.treeReader.parent_id_field, dtid = $t.p.localReader.id; $(this.p.data).each(function(i){ len = result.length; for (i = 0; i < len; i++) { if ($.jgrid.stripPref($t.p.idPrefix, result[i][dtid]) === this[parent_id]) { result.push(this); break; } } }); } break; } }); return result; }, // End NS, adjacency Model getNodeAncestors : function(rc) { var ancestors = []; this.each(function(){ if(!this.grid || !this.p.treeGrid) {return;} var parent = $(this).jqGrid("getNodeParent",rc); while (parent) { ancestors.push(parent); parent = $(this).jqGrid("getNodeParent",parent); } }); return ancestors; }, isVisibleNode : function(rc) { var result = true; this.each(function(){ var $t = this; if(!$t.grid || !$t.p.treeGrid) {return;} var ancestors = $($t).jqGrid("getNodeAncestors",rc), expanded = $t.p.treeReader.expanded_field; $(ancestors).each(function(){ result = result && this[expanded]; if(!result) {return false;} }); }); return result; }, isNodeLoaded : function(rc) { var result; this.each(function(){ var $t = this; if(!$t.grid || !$t.p.treeGrid) {return;} var isLeaf = $t.p.treeReader.leaf_field; if(rc !== undefined ) { if(rc.loaded !== undefined) { result = rc.loaded; } else if( rc[isLeaf] || $($t).jqGrid("getNodeChildren",rc).length > 0){ result = true; } else { result = false; } } else { result = false; } }); return result; }, expandNode : function(rc) { return this.each(function(){ if(!this.grid || !this.p.treeGrid) {return;} var expanded = this.p.treeReader.expanded_field, parent = this.p.treeReader.parent_id_field, loaded = this.p.treeReader.loaded, level = this.p.treeReader.level_field, lft = this.p.treeReader.left_field, rgt = this.p.treeReader.right_field; if(!rc[expanded]) { var id = $.jgrid.getAccessor(rc,this.p.localReader.id); var rc1 = $("#" + this.p.idPrefix + $.jgrid.jqID(id),this.grid.bDiv)[0]; var position = this.p._index[id]; if( $(this).jqGrid("isNodeLoaded",this.p.data[position]) ) { rc[expanded] = true; $("div.treeclick",rc1).removeClass(this.p.treeIcons.plus+" tree-plus").addClass(this.p.treeIcons.minus+" tree-minus"); } else if (!this.grid.hDiv.loading) { rc[expanded] = true; $("div.treeclick",rc1).removeClass(this.p.treeIcons.plus+" tree-plus").addClass(this.p.treeIcons.minus+" tree-minus"); this.p.treeANode = rc1.rowIndex; this.p.datatype = this.p.treedatatype; if(this.p.treeGridModel === 'nested') { $(this).jqGrid("setGridParam",{postData:{nodeid:id,n_left:rc[lft],n_right:rc[rgt],n_level:rc[level]}}); } else { $(this).jqGrid("setGridParam",{postData:{nodeid:id,parentid:rc[parent],n_level:rc[level]}} ); } $(this).trigger("reloadGrid"); rc[loaded] = true; if(this.p.treeGridModel === 'nested') { $(this).jqGrid("setGridParam",{postData:{nodeid:'',n_left:'',n_right:'',n_level:''}}); } else { $(this).jqGrid("setGridParam",{postData:{nodeid:'',parentid:'',n_level:''}}); } } } }); }, collapseNode : function(rc) { return this.each(function(){ if(!this.grid || !this.p.treeGrid) {return;} var expanded = this.p.treeReader.expanded_field; if(rc[expanded]) { rc[expanded] = false; var id = $.jgrid.getAccessor(rc,this.p.localReader.id); var rc1 = $("#" + this.p.idPrefix + $.jgrid.jqID(id),this.grid.bDiv)[0]; $("div.treeclick",rc1).removeClass(this.p.treeIcons.minus+" tree-minus").addClass(this.p.treeIcons.plus+" tree-plus"); } }); }, SortTree : function( sortname, newDir, st, datefmt) { return this.each(function(){ if(!this.grid || !this.p.treeGrid) {return;} var i, len, rec, records = [], $t = this, query, roots, rt = $(this).jqGrid("getRootNodes"); // Sorting roots query = $.jgrid.from(rt); query.orderBy(sortname,newDir,st, datefmt); roots = query.select(); // Sorting children for (i = 0, len = roots.length; i < len; i++) { rec = roots[i]; records.push(rec); $(this).jqGrid("collectChildrenSortTree",records, rec, sortname, newDir,st, datefmt); } $.each(records, function(index) { var id = $.jgrid.getAccessor(this,$t.p.localReader.id); $('#'+$.jgrid.jqID($t.p.id)+ ' tbody tr:eq('+index+')').after($('tr#'+$.jgrid.jqID(id),$t.grid.bDiv)); }); query = null;roots=null;records=null; }); }, collectChildrenSortTree : function(records, rec, sortname, newDir,st, datefmt) { return this.each(function(){ if(!this.grid || !this.p.treeGrid) {return;} var i, len, child, ch, query, children; ch = $(this).jqGrid("getNodeChildren",rec); query = $.jgrid.from(ch); query.orderBy(sortname, newDir, st, datefmt); children = query.select(); for (i = 0, len = children.length; i < len; i++) { child = children[i]; records.push(child); $(this).jqGrid("collectChildrenSortTree",records, child, sortname, newDir, st, datefmt); } }); }, // experimental setTreeRow : function(rowid, data) { var success=false; this.each(function(){ var t = this; if(!t.grid || !t.p.treeGrid) {return;} success = $(t).jqGrid("setRowData",rowid,data); }); return success; }, delTreeNode : function (rowid) { return this.each(function () { var $t = this, rid = $t.p.localReader.id, i, left = $t.p.treeReader.left_field, right = $t.p.treeReader.right_field, myright, width, res, key; if(!$t.grid || !$t.p.treeGrid) {return;} var rc = $t.p._index[rowid]; if (rc !== undefined) { // nested myright = parseInt($t.p.data[rc][right],10); width = myright - parseInt($t.p.data[rc][left],10) + 1; var dr = $($t).jqGrid("getFullTreeNode",$t.p.data[rc]); if(dr.length>0){ for (i=0;i= 0 ) { while(i>=0){max = Math.max(max, parseInt($t.p.data[i][$t.p.localReader.id],10)); i--;} } nodeid = max+1; } var prow = $($t).jqGrid('getInd', parentid); leaf = false; // if not a parent we assume root if ( parentid === undefined || parentid === null || parentid==="") { parentid = null; rowind = null; method = 'last'; parentlevel = $t.p.tree_root_level; i = $t.p.data.length+1; } else { method = 'after'; parentindex = $t.p._index[parentid]; parentdata = $t.p.data[parentindex]; parentid = parentdata[$t.p.localReader.id]; parentlevel = parseInt(parentdata[level],10)+1; var childs = $($t).jqGrid('getFullTreeNode', parentdata); // if there are child nodes get the last index of it if(childs.length) { i = childs[childs.length-1][$t.p.localReader.id]; rowind = i; i = $($t).jqGrid('getInd',rowind)+1; } else { i = $($t).jqGrid('getInd', parentid)+1; } // if the node is leaf if(parentdata[isLeaf]) { leaf = true; parentdata[expanded] = true; //var prow = $($t).jqGrid('getInd', parentid); $($t.rows[prow]) .find("span.cell-wrapperleaf").removeClass("cell-wrapperleaf").addClass("cell-wrapper") .end() .find("div.tree-leaf").removeClass($t.p.treeIcons.leaf+" tree-leaf").addClass($t.p.treeIcons.minus+" tree-minus"); $t.p.data[parentindex][isLeaf] = false; parentdata[loaded] = true; } } len = i+1; if( data[expanded]===undefined) {data[expanded]= false;} if( data[loaded]===undefined ) { data[loaded] = false;} data[level] = parentlevel; if( data[isLeaf]===undefined) {data[isLeaf]= true;} if( $t.p.treeGridModel === "adjacency") { data[parent] = parentid; } if( $t.p.treeGridModel === "nested") { // this method requiere more attention var query, res, key; //maxright = parseInt(maxright,10); // ToDo - update grid data if(parentid !== null) { maxright = parseInt(parentdata[right],10); query = $.jgrid.from($t.p.data); query = query.greaterOrEquals(right,maxright,{stype:'integer'}); res = query.select(); if(res.length) { for( key in res) { if(res.hasOwnProperty(key)) { res[key][left] = res[key][left] > maxright ? parseInt(res[key][left],10) +2 : res[key][left]; res[key][right] = res[key][right] >= maxright ? parseInt(res[key][right],10) +2 : res[key][right]; } } } data[left] = maxright; data[right]= maxright+1; } else { maxright = parseInt( $($t).jqGrid('getCol', right, false, 'max'), 10); res = $.jgrid.from($t.p.data) .greater(left,maxright,{stype:'integer'}) .select(); if(res.length) { for( key in res) { if(res.hasOwnProperty(key)) { res[key][left] = parseInt(res[key][left],10) +2 ; } } } res = $.jgrid.from($t.p.data) .greater(right,maxright,{stype:'integer'}) .select(); if(res.length) { for( key in res) { if(res.hasOwnProperty(key)) { res[key][right] = parseInt(res[key][right],10) +2 ; } } } data[left] = maxright+1; data[right] = maxright + 2; } } if( parentid === null || $($t).jqGrid("isNodeLoaded",parentdata) || leaf ) { $($t).jqGrid('addRowData', nodeid, data, method, rowind); $($t).jqGrid('setTreeNode', i, len); } if(parentdata && !parentdata[expanded] && expandData) { $($t.rows[prow]) .find("div.treeclick") .click(); } } //}); } }); })(jQuery); /*jshint eqeqeq:false, eqnull:true */ /*global jQuery */ // Grouping module (function($){ "use strict"; $.extend($.jgrid,{ template : function(format){ //jqgformat var args = $.makeArray(arguments).slice(1), j, al = args.length; if(format==null) { format = ""; } return format.replace(/\{([\w\-]+)(?:\:([\w\.]*)(?:\((.*?)?\))?)?\}/g, function(m,i){ if(!isNaN(parseInt(i,10))) { return args[parseInt(i,10)]; } for(j=0; j < al;j++) { if($.isArray(args[j])) { var nmarr = args[ j ], k = nmarr.length; while(k--) { if(i===nmarr[k].nm) { return nmarr[k].v; } } } } }); } }); $.jgrid.extend({ groupingSetup : function () { return this.each(function (){ var $t = this, i, j, cml, cm = $t.p.colModel, grp = $t.p.groupingView; if(grp !== null && ( (typeof grp === 'object') || $.isFunction(grp) ) ) { if(!grp.groupField.length) { $t.p.grouping = false; } else { if (grp.visibiltyOnNextGrouping === undefined) { grp.visibiltyOnNextGrouping = []; } grp.lastvalues=[]; grp.groups =[]; grp.counters =[]; for(i=0;i= 0; i--) { if(grp[i].idx === id-offset) { ret = grp[i]; break; } } } } return ret; } var sumreverse = $.makeArray(grp.groupSummary); sumreverse.reverse(); $.each(grp.groups,function(i,n){ toEnd++; clid = $t.p.id+"ghead_"+n.idx; hid = clid+"_"+i; icon = ""; try { if ($.isArray(grp.formatDisplayField) && $.isFunction(grp.formatDisplayField[n.idx])) { n.displayValue = grp.formatDisplayField[n.idx].call($t, n.displayValue, n.value, $t.p.colModel[cp[n.idx]], n.idx, grp); } gv = $t.formatter(hid, n.displayValue, cp[n.idx], n.value ); } catch (egv) { gv = n.displayValue; } str += ""+icon+$.jgrid.template(grp.groupText[n.idx], gv, n.cnt, n.summary)+""; var leaf = len-1 === n.idx; if( leaf ) { var gg = grp.groups[i+1], k, kk, ik; var end = gg !== undefined ? grp.groups[i+1].startRow : grdata.length; for(kk=n.startRow;kk"; var fdata = findGroupIdx(i, ik, grp.groups), cm = $t.p.colModel, vv, grlen = fdata.cnt; for(k=0; k ", tplfld = "{0}"; $.each(fdata.summary,function(){ if(this.nm === cm[k].name) { if(cm[k].summaryTpl) { tplfld = cm[k].summaryTpl; } if(typeof this.st === 'string' && this.st.toLowerCase() === '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 += ""; } toEnd = jj; } }); $("#"+$.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 (grp.visibiltyOnNextGrouping === undefined) { grp.visibiltyOnNextGrouping = []; } var i; // show previous hidden groups if they are hidden and weren't removed yet for(i=0;i