', {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': '0 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': '0 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 )
{
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('jqGridSortCol.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[role=row]",btbl).each(function(){
$("td[role=gridcell]: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;
});
if(!$t.grid.hDiv.loading) {
$($t).triggerHandler("jqGridAfterGridComplete");
}
$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_"+name+">\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 : "") + "" + name + ">";
}
}
else if (typeof(v) === "function") {
xml += ind + "<" + name + ">" + "" + "" + name + ">";
}
else {
if (v === undefined ) { v = ""; }
if (v.toString() === "\"\"" || v.toString().length === 0) {
xml += ind + "<" + name + ">__EMPTY_STRING_" + name + ">";
}
else {
xml += ind + "<" + name + ">" + v.toString() + "" + name + ">";
}
}
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 += "" + n.nodeName + ">";
}
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 = {
extraparam: {}
},
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 += "
");
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 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
});
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 = "";
if(rd.tagName.toUpperCase() !== 'SELECT') rd.value = "";
rd.setAttribute("readonly", "true");
rd.setAttribute("disabled", "true");
} else {
if(rd.tagName.toUpperCase() === 'SELECT') rule.data = rd.value;
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,
mustReload = 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 = $("
");
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 = "