public.component.assets.js.jqGrid.jquery.jqGrid.js Maven / Gradle / Ivy
// ==ClosureCompiler==
// @compilation_level SIMPLE_OPTIMIZATIONS
/**
* @license Guriddo jqGrid JS 4.7.1 (2014-12-16)
* Copyright (c) 2008, Tony Tomov, [email protected]
*
* License: http://guriddo.net/?page_id=103334
*/
//jsHint options
/*jshint evil:true, eqeqeq:false, eqnull:true, devel:true */
/*global jQuery */
(function ($) {
"use strict";
$.jgrid = $.jgrid || {};
$.extend($.jgrid,{
version : "4.7.1",
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;
},
offset =0;
if(opts === undefined) {
opts = $.jgrid.formatter.date;
}
// old lang files
if(opts.parseRe === undefined ) {
opts.parseRe = /[#%\\\/:_;.,\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]) {
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 {
//Support ISO8601Long that have Z at the end to indicate UTC timezone
if(opts.srcformat === 'ISO8601Long' && date.charAt(date.length - 1) === 'Z') {
offset -= (new Date()).getTimezoneOffset();
}
date = String(date).replace(/\T/g,"#").replace(/\t/,"%").split(opts.parseRe);
format = format.replace(/\T/g,"#").replace(/\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);
//Apply offset to show date as local time.
if(offset > 0) {
timestamp.setTime(Number(Number(timestamp) + (offset * 60 * 1000)));
}
}
} else {
timestamp = new Date(ts.y, ts.m, ts.d, ts.h, ts.i, ts.s, ts.u);
}
if(opts.userLocalTime && offset === 0) {
offset -= (new Date()).getTimezoneOffset();
if( offset > 0 ) {
timestamp.setTime(Number(Number(timestamp) + (offset * 60 * 1000)));
}
}
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 Math.abs(testCell-5) > 0.1;
},
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,
sfunc = _sorting[q].sfunc;
if(q===_sorting.length-1){
return self._getOrder(d, by, dir, type, dfmt, sfunc);
}
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{
if (v!=null) { 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, sfunc){
dir = dir == null ? "a" :$.trim(dir.toString().toLowerCase());
if(stype == null) { stype = "text"; }
if(dfmt == null) { dfmt = "Y-m-d"; }
if(sfunc == null) { sfunc = false; }
if(dir==="desc"||dir==="descending"){dir="d";}
if(dir==="asc"||dir==="ascending"){dir="a";}
_sorting.push({by:by,dir:dir,type:stype, datefmt: dfmt, sfunc: sfunc});
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 localData;
if (pin != null && pin.data !== undefined) {
localData = pin.data;
pin.data = [];
}
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: [], groupSummaryPos:[], formatDisplayField : [], _locgr : false},
ignoreCase : false,
cmTemplate : {},
idPrefix : "",
multiSort : false,
minColWidth : 33
}, $.jgrid.defaults, pin || {});
if (localData !== undefined) {
p.data = localData;
pin.data = localData;
}
var ts= this, grid={
headers:[],
cols:[],
footers: [],
dragStart: function(i,x,y) {
var gridLeftPos = $(this.bDiv).offset().left;
this.resizing = { idx: i, startX: x.pageX, sOL : x.pageX - gridLeftPos };
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:x.pageX-gridLeftPos,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.pageX-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 > p.minColWidth ) {
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) || 0) <= p.lastpage))
{
npage = parseInt((dh - tbot + div - 1) / div,10) || 1;
if (tbot >= 0 || npage < 2 || p.scroll === true) {
page = ( Math.round((tbot + scrollTop) / div) || 0) + 1;
ttop = -1;
} else {
ttop = 1;
}
}
if (ttop > 0) {
page = ( parseInt(scrollTop / div,10) || 0 ) + 1;
npage = (parseInt((scrollTop + dh) / div,10) || 0) + 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
"+this.p.loadtext+"
").insertBefore(gv);
$(this).attr({cellspacing:"0",cellpadding:"0",border:"0","role":"presentation","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], cellAttrFunc,
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 ($.isFunction(cm.cellattr) || (typeof cm.cellattr === "string" && $.jgrid.cellattr != null && $.isFunction($.jgrid.cellattr[cm.cellattr]))) {
cellAttrFunc = $.isFunction(cm.cellattr) ? cm.cellattr : $.jgrid.cellattr[cm.cellattr];
celp = cellAttrFunc.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.replace(/\-style/g,'-sti').split(/style/);
if(acp.length === 2 ) {
acp[1] = $.trim(acp[1].replace(/\-sti/g,'-style').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 ""+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 += ""; 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 && ts.p.sortname !== "") {$("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( ts.p.id.length + 1 ); $(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 += " |
"+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($){
"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 :'', removemodal: false, formprop: false, form : ''}, o || {});
var thisgrid = o.gb && typeof o.gb === "string" && o.gb.substr(0,6) === "#gbox_" ? $("#" + o.gb.substr(6))[0] : false;
if(o.onClose) {
var oncret = thisgrid ? o.onClose.call(thisgrid, selector) : o.onClose(selector);
if (typeof oncret === 'boolean' && !oncret ) { return; }
}
if( o.formprop && thisgrid && o.form) {
var fh = $(selector)[0].style.height;
if(fh.indexOf("px") > -1 ) {
fh = parseFloat(fh);
}
var frmgr, frmdata;
if(o.form==='edit'){
frmgr = '#' +$.jgrid.jqID("FrmGrid_"+ o.gb.substr(6));
frmdata = "formProp";
} else if( o.form === 'view') {
frmgr = '#' +$.jgrid.jqID("ViewGrid_"+ o.gb.substr(6));
frmdata = "viewProp";
}
$(thisgrid).data(frmdata, {
top:parseFloat($(selector).css("top")),
left : parseFloat($(selector).css("left")),
width : $(selector).width(),
height : fh,
dataheight : $(frmgr).height(),
datawidth: $(frmgr).width()
});
}
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");
}
if( o.removemodal ) {
$(selector).remove();
}
},
//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, removemodal: p.removemodal || false, formprop : !p.recreateForm || false, form: p.form || ''});
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, removemodal: p.removemodal || false, formprop : !p.recreateForm || false, form: p.form || ''});
}
});
}
},
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
";
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,opt);
}
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 = null, postData = options.postData || ajaxso.postData;
try {
rowid = options.rowId;
} catch(e) {}
if ($t.p && $t.p.idPrefix) {
rowid = $.jgrid.stripPref($t.p.idPrefix, rowid);
}
$.ajax($.extend({
url: $.isFunction(options.dataUrl) ? options.dataUrl.call($t, rowid, vl, String(options.name)) : 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, postData ? ['postData'] : undefined );
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"+content+"
";
cnt += c_b ? " " :
buttstr !== "" ? " " : "";
cnt += "").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+" |
"+(rtlb ? bN+bP : bP+bN)+" | "+bS+bC+" |
"+(rtlb ? bN+bP : bP+bN)+" | "+bC+" |
";
tbl += "";
// error data
tbl += "
";
tbl += " ";
tbl += "
";
var bS = ""+p.bSubmit+"",
bC = ""+p.bCancel+"";
tbl += ""+rp_ge[$t.p.id].msg+" |
"+bS+" "+bC+" |
"+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"+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 = $(""+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 = $(""+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 = $(""+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 = $(""+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 = $(""+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;
$t.p.resetsearch = true;
try {
if( o.refreshstate !== 'currentfilter') {
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':
case 'currentfilter':
$($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 = $(""+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 = "'+ 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=-1, ind, ares={}, k;
if (!$t.grid ) { return; }
ind = $($t).jqGrid("getInd",rowid,true);
if(ind === false) {return;}
var bfcr = $.isFunction( o.beforeCancelRow ) ? o.beforeCancelRow.call($t, o, rowid) : undefined;
if( bfcr === undefined ) {
bfcr = true;
}
if(!bfcr) { return; }
for(k=0;k<$t.p.savedRow.length;k++) {
if( String($t.p.savedRow[k].id) === String(rowid)) {fr = k; break;}
}
if(fr >= 0) {
if($.isFunction($.fn.datepicker)) {
try {
$("input.hasDatepicker","#"+$.jgrid.jqID(ind.id)).datepicker('hide');
} catch (e) {}
}
$.each($t.p.colModel, function(){
if(this.editable === true && $t.p.savedRow[fr].hasOwnProperty(this.name)) {
ares[this.name] = $t.p.savedRow[fr][this.name];
}
});
$($t).jqGrid("setRowData",rowid,ares);
$(ind).attr("editable","0").unbind("keydown");
$t.p.savedRow.splice(fr,1);
if($("#"+$.jgrid.jqID(rowid), "#"+$.jgrid.jqID($t.p.id)).hasClass("jqgrid-new-row")){
setTimeout(function(){
$($t).jqGrid("delRowData",rowid);
$($t).jqGrid('showAddEditButtons');
},0);
}
}
$($t).triggerHandler("jqGridInlineAfterRestoreRow", [rowid]);
if ($.isFunction(o.afterrestorefunc))
{
o.afterrestorefunc.call($t, rowid);
}
});
},
addRow : function ( p ) {
p = $.extend(true, {
rowID : null,
initdata : {},
position :"first",
useDefValues : true,
useFormatter : false,
addRowParams : {extraparam:{}}
},p || {});
return this.each(function(){
if (!this.grid ) { return; }
var $t = this;
var bfar = $.isFunction( p.beforeAddRow ) ? p.beforeAddRow.call($t,p.addRowParams) : undefined;
if( bfar === undefined ) {
bfar = true;
}
if(!bfar) { return; }
p.rowID = $.isFunction(p.rowID) ? p.rowID.call($t, p) : ( (p.rowID != null) ? p.rowID : $.jgrid.randId());
if(p.useDefValues === true) {
$($t.p.colModel).each(function(){
if( this.editoptions && this.editoptions.defaultValue ) {
var opt = this.editoptions.defaultValue,
tmp = $.isFunction(opt) ? opt.call($t) : opt;
p.initdata[this.name] = tmp;
}
});
}
$($t).jqGrid('addRowData', p.rowID, p.initdata, p.position);
p.rowID = $t.p.idPrefix + p.rowID;
$("#"+$.jgrid.jqID(p.rowID), "#"+$.jgrid.jqID($t.p.id)).addClass("jqgrid-new-row");
if(p.useFormatter) {
$("#"+$.jgrid.jqID(p.rowID)+" .ui-inline-edit", "#"+$.jgrid.jqID($t.p.id)).click();
} else {
var opers = $t.p.prmNames,
oper = opers.oper;
p.addRowParams.extraparam[oper] = opers.addoper;
$($t).jqGrid('editRow', p.rowID, p.addRowParams);
$($t).jqGrid('setSelection', p.rowID);
}
});
},
inlineNav : function (elem, o) {
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');
select = $('select', selector);
function insert(perm,i,v) {
var a, b;
if(i>=0){
a = perm.slice();
b = a.splice(i,Math.max(perm.length-i,i));
if(i>perm.length) { i = perm.length; }
a[i] = v;
return a.concat(b);
}
return perm;
}
function call(fn, obj) {
if (!fn) { return; }
if (typeof fn === 'string') {
if ($.fn[fn]) {
$.fn[fn].apply(obj, $.makeArray(arguments).slice(2));
}
} else if ($.isFunction(fn)) {
fn.apply(obj, $.makeArray(arguments).slice(2));
}
}
opts = $.extend({
width : 400,
height : 240,
classname : null,
done : function(perm) { if (perm) { self.jqGrid("remapColumns", perm, true); } },
/* msel is either the name of a ui widget class that
extends a multiselect, or a function that supports
creating a multiselect object (with no argument,
or when passed an object), and destroying it (when
passed the string "destroy"). */
msel : "multiselect",
/* "msel_opts" : {}, */
/* dlog is either the name of a ui widget class that
behaves in a dialog-like way, or a function, that
supports creating a dialog (when passed dlog_opts)
or destroying a dialog (when passed the string
"destroy")
*/
dlog : "dialog",
dialog_opts : {
minWidth: 470,
dialogClass: "ui-jqdialog"
},
/* dlog_opts is either an option object to be passed
to "dlog", or (more likely) a function that creates
the options object.
The default produces a suitable options object for
ui.dialog */
dlog_opts : function(options) {
var buttons = {};
buttons[options.bSubmit] = function() {
options.apply_perm();
options.cleanup(false);
};
buttons[options.bCancel] = function() {
options.cleanup(true);
};
return $.extend(true, {
buttons: buttons,
close: function() {
options.cleanup(true);
},
modal: options.modal || false,
resizable: options.resizable || true,
width: options.width + 70,
resize: function () {
var widgetData = getMultiselectWidgetData(select),
$thisDialogContent = widgetData.container.closest(".ui-dialog-content");
if ($thisDialogContent.length > 0 && typeof $thisDialogContent[0].style === "object") {
$thisDialogContent[0].style.width = "";
} else {
$thisDialogContent.css("width", ""); // or just remove width style
}
widgetData.selectedList.height(Math.max(widgetData.selectedContainer.height() - widgetData.selectedActions.outerHeight() - 1, 1));
widgetData.availableList.height(Math.max(widgetData.availableContainer.height() - widgetData.availableActions.outerHeight() - 1, 1));
}
}, options.dialog_opts || {});
},
/* Function to get the permutation array, and pass it to the
"done" function */
apply_perm : function() {
var perm = [];
$('option',select).each(function() {
if ($(this).is("[selected]")) {
self.jqGrid("showCol", colModel[this.value].name);
} else {
self.jqGrid("hideCol", colModel[this.value].name);
}
});
//fixedCols.slice(0);
$('option[selected]',select).each(function() { perm.push(parseInt(this.value,10)); });
$.each(perm, function() { delete colMap[colModel[parseInt(this,10)].name]; });
$.each(colMap, function() {
var ti = parseInt(this,10);
perm = insert(perm,ti,ti);
});
if (opts.done) {
opts.done.call(self, perm);
}
self.jqGrid("setGridWidth", self[0].p.tblwidth, self[0].p.shrinkToFit);
},
/* Function to cleanup the dialog, and select. Also calls the
done function with no permutation (to indicate that the
columnChooser was aborted */
cleanup : function(calldone) {
call(opts.dlog, selector, 'destroy');
call(opts.msel, select, 'destroy');
selector.remove();
if (calldone && opts.done) {
opts.done.call(self);
}
},
msel_opts : {}
}, $.jgrid.col, opts || {});
if($.ui) {
if ($.ui.multiselect && $.ui.multiselect.defaults) {
if (!$.jgrid._multiselect) {
// should be in language file
alert("Multiselect plugin loaded after jqGrid. Please load the plugin before the jqGrid!");
return;
}
// ??? the next line uses $.ui.multiselect.defaults which will be typically undefined
opts.msel_opts = $.extend($.ui.multiselect.defaults, opts.msel_opts);
}
}
if (opts.caption) {
selector.attr("title", opts.caption);
}
if (opts.classname) {
selector.addClass(opts.classname);
select.addClass(opts.classname);
}
if (opts.width) {
$(">div",selector).css({width: opts.width,margin:"0 auto"});
select.css("width", opts.width);
}
if (opts.height) {
$(">div",selector).css("height", opts.height);
select.css("height", opts.height - 10);
}
select.empty();
$.each(colModel, function(i) {
colMap[this.name] = i;
if (this.hidedlg) {
if (!this.hidden) {
fixedCols.push(i);
}
return;
}
select.append("");
});
dopts = $.isFunction(opts.dlog_opts) ? opts.dlog_opts.call(self, opts) : opts.dlog_opts;
call(opts.dlog, selector, dopts);
mopts = $.isFunction(opts.msel_opts) ? opts.msel_opts.call(self, opts) : opts.msel_opts;
call(opts.msel, select, mopts);
// fix height of elements of the multiselect widget
$dialogContent = $("#colchooser_" + $.jgrid.jqID(self[0].p.id));
$dialogContent.css({ margin: "auto" });
$dialogContent.find(">div").css({ width: "100%", height: "100%", margin: "auto" });
multiselectData = getMultiselectWidgetData(select);
multiselectData.container.css({ width: "100%", height: "100%", margin: "auto" });
multiselectData.selectedContainer.css({ width: multiselectData.options.dividerLocation * 100 + "%", height: "100%", margin: "auto", boxSizing: "border-box" });
multiselectData.availableContainer.css({ width: (100 - multiselectData.options.dividerLocation * 100) + "%", height: "100%", margin: "auto", boxSizing: "border-box" });
// set height for both selectedList and availableList
multiselectData.selectedList.css("height", "auto");
multiselectData.availableList.css("height", "auto");
listHeight = Math.max(multiselectData.selectedList.height(), multiselectData.availableList.height());
listHeight = Math.min(listHeight, $(window).height());
multiselectData.selectedList.css("height", listHeight);
multiselectData.availableList.css("height", listHeight);
},
sortableRows : function (opts) {
// Can accept all sortable options and events
return this.each(function(){
var $t = this;
if(!$t.grid) { return; }
// Currently we disable a treeGrid sortable
if($t.p.treeGrid) { return; }
if($.fn.sortable) {
opts = $.extend({
"cursor":"move",
"axis" : "y",
"items": ".jqgrow"
},
opts || {});
if(opts.start && $.isFunction(opts.start)) {
opts._start_ = opts.start;
delete opts.start;
} else {opts._start_=false;}
if(opts.update && $.isFunction(opts.update)) {
opts._update_ = opts.update;
delete opts.update;
} else {opts._update_ = false;}
opts.start = function(ev,ui) {
$(ui.item).css("border-width","0");
$("td",ui.item).each(function(i){
this.style.width = $t.grid.cols[i].style.width;
});
if($t.p.subGrid) {
var subgid = $(ui.item).attr("id");
try {
$($t).jqGrid('collapseSubGridRow',subgid);
} catch (e) {}
}
if(opts._start_) {
opts._start_.apply(this,[ev,ui]);
}
};
opts.update = function (ev,ui) {
$(ui.item).css("border-width","");
if($t.p.rownumbers === true) {
$("td.jqgrid-rownum",$t.rows).each(function( i ){
$(this).html( i+1+(parseInt($t.p.page,10)-1)*parseInt($t.p.rowNum,10) );
});
}
if(opts._update_) {
opts._update_.apply(this,[ev,ui]);
}
};
$("tbody:first",$t).sortable(opts);
$("tbody:first",$t).disableSelection();
}
});
},
gridDnD : function(opts) {
return this.each(function(){
var $t = this, i, cn;
if(!$t.grid) { return; }
// Currently we disable a treeGrid drag and drop
if($t.p.treeGrid) { return; }
if(!$.fn.draggable || !$.fn.droppable) { return; }
function updateDnD ()
{
var datadnd = $.data($t,"dnd");
$("tr.jqgrow:not(.ui-draggable)",$t).draggable($.isFunction(datadnd.drag) ? datadnd.drag.call($($t),datadnd) : datadnd.drag);
}
var appender = "