Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
', {role: "row", "aria-hidden": "true"}).addClass("jqg-first-row-header").css("height", "auto");
} else {
$firstHeaderRow.empty();
}
var $firstRow,
inColumnHeader = function (text, columnHeaders) {
var length = columnHeaders.length, i;
for (i = 0; i < length; i++) {
if (columnHeaders[i].startColumnName === text) {
return i;
}
}
return -1;
};
$(ts).prepend($thead);
$tr = $('
', {role: "rowheader"}).addClass("ui-jqgrid-labels jqg-third-row-header");
for (i = 0; i < cml; i++) {
th = ths[i].el;
$th = $(th);
cmi = colModel[i];
// build the next cell for the first header row
thStyle = { height: '0px', width: ths[i].width + 'px', display: (cmi.hidden ? 'none' : '')};
$("
", {role: 'gridcell'}).css(thStyle).addClass("ui-first-th-" + ts.p.direction).appendTo($firstHeaderRow);
th.style.width = ""; // remove unneeded style
iCol = inColumnHeader(cmi.name, o.groupHeaders);
if (iCol >= 0) {
cghi = o.groupHeaders[iCol];
numberOfColumns = cghi.numberOfColumns;
titleText = cghi.titleText;
// caclulate the number of visible columns from the next numberOfColumns columns
for (cVisibleColumns = 0, iCol = 0; iCol < numberOfColumns && (i + iCol < cml); iCol++) {
if (!colModel[i + iCol].hidden) {
cVisibleColumns++;
}
}
// The next numberOfColumns headers will be moved in the next row
// in the current row will be placed the new column header with the titleText.
// The text will be over the cVisibleColumns columns
$colHeader = $('
').attr({role: "columnheader"})
.addClass("ui-state-default ui-th-column-header ui-th-" + ts.p.direction)
.css({'height': '22px', 'border-top': '0px none'})
.html(titleText);
if (cVisibleColumns > 0) {
$colHeader.attr("colspan", String(cVisibleColumns));
}
if (ts.p.headertitles) {
$colHeader.attr("title", $colHeader.text());
}
// hide if not a visible cols
if (cVisibleColumns === 0) {
$colHeader.hide();
}
$th.before($colHeader); // insert new column header before the current
$tr.append(th); // move the current header in the next row
// set the coumter of headers which will be moved in the next row
skip = numberOfColumns - 1;
} else {
if (skip === 0) {
if (o.useColSpanStyle) {
// expand the header height to two rows
$th.attr("rowspan", "2");
} else {
$('
', {role: "columnheader"})
.addClass("ui-state-default ui-th-column-header ui-th-" + ts.p.direction)
.css({"display": cmi.hidden ? 'none' : '', 'border-top': '0px none'})
.insertBefore($th);
$tr.append(th);
}
} else {
// move the header to the next row
//$th.css({"padding-top": "2px", height: "19px"});
$tr.append(th);
skip--;
}
}
}
$theadInTable = $(ts).children("thead");
$theadInTable.prepend($firstHeaderRow);
$tr.insertAfter($trLabels);
$htable.append($theadInTable);
if (o.useColSpanStyle) {
// Increase the height of resizing span of visible headers
$htable.find("span.ui-jqgrid-resize").each(function () {
var $parent = $(this).parent();
if ($parent.is(":visible")) {
this.style.cssText = 'height: ' + $parent.height() + 'px !important; cursor: col-resize;';
}
});
// Set position of the sortable div (the main lable)
// with the column header text to the middle of the cell.
// One should not do this for hidden headers.
$htable.find("div.ui-jqgrid-sortable").each(function () {
var $ts = $(this), $parent = $ts.parent();
if ($parent.is(":visible") && $parent.is(":has(span.ui-jqgrid-resize)")) {
$ts.css('top', ($parent.height() - $ts.outerHeight()) / 2 + 'px');
}
});
}
$firstRow = $theadInTable.find("tr.jqg-first-row-header");
$(ts).bind('jqGridResizeStop.setGroupHeaders', function (e, nw, idx) {
$firstRow.find('th').eq(idx).width(nw);
});
});
},
setFrozenColumns: function () {
return this.each(function () {
if (!this.grid) {
return;
}
var $t = this, cm = $t.p.colModel, i = 0, len = cm.length, maxfrozen = -1, frozen = false;
// TODO treeGrid and grouping Support
if ($t.p.subGrid === true || $t.p.treeGrid === true || $t.p.cellEdit === true || $t.p.sortable || $t.p.scroll || $t.p.grouping) {
return;
}
if ($t.p.rownumbers) {
i++;
}
if ($t.p.multiselect) {
i++;
}
// get the max index of frozen col
while (i < len) {
// from left, no breaking frozen
if (cm[i].frozen === true) {
frozen = true;
maxfrozen = i;
} else {
break;
}
i++;
}
if (maxfrozen >= 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);
/*
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 [email protected]
* http://www.greenbill.com
*
* Changes from Tony Tomov [email protected]
* 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 < so.length; i++) {
sv = so[i].split(sep);
if (sv.length > 2) {
sv[1] = $.map(sv,function (n, i) {
if (i > 0) {
return n;
}
}).join(sep);
}
if (msl) {
if ($.inArray(sv[0], scell) > -1) {
ret[j] = sv[1];
j++;
}
} else if ($.trim(sv[0]) === $.trim(cellval)) {
ret[0] = sv[1];
break;
}
}
} else if ($.fmatter.isObject(oSelect)) {
// this is quicker
if (msl) {
ret = $.map(scell, function (n) {
return oSelect[n];
});
} else {
ret[0] = oSelect[cellval] || "";
}
}
}
cellval = ret.join(", ");
return cellval === "" ? $.fn.fmatter.defaultFormat(cellval, opts) : cellval;
};
$.fn.fmatter.rowactions = function (act) {
var $tr = $(this).closest("tr.jqgrow"),
rid = $tr.attr("id"),
$id = $(this).closest("table.ui-jqgrid-btable").attr('id').replace(/_frozen([^_]*)$/, '$1'),
$grid = $("#" + $id),
$t = $grid[0],
p = $t.p,
cm = p.colModel[$.jgrid.getCellIndex(this)],
$actionsDiv = cm.frozen ? $("tr#" + rid + " td:eq(" + $.jgrid.getCellIndex(this) + ") > div", $grid) : $(this).parent(),
op = {
keys: false,
onEdit: null,
onSuccess: null,
afterSave: null,
onError: null,
afterRestore: null,
extraparam: {},
url: null,
restoreAfterError: true,
mtype: "POST",
delOptions: {},
editOptions: {}
},
saverow = function (rowid, res) {
if ($.isFunction(op.afterSave)) {
op.afterSave.call($t, rowid, res);
}
$actionsDiv.find("div.ui-inline-edit,div.ui-inline-del").show();
$actionsDiv.find("div.ui-inline-save,div.ui-inline-cancel").hide();
},
restorerow = function (rowid) {
if ($.isFunction(op.afterRestore)) {
op.afterRestore.call($t, rowid);
}
$actionsDiv.find("div.ui-inline-edit,div.ui-inline-del").show();
$actionsDiv.find("div.ui-inline-save,div.ui-inline-cancel").hide();
};
if (cm.formatoptions !== undefined) {
op = $.extend(op, cm.formatoptions);
}
if (p.editOptions !== undefined) {
op.editOptions = p.editOptions;
}
if (p.delOptions !== undefined) {
op.delOptions = p.delOptions;
}
if ($tr.hasClass("jqgrid-new-row")) {
op.extraparam[p.prmNames.oper] = p.prmNames.addoper;
}
var actop = {
keys: op.keys,
oneditfunc: op.onEdit,
successfunc: op.onSuccess,
url: op.url,
extraparam: op.extraparam,
aftersavefunc: saverow,
errorfunc: op.onError,
afterrestorefunc: restorerow,
restoreAfterError: op.restoreAfterError,
mtype: op.mtype
};
switch (act) {
case 'edit':
$grid.jqGrid('editRow', rid, actop);
$actionsDiv.find("div.ui-inline-edit,div.ui-inline-del").hide();
$actionsDiv.find("div.ui-inline-save,div.ui-inline-cancel").show();
$grid.triggerHandler("jqGridAfterGridComplete");
break;
case 'save':
if ($grid.jqGrid('saveRow', rid, actop)) {
$actionsDiv.find("div.ui-inline-edit,div.ui-inline-del").show();
$actionsDiv.find("div.ui-inline-save,div.ui-inline-cancel").hide();
$grid.triggerHandler("jqGridAfterGridComplete");
}
break;
case 'cancel' :
$grid.jqGrid('restoreRow', rid, restorerow);
$actionsDiv.find("div.ui-inline-edit,div.ui-inline-del").show();
$actionsDiv.find("div.ui-inline-save,div.ui-inline-cancel").hide();
$grid.triggerHandler("jqGridAfterGridComplete");
break;
case 'del':
$grid.jqGrid('delGridRow', rid, op.delOptions);
break;
case 'formedit':
$grid.jqGrid('setSelection', rid);
$grid.jqGrid('editGridRow', rid, op.editOptions);
break;
}
};
$.fn.fmatter.actions = function (cellval, opts) {
var op = {keys: false, editbutton: true, delbutton: true, editformbutton: false},
rowid = opts.rowId, str = "", ocl;
if (opts.colModel.formatoptions !== undefined) {
op = $.extend(op, opts.colModel.formatoptions);
}
if (rowid === undefined || $.fmatter.isEmpty(rowid)) {
return "";
}
if (op.editformbutton) {
ocl = "id='jEditButton_" + rowid + "' onclick=jQuery.fn.fmatter.rowactions.call(this,'formedit'); onmouseover=jQuery(this).addClass('ui-state-hover'); onmouseout=jQuery(this).removeClass('ui-state-hover'); ";
str += "
";
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 = options.name ? String(options.id).substring(0, String(options.id).length - String(options.name).length - 1) : String(options.id),
postData = options.postData || ajaxso.postData;
if ($t.p && $t.p.idPrefix) {
rowid = $.jgrid.stripPref($t.p.idPrefix, rowid);
}
$.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 < so.length; i++) {
sv = so[i].split(sep);
if (sv.length > 2) {
sv[1] = $.map(sv,function (n, ii) {
if (ii > 0) {
return n;
}
}).join(sep);
}
ov = document.createElement("option");
ov.setAttribute("role", "option");
ov.value = sv[0];
ov.innerHTML = sv[1];
elem.appendChild(ov);
if (!msl && ($.trim(sv[0]) === $.trim(vl) || $.trim(sv[1]) === $.trim(vl))) {
ov.selected = "selected";
}
if (msl && ($.inArray($.trim(sv[1]), ovm) > -1 || $.inArray($.trim(sv[0]), ovm) > -1)) {
ov.selected = "selected";
}
}
} else if (typeof options.value === 'object') {
var oSv = options.value, key;
for (key in oSv) {
if (oSv.hasOwnProperty(key)) {
ov = document.createElement("option");
ov.setAttribute("role", "option");
ov.value = key;
ov.innerHTML = oSv[key];
elem.appendChild(ov);
if (!msl && ( $.trim(key) === $.trim(vl) || $.trim(oSv[key]) === $.trim(vl))) {
ov.selected = "selected";
}
if (msl && ($.inArray($.trim(oSv[key]), ovm) > -1 || $.inArray($.trim(key), ovm) > -1)) {
ov.selected = "selected";
}
}
}
}
setAttributes(elem, options, ['value']);
}
break;
case "text" :
case "password" :
case "button" :
var role;
if (eltype === "button") {
role = "button";
}
else {
role = "textbox";
}
elem = document.createElement("input");
elem.type = eltype;
elem.value = vl;
setAttributes(elem, options);
if (eltype !== "button") {
if (autowidth) {
if (!options.size) {
$(elem).css({width: "98%"});
}
} else if (!options.size) {
options.size = 20;
}
}
$(elem).attr("role", role);
break;
case "image" :
case "file" :
elem = document.createElement("input");
elem.type = eltype;
setAttributes(elem, options);
break;
case "custom" :
elem = document.createElement("span");
try {
if ($.isFunction(options.custom_element)) {
var celm = options.custom_element.call($t, vl, options);
if (celm) {
celm = $(celm).addClass("customelement").attr({id: options.id, name: options.name});
$(elem).empty().append(celm);
} else {
throw "e2";
}
} else {
throw "e1";
}
} catch (e) {
if (e === "e1") {
$.jgrid.info_dialog($.jgrid.errors.errcap, "function 'custom_element' " + $.jgrid.edit.msg.nodefined, $.jgrid.edit.bClose);
}
if (e === "e2") {
$.jgrid.info_dialog($.jgrid.errors.errcap, "function 'custom_element' " + $.jgrid.edit.msg.novalue, $.jgrid.edit.bClose);
}
else {
$.jgrid.info_dialog($.jgrid.errors.errcap, typeof e === "string" ? e : e.message, $.jgrid.edit.bClose);
}
}
break;
}
return elem;
},
// Date Validation Javascript
checkDate: function (format, date) {
var daysInFebruary = function (year) {
// February has 29 days in any year evenly divisible by four,
// EXCEPT for centurial years which are not also divisible by 400.
return (((year % 4 === 0) && ( year % 100 !== 0 || (year % 400 === 0))) ? 29 : 28 );
},
tsp = {}, sep;
format = format.toLowerCase();
//we search for /,-,. for the date separator
if (format.indexOf("/") !== -1) {
sep = "/";
} else if (format.indexOf("-") !== -1) {
sep = "-";
} else if (format.indexOf(".") !== -1) {
sep = ".";
} else {
sep = "/";
}
format = format.split(sep);
date = date.split(sep);
if (date.length !== 3) {
return false;
}
var j = -1, yln, dln = -1, mln = -1, i;
for (i = 0; i < format.length; i++) {
var dv = isNaN(date[i]) ? 0 : parseInt(date[i], 10);
tsp[format[i]] = dv;
yln = format[i];
if (yln.indexOf("y") !== -1) {
j = i;
}
if (yln.indexOf("m") !== -1) {
mln = i;
}
if (yln.indexOf("d") !== -1) {
dln = i;
}
}
if (format[j] === "y" || format[j] === "yyyy") {
yln = 4;
} else if (format[j] === "yy") {
yln = 2;
} else {
yln = -1;
}
var daysInMonth = [0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31],
strDate;
if (j === -1) {
return false;
}
strDate = tsp[format[j]].toString();
if (yln === 2 && strDate.length === 1) {
yln = 1;
}
if (strDate.length !== yln || (tsp[format[j]] === 0 && date[j] !== "00")) {
return false;
}
if (mln === -1) {
return false;
}
strDate = tsp[format[mln]].toString();
if (strDate.length < 1 || tsp[format[mln]] < 1 || tsp[format[mln]] > 12) {
return false;
}
if (dln === -1) {
return false;
}
strDate = tsp[format[dln]].toString();
if (strDate.length < 1 || tsp[format[dln]] < 1 || tsp[format[dln]] > 31 || (tsp[format[mln]] === 2 && tsp[format[dln]] > daysInFebruary(tsp[format[j]])) || tsp[format[dln]] > daysInMonth[tsp[format[mln]]]) {
return false;
}
return true;
},
isEmpty: function (val) {
if (val.match(/^\s+$/) || val === "") {
return true;
}
return false;
},
checkTime: function (time) {
// checks only hh:ss (and optional am/pm)
var re = /^(\d{1,2}):(\d{2})([apAP][Mm])?$/, regs;
if (!$.jgrid.isEmpty(time)) {
regs = time.match(re);
if (regs) {
if (regs[3]) {
if (regs[1] < 1 || regs[1] > 12) {
return false;
}
} else {
if (regs[1] > 23) {
return false;
}
}
if (regs[2] > 59) {
return false;
}
} else {
return false;
}
}
return true;
},
checkValues: function (val, valref, customobject, nam) {
var edtrul, i, nm, dft, len, g = this, cm = g.p.colModel;
if (customobject === undefined) {
if (typeof valref === 'string') {
for (i = 0, len = cm.length; i < len; i++) {
if (cm[i].name === valref) {
edtrul = cm[i].editrules;
valref = i;
if (cm[i].formoptions != null) {
nm = cm[i].formoptions.label;
}
break;
}
}
} else if (valref >= 0) {
edtrul = cm[valref].editrules;
}
} else {
edtrul = customobject;
nm = nam === undefined ? "_" : nam;
}
if (edtrul) {
if (!nm) {
nm = g.p.colNames != null ? g.p.colNames[valref] : cm[valref].label;
}
if (edtrul.required === true) {
if ($.jgrid.isEmpty(val)) {
return [false, nm + ": " + $.jgrid.edit.msg.required, ""];
}
}
// force required
var rqfield = edtrul.required === false ? false : true;
if (edtrul.number === true) {
if (!(rqfield === false && $.jgrid.isEmpty(val))) {
if (isNaN(val)) {
return [false, nm + ": " + $.jgrid.edit.msg.number, ""];
}
}
}
if (edtrul.minValue !== undefined && !isNaN(edtrul.minValue)) {
if (parseFloat(val) < parseFloat(edtrul.minValue)) {
return [false, nm + ": " + $.jgrid.edit.msg.minValue + " " + edtrul.minValue, ""];
}
}
if (edtrul.maxValue !== undefined && !isNaN(edtrul.maxValue)) {
if (parseFloat(val) > parseFloat(edtrul.maxValue)) {
return [false, nm + ": " + $.jgrid.edit.msg.maxValue + " " + edtrul.maxValue, ""];
}
}
var filter;
if (edtrul.email === true) {
if (!(rqfield === false && $.jgrid.isEmpty(val))) {
// taken from $ Validate plugin
filter = /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i;
if (!filter.test(val)) {
return [false, nm + ": " + $.jgrid.edit.msg.email, ""];
}
}
}
if (edtrul.integer === true) {
if (!(rqfield === false && $.jgrid.isEmpty(val))) {
if (isNaN(val)) {
return [false, nm + ": " + $.jgrid.edit.msg.integer, ""];
}
if ((val % 1 !== 0) || (val.indexOf('.') !== -1)) {
return [false, nm + ": " + $.jgrid.edit.msg.integer, ""];
}
}
}
if (edtrul.date === true) {
if (!(rqfield === false && $.jgrid.isEmpty(val))) {
if (cm[valref].formatoptions && cm[valref].formatoptions.newformat) {
dft = cm[valref].formatoptions.newformat;
if ($.jgrid.formatter.date.masks.hasOwnProperty(dft)) {
dft = $.jgrid.formatter.date.masks[dft];
}
} else {
dft = cm[valref].datefmt || "Y-m-d";
}
if (!$.jgrid.checkDate(dft, val)) {
return [false, nm + ": " + $.jgrid.edit.msg.date + " - " + dft, ""];
}
}
}
if (edtrul.time === true) {
if (!(rqfield === false && $.jgrid.isEmpty(val))) {
if (!$.jgrid.checkTime(val)) {
return [false, nm + ": " + $.jgrid.edit.msg.date + " - hh:mm (am/pm)", ""];
}
}
}
if (edtrul.url === true) {
if (!(rqfield === false && $.jgrid.isEmpty(val))) {
filter = /^(((https?)|(ftp)):\/\/([\-\w]+\.)+\w{2,3}(\/[%\-\w]+(\.\w{2,})?)*(([\w\-\.\?\\\/+@`~=%!]*)(\.\w{2,})?)*\/?)/i;
if (!filter.test(val)) {
return [false, nm + ": " + $.jgrid.edit.msg.url, ""];
}
}
}
if (edtrul.custom === true) {
if (!(rqfield === false && $.jgrid.isEmpty(val))) {
if ($.isFunction(edtrul.custom_func)) {
var ret = edtrul.custom_func.call(g, val, nm, valref);
return $.isArray(ret) ? ret : [false, $.jgrid.edit.msg.customarray, ""];
}
return [false, $.jgrid.edit.msg.customfcheck, ""];
}
}
}
return [true, "", ""];
}
});
})(jQuery);
/*jshint evil:true, eqeqeq:false, eqnull:true, devel:true */
/*global jQuery */
(function ($) {
/*
**
* jqGrid addons using jQuery UI
* Author: Mark Williams
* 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
* depends on jQuery UI
**/
"use strict";
if ($.jgrid.msie && $.jgrid.msiever() === 8) {
$.expr[":"].hidden = function (elem) {
return elem.offsetWidth === 0 || elem.offsetHeight === 0 ||
elem.style.display === "none";
};
}
// requiere load multiselect before grid
$.jgrid._multiselect = false;
if ($.ui) {
if ($.ui.multiselect) {
if ($.ui.multiselect.prototype._setSelected) {
var setSelected = $.ui.multiselect.prototype._setSelected;
$.ui.multiselect.prototype._setSelected = function (item, selected) {
var ret = setSelected.call(this, item, selected);
if (selected && this.selectedList) {
var elt = this.element;
this.selectedList.find('li').each(function () {
if ($(this).data('optionLink')) {
$(this).data('optionLink').remove().appendTo(elt);
}
});
}
return ret;
};
}
if ($.ui.multiselect.prototype.destroy) {
$.ui.multiselect.prototype.destroy = function () {
this.element.show();
this.container.remove();
if ($.Widget === undefined) {
$.widget.prototype.destroy.apply(this, arguments);
} else {
$.Widget.prototype.destroy.apply(this, arguments);
}
};
}
$.jgrid._multiselect = true;
}
}
$.jgrid.extend({
sortableColumns: function (tblrow) {
return this.each(function () {
var ts = this, tid = $.jgrid.jqID(ts.p.id);
function start() {
ts.p.disableClick = true;
}
var sortable_opts = {
"tolerance": "pointer",
"axis": "x",
"scrollSensitivity": "1",
"items": '>th:not(:has(#jqgh_' + tid + '_cb' + ',#jqgh_' + tid + '_rn' + ',#jqgh_' + tid + '_subgrid),:hidden)',
"placeholder": {
element: function (item) {
var el = $(document.createElement(item[0].nodeName))
.addClass(item[0].className + " ui-sortable-placeholder ui-state-highlight")
.removeClass("ui-sortable-helper")[0];
return el;
},
update: function (self, p) {
p.height(self.currentItem.innerHeight() - parseInt(self.currentItem.css('paddingTop') || 0, 10) - parseInt(self.currentItem.css('paddingBottom') || 0, 10));
p.width(self.currentItem.innerWidth() - parseInt(self.currentItem.css('paddingLeft') || 0, 10) - parseInt(self.currentItem.css('paddingRight') || 0, 10));
}
},
"update": function (event, ui) {
var p = $(ui.item).parent(),
th = $(">th", p),
colModel = ts.p.colModel,
cmMap = {}, tid = ts.p.id + "_";
$.each(colModel, function (i) {
cmMap[this.name] = i;
});
var permutation = [];
th.each(function () {
var id = $(">div", this).get(0).id.replace(/^jqgh_/, "").replace(tid, "");
if (cmMap.hasOwnProperty(id)) {
permutation.push(cmMap[id]);
}
});
$(ts).jqGrid("remapColumns", permutation, true, true);
if ($.isFunction(ts.p.sortable.update)) {
ts.p.sortable.update(permutation);
}
setTimeout(function () {
ts.p.disableClick = false;
}, 50);
}
};
if (ts.p.sortable.options) {
$.extend(sortable_opts, ts.p.sortable.options);
} else if ($.isFunction(ts.p.sortable)) {
ts.p.sortable = { "update": ts.p.sortable };
}
if (sortable_opts.start) {
var s = sortable_opts.start;
sortable_opts.start = function (e, ui) {
start();
s.call(this, e, ui);
};
} else {
sortable_opts.start = start;
}
if (ts.p.sortable.exclude) {
sortable_opts.items += ":not(" + ts.p.sortable.exclude + ")";
}
tblrow.sortable(sortable_opts).data("sortable").floating = true;
});
},
columnChooser: function (opts) {
var self = this;
if ($("#colchooser_" + $.jgrid.jqID(self[0].p.id)).length) {
return;
}
var selector = $('
');
var select = $('select', selector);
function insert(perm, i, v) {
if (i >= 0) {
var a = perm.slice();
var b = a.splice(i, Math.max(perm.length - i, i));
if (i > perm.length) {
i = perm.length;
}
a[i] = v;
return a.concat(b);
}
}
opts = $.extend({
"width": 420,
"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
},
/* 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 (opts) {
var buttons = {};
buttons[opts.bSubmit] = function () {
opts.apply_perm();
opts.cleanup(false);
};
buttons[opts.bCancel] = function () {
opts.cleanup(true);
};
return $.extend(true, {
"buttons": buttons,
"close": function () {
opts.cleanup(true);
},
"modal": opts.modal || false,
"resizable": opts.resizable || true,
"width": opts.width + 20
}, opts.dialog_opts || {});
},
/* Function to get the permutation array, and pass it to the
"done" function */
"apply_perm": function () {
$('option', select).each(function () {
if (this.selected) {
self.jqGrid("showCol", colModel[this.value].name);
} else {
self.jqGrid("hideCol", colModel[this.value].name);
}
});
var perm = [];
//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);
}
},
/* 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) {
if (opts.msel === "multiselect") {
if (!$.jgrid._multiselect) {
// should be in language file
alert("Multiselect plugin loaded after jqGrid. Please load the plugin before the jqGrid!");
return;
}
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);
}
var colModel = self.jqGrid("getGridParam", "colModel");
var colNames = self.jqGrid("getGridParam", "colNames");
var colMap = {}, fixedCols = [];
select.empty();
$.each(colModel, function (i) {
colMap[this.name] = i;
if (this.hidedlg) {
if (!this.hidden) {
fixedCols.push(i);
}
return;
}
select.append("");
});
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));
}
}
var dopts = $.isFunction(opts.dlog_opts) ? opts.dlog_opts.call(self, opts) : opts.dlog_opts;
call(opts.dlog, selector, dopts);
var mopts = $.isFunction(opts.msel_opts) ? opts.msel_opts.call(self, opts) : opts.msel_opts;
call(opts.msel, select, mopts);
},
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", "0px");
$("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 = "
";
if ($("#jqgrid_dnd")[0] === undefined) {
$('body').append(appender);
}
if (typeof opts === 'string' && opts === 'updateDnD' && $t.p.jqgdnd === true) {
updateDnD();
return;
}
opts = $.extend({
"drag": function (opts) {
return $.extend({
start: function (ev, ui) {
var i, subgid;
// if we are in subgrid mode try to collapse the node
if ($t.p.subGrid) {
subgid = $(ui.helper).attr("id");
try {
$($t).jqGrid('collapseSubGridRow', subgid);
} catch (e) {
}
}
// hack
// drag and drop does not insert tr in table, when the table has no rows
// we try to insert new empty row on the target(s)
for (i = 0; i < $.data($t, "dnd").connectWith.length; i++) {
if ($($.data($t, "dnd").connectWith[i]).jqGrid('getGridParam', 'reccount') === 0) {
$($.data($t, "dnd").connectWith[i]).jqGrid('addRowData', 'jqg_empty_row', {});
}
}
ui.helper.addClass("ui-state-highlight");
$("td", ui.helper).each(function (i) {
this.style.width = $t.grid.headers[i].width + "px";
});
if (opts.onstart && $.isFunction(opts.onstart)) {
opts.onstart.call($($t), ev, ui);
}
},
stop: function (ev, ui) {
var i, ids;
if (ui.helper.dropped && !opts.dragcopy) {
ids = $(ui.helper).attr("id");
if (ids === undefined) {
ids = $(this).attr("id");
}
$($t).jqGrid('delRowData', ids);
}
// if we have a empty row inserted from start event try to delete it
for (i = 0; i < $.data($t, "dnd").connectWith.length; i++) {
$($.data($t, "dnd").connectWith[i]).jqGrid('delRowData', 'jqg_empty_row');
}
if (opts.onstop && $.isFunction(opts.onstop)) {
opts.onstop.call($($t), ev, ui);
}
}
}, opts.drag_opts || {});
},
"drop": function (opts) {
return $.extend({
accept: function (d) {
if (!$(d).hasClass('jqgrow')) {
return d;
}
var tid = $(d).closest("table.ui-jqgrid-btable");
if (tid.length > 0 && $.data(tid[0], "dnd") !== undefined) {
var cn = $.data(tid[0], "dnd").connectWith;
return $.inArray('#' + $.jgrid.jqID(this.id), cn) !== -1 ? true : false;
}
return false;
},
drop: function (ev, ui) {
if (!$(ui.draggable).hasClass('jqgrow')) {
return;
}
var accept = $(ui.draggable).attr("id");
var getdata = ui.draggable.parent().parent().jqGrid('getRowData', accept);
if (!opts.dropbyname) {
var j = 0, tmpdata = {}, nm, key;
var dropmodel = $("#" + $.jgrid.jqID(this.id)).jqGrid('getGridParam', 'colModel');
try {
for (key in getdata) {
if (getdata.hasOwnProperty(key)) {
nm = dropmodel[j].name;
if (!(nm === 'cb' || nm === 'rn' || nm === 'subgrid' )) {
if (getdata.hasOwnProperty(key) && dropmodel[j]) {
tmpdata[nm] = getdata[key];
}
}
j++;
}
}
getdata = tmpdata;
} catch (e) {
}
}
ui.helper.dropped = true;
if (opts.beforedrop && $.isFunction(opts.beforedrop)) {
//parameters to this callback - event, element, data to be inserted, sender, reciever
// should return object which will be inserted into the reciever
var datatoinsert = opts.beforedrop.call(this, ev, ui, getdata, $('#' + $.jgrid.jqID($t.p.id)), $(this));
if (datatoinsert !== undefined && datatoinsert !== null && typeof datatoinsert === "object") {
getdata = datatoinsert;
}
}
if (ui.helper.dropped) {
var grid;
if (opts.autoid) {
if ($.isFunction(opts.autoid)) {
grid = opts.autoid.call(this, getdata);
} else {
grid = Math.ceil(Math.random() * 1000);
grid = opts.autoidprefix + grid;
}
}
// NULL is interpreted as undefined while null as object
$("#" + $.jgrid.jqID(this.id)).jqGrid('addRowData', grid, getdata, opts.droppos);
}
if (opts.ondrop && $.isFunction(opts.ondrop)) {
opts.ondrop.call(this, ev, ui, getdata);
}
}}, opts.drop_opts || {});
},
"onstart": null,
"onstop": null,
"beforedrop": null,
"ondrop": null,
"drop_opts": {
"activeClass": "ui-state-active",
"hoverClass": "ui-state-hover"
},
"drag_opts": {
"revert": "invalid",
"helper": "clone",
"cursor": "move",
"appendTo": "#jqgrid_dnd",
"zIndex": 5000
},
"dragcopy": false,
"dropbyname": false,
"droppos": "first",
"autoid": true,
"autoidprefix": "dnd_"
}, opts || {});
if (!opts.connectWith) {
return;
}
opts.connectWith = opts.connectWith.split(",");
opts.connectWith = $.map(opts.connectWith, function (n) {
return $.trim(n);
});
$.data($t, "dnd", opts);
if ($t.p.reccount !== 0 && !$t.p.jqgdnd) {
updateDnD();
}
$t.p.jqgdnd = true;
for (i = 0; i < opts.connectWith.length; i++) {
cn = opts.connectWith[i];
$(cn).droppable($.isFunction(opts.drop) ? opts.drop.call($($t), opts) : opts.drop);
}
});
},
gridResize: function (opts) {
return this.each(function () {
var $t = this, gID = $.jgrid.jqID($t.p.id);
if (!$t.grid || !$.fn.resizable) {
return;
}
opts = $.extend({}, opts || {});
if (opts.alsoResize) {
opts._alsoResize_ = opts.alsoResize;
delete opts.alsoResize;
} else {
opts._alsoResize_ = false;
}
if (opts.stop && $.isFunction(opts.stop)) {
opts._stop_ = opts.stop;
delete opts.stop;
} else {
opts._stop_ = false;
}
opts.stop = function (ev, ui) {
$($t).jqGrid('setGridParam', {height: $("#gview_" + gID + " .ui-jqgrid-bdiv").height()});
$($t).jqGrid('setGridWidth', ui.size.width, opts.shrinkToFit);
if (opts._stop_) {
opts._stop_.call($t, ev, ui);
}
};
if (opts._alsoResize_) {
var optstest = "{\'#gview_" + gID + " .ui-jqgrid-bdiv\':true,'" + opts._alsoResize_ + "':true}";
opts.alsoResize = eval('(' + optstest + ')'); // the only way that I found to do this
} else {
opts.alsoResize = $(".ui-jqgrid-bdiv", "#gview_" + gID);
}
delete opts._alsoResize_;
$("#gbox_" + gID).resizable(opts);
});
}
});
})(jQuery);
/*
Transform a table to a jqGrid.
Peter Romianowski
If the first column of the table contains checkboxes or
radiobuttons then the jqGrid is made selectable.
*/
// Addition - selector can be a class or id
function tableToGrid(selector, options) {
jQuery(selector).each(function () {
if (this.grid) {
return;
} //Adedd from Tony Tomov
// This is a small "hack" to make the width of the jqGrid 100%
jQuery(this).width("99%");
var w = jQuery(this).width();
// Text whether we have single or multi select
var inputCheckbox = jQuery('tr td:first-child input[type=checkbox]:first', jQuery(this));
var inputRadio = jQuery('tr td:first-child input[type=radio]:first', jQuery(this));
var selectMultiple = inputCheckbox.length > 0;
var selectSingle = !selectMultiple && inputRadio.length > 0;
var selectable = selectMultiple || selectSingle;
//var inputName = inputCheckbox.attr("name") || inputRadio.attr("name");
// Build up the columnModel and the data
var colModel = [];
var colNames = [];
jQuery('th', jQuery(this)).each(function () {
if (colModel.length === 0 && selectable) {
colModel.push({
name: '__selection__',
index: '__selection__',
width: 0,
hidden: true
});
colNames.push('__selection__');
} else {
colModel.push({
name: jQuery(this).attr("id") || jQuery.trim(jQuery.jgrid.stripHtml(jQuery(this).html())).split(' ').join('_'),
index: jQuery(this).attr("id") || jQuery.trim(jQuery.jgrid.stripHtml(jQuery(this).html())).split(' ').join('_'),
width: jQuery(this).width() || 150
});
colNames.push(jQuery(this).html());
}
});
var data = [];
var rowIds = [];
var rowChecked = [];
jQuery('tbody > tr', jQuery(this)).each(function () {
var row = {};
var rowPos = 0;
jQuery('td', jQuery(this)).each(function () {
if (rowPos === 0 && selectable) {
var input = jQuery('input', jQuery(this));
var rowId = input.attr("value");
rowIds.push(rowId || data.length);
if (input.is(":checked")) {
rowChecked.push(rowId);
}
row[colModel[rowPos].name] = input.attr("value");
} else {
row[colModel[rowPos].name] = jQuery(this).html();
}
rowPos++;
});
if (rowPos > 0) {
data.push(row);
}
});
// Clear the original HTML table
jQuery(this).empty();
// Mark it as jqGrid
jQuery(this).addClass("scroll");
jQuery(this).jqGrid(jQuery.extend({
datatype: "local",
width: w,
colNames: colNames,
colModel: colModel,
multiselect: selectMultiple
//inputName: inputName,
//inputValueCol: imputName != null ? "__selection__" : null
}, options || {}));
// Add data
var a;
for (a = 0; a < data.length; a++) {
var id = null;
if (rowIds.length > 0) {
id = rowIds[a];
if (id && id.replace) {
// We have to do this since the value of a checkbox
// or radio button can be anything
id = encodeURIComponent(id).replace(/[.\-%]/g, "_");
}
}
if (id === null) {
id = a + 1;
}
jQuery(this).jqGrid("addRowData", id, data[a]);
}
// Set the selection
for (a = 0; a < rowChecked.length; a++) {
jQuery(this).jqGrid("setSelection", rowChecked[a]);
}
});
};