jquery.fmatter.js 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061
  1. /**
  2. * formatter for values but most of the values if for jqGrid
  3. * Some of this was inspired and based on how YUI does the table datagrid but in jQuery fashion
  4. * we are trying to keep it as light as possible
  5. * Joshua Burnett josh@9ci.com
  6. * http://www.greenbill.com
  7. *
  8. * Changes from Tony Tomov tony@trirand.com
  9. * Changed by Oleg Kiriljuk, oleg.kiriljuk@ok-soft-gmbh.com
  10. * Dual licensed under the MIT and GPL licenses:
  11. * http://www.opensource.org/licenses/mit-license.php
  12. * http://www.gnu.org/licenses/gpl-2.0.html
  13. *
  14. **/
  15. /*jshint eqeqeq:false */
  16. /*jslint
  17. browser, devel, for, multivar, this, white
  18. */
  19. /*global jQuery, define, exports, module, require */
  20. (function (factory) {
  21. "use strict";
  22. if (typeof define === "function" && define.amd) {
  23. // AMD. Register as an anonymous module.
  24. //console.log("jquery.fmatter AMD");
  25. define([
  26. "jquery",
  27. "./grid.base"
  28. ], function ($) {
  29. //console.log("jquery.fmatter AMD: define callback");
  30. return factory($);
  31. });
  32. } else if (typeof module === "object" && module.exports) {
  33. // Node/CommonJS
  34. //console.log("jquery.fmatter CommonJS");
  35. module.exports = function (root, $) {
  36. //console.log("jquery.fmatter CommonJS: in module.exports");
  37. if (!root) {
  38. root = window;
  39. }
  40. //console.log("jquery.fmatter CommonJS: before require('jquery')");
  41. if ($ === undefined) {
  42. // require("jquery") returns a factory that requires window to
  43. // build a jQuery instance, we normalize how we use modules
  44. // that require this pattern but the window provided is a noop
  45. // if it's defined (how jquery works)
  46. $ = typeof window !== "undefined" ?
  47. require("jquery") :
  48. require("jquery")(root);
  49. }
  50. //console.log("jquery.fmatter CommonJS: before require('./grid.base')");
  51. require("./grid.base");
  52. //console.log("jquery.fmatter CommonJS: before factory");
  53. factory($);
  54. return $;
  55. };
  56. } else {
  57. // Browser globals
  58. //console.log("jquery.fmatter Browser: before factory");
  59. factory(jQuery);
  60. }
  61. }(function ($) {
  62. "use strict";
  63. $.jgrid = $.jgrid || {};
  64. var jgrid = $.jgrid, getGridRes = jgrid.getMethod("getGridRes"), base = $.fn.jqGrid;
  65. // begin module jquery.fmatter
  66. $.fmatter = $.fmatter || {};
  67. var fmatter = $.fmatter,
  68. getOptionByName = function (colModel, name) {
  69. var option = colModel.formatoptions || {};
  70. if (option.hasOwnProperty(name)) {
  71. return option[name];
  72. } else {
  73. return (colModel.editoptions || {})[name];
  74. }
  75. },
  76. encodeAttr = function (v) {
  77. return String(v).replace(/\'/g, "'");
  78. },
  79. parseCheckboxOptions = function (options) {
  80. var colModel = options.colModel || options.cm, checked, unchecked,
  81. title = colModel.title !== false ?
  82. " title='" + encodeAttr(options.colName || colModel.name) + "'" :
  83. "",
  84. getOption = function (name) {
  85. return getOptionByName(colModel, name);
  86. },
  87. checkedClasses = getOption("checkedClass"),
  88. uncheckedClasses = getOption("uncheckedClass"),
  89. value = getOption("value"),
  90. yes = typeof value === "string" ? (value.split(":")[0] || "Yes") : "Yes",
  91. no = typeof value === "string" ? (value.split(":")[1] || "No") : "No",
  92. buildCheckbox = function (classes) {
  93. return "<i class='" + encodeAttr(classes) + "'" + title + "></i>";
  94. },
  95. disabled = getOption("disabled");
  96. if (disabled === undefined) {
  97. disabled = jgrid.formatter.checkbox.disabled;
  98. }
  99. var checkedIcon = base.getIconRes.call(this, "checkbox.checked"),
  100. checkedIconClasses = base.getIconRes.call(this, "checkbox.checkedClasses"),
  101. uncheckedIcon = base.getIconRes.call(this, "checkbox.unchecked");
  102. if (disabled === true && (checkedClasses || uncheckedClasses || checkedIcon || uncheckedIcon)) {
  103. checked = buildCheckbox(checkedClasses || checkedIcon);
  104. unchecked = buildCheckbox(uncheckedClasses || uncheckedIcon);
  105. checkedClasses = checkedIconClasses ? checkedIconClasses : checkedClasses || checkedIcon;
  106. } else {
  107. checkedClasses = "";
  108. title += disabled === true ? " disabled='disabled'" : "";
  109. checked = "<input type='checkbox' checked='checked'" + title + " />";
  110. unchecked = "<input type='checkbox'" + title + " />";
  111. }
  112. return {
  113. checkedClasses: checkedClasses,
  114. checked: checked,
  115. unchecked: unchecked,
  116. yes: yes,
  117. no: no
  118. };
  119. },
  120. // http://jsperf.com/regex-vs-indexof-vs-in/12
  121. /*yesObject = Object.create(null, {
  122. 1: { value: 1 },
  123. x: { value: 1 },
  124. "true": { value: 1 },
  125. yes: { value: 1 },
  126. on: { value: 1 }
  127. }),
  128. noObject = Object.create(null, {
  129. 0: { value: 1 },
  130. "false": { value: 1 },
  131. no: { value: 1 },
  132. off: { value: 1 }
  133. });*/
  134. // one can use typeof Object.create != "function" and use either
  135. // Object.create or simple object firm, but the performance differences
  136. // are so low, that the compatibility to IE8 is more important
  137. yesObject = { 1: 1, x: 1, "true": 1, yes: 1, y: 1, on: 1 },
  138. noObject = { 0: 1, "false": 1, no: 1, n: 1, off: 1 };
  139. $.extend(true, jgrid, {
  140. formatter: { // setting common formatter settings, which are independent from the language and locale
  141. date: {
  142. parseRe: /[#%\\\/:_;.,\t\s\-]/,
  143. masks: {
  144. ISO8601Long: "Y-m-d H:i:s",
  145. ISO8601Short: "Y-m-d",
  146. SortableDateTime: "Y-m-d\\TH:i:s",
  147. UniversalSortableDateTime: "Y-m-d H:i:sO"
  148. },
  149. reformatAfterEdit: true,
  150. userLocalTime: false
  151. },
  152. baseLinkUrl: "",
  153. showAction: "",
  154. target: "",
  155. checkbox: { disabled: true, defaultValue: false },
  156. idName: "id"
  157. },
  158. cmTemplate: {
  159. integerStr: {
  160. formatter: "integer", align: "right", sorttype: "integer",
  161. searchoptions: { sopt: ["eq", "ne", "lt", "le", "gt", "ge"] }
  162. },
  163. integer: {
  164. formatter: "integer", align: "right", sorttype: "integer",
  165. convertOnSave: function (options) {
  166. var nData = options.newValue;
  167. return isNaN(nData) ? nData : parseInt(nData, 10);
  168. },
  169. searchoptions: { sopt: ["eq", "ne", "lt", "le", "gt", "ge"] }
  170. },
  171. numberStr: {
  172. formatter: "number", align: "right", sorttype: "number",
  173. searchoptions: { sopt: ["eq", "ne", "lt", "le", "gt", "ge"] }
  174. },
  175. number: {
  176. formatter: "number", align: "right", sorttype: "number",
  177. convertOnSave: function (options) {
  178. var nData = options.newValue;
  179. return isNaN(nData) ? nData : parseFloat(nData);
  180. },
  181. searchoptions: { sopt: ["eq", "ne", "lt", "le", "gt", "ge"] }
  182. },
  183. booleanCheckbox: {
  184. align: "center", formatter: "checkbox", sorttype: "boolean",
  185. edittype: "checkbox", editoptions: { value: "true:false", defaultValue: "false" },
  186. convertOnSave: function (options) {
  187. var newValue = options.newValue,
  188. checkboxOptions = parseCheckboxOptions.call(this, options),
  189. lowerCaseNewData = String(newValue).toLowerCase();
  190. if (yesObject[lowerCaseNewData] || lowerCaseNewData === checkboxOptions.yes.toLowerCase()) {
  191. newValue = true;
  192. } else if (noObject[lowerCaseNewData] || lowerCaseNewData === checkboxOptions.no.toLowerCase()) {
  193. newValue = false;
  194. }
  195. return newValue;
  196. },
  197. stype: "checkbox", searchoptions: { sopt: ["eq"], value: "true:false" }
  198. },
  199. // TODO: add cmTemplate for currency and date
  200. actions: function () {
  201. var p = this.p;
  202. return {
  203. formatter: "actions",
  204. width: (p != null && (base.isInCommonIconClass.call(this, "fa") || base.isInCommonIconClass.call(this, "glyphicon")) ?
  205. ($(this).jqGrid("isBootstrapGuiStyle") ? 45 : 39) : 40) + (jgrid.cellWidth() ? 5 : 0),
  206. align: "center",
  207. label: "",
  208. autoResizable: false,
  209. title: false,
  210. frozen: true,
  211. fixed: true,
  212. hidedlg: true,
  213. resizable: false,
  214. sortable: false,
  215. search: false,
  216. editable: false,
  217. viewable: false
  218. };
  219. }
  220. }
  221. });
  222. jgrid.cmTemplate.booleanCheckboxFa = jgrid.cmTemplate.booleanCheckbox;
  223. //opts can be id:row id for the row, rowdata:the data for the row, colmodel:the column model for this column
  224. //example {id:1234,}
  225. $.extend(fmatter, {
  226. // one can consider to use $.type instead of some functions below (see http://api.jquery.com/jQuery.type/)
  227. isObject: function (o) {
  228. return (o && (typeof o === "object" || $.isFunction(o))) || false;
  229. },
  230. isNumber: function (o) {
  231. // probably Number.isFinite can be used instead.
  232. return typeof o === "number" && isFinite(o); // return false for +infinity, -infinity, or NaN
  233. },
  234. isValue: function (o) {
  235. return (this.isObject(o) || typeof o === "string" || this.isNumber(o) || typeof o === "boolean");
  236. },
  237. isEmpty: function (o) {
  238. if (typeof o !== "string" && this.isValue(o)) {
  239. return false;
  240. }
  241. if (!this.isValue(o)) {
  242. return true;
  243. }
  244. o = $.trim(o).replace(/&nbsp;/ig, "").replace(/&#160;/ig, "");
  245. return o === "";
  246. },
  247. NumberFormat: function (nData, opts) {
  248. var isNumber = fmatter.isNumber;
  249. if (!isNumber(nData)) {
  250. nData *= 1;
  251. }
  252. if (isNumber(nData)) {
  253. var bNegative = (nData < 0);
  254. var sOutput = String(nData);
  255. var sDecimalSeparator = opts.decimalSeparator || ".";
  256. var nDotIndex;
  257. if (isNumber(opts.decimalPlaces)) {
  258. // Round to the correct decimal place
  259. var nDecimalPlaces = opts.decimalPlaces;
  260. // we use rounding described in http://www.jacklmoore.com/notes/rounding-in-javascript/
  261. sOutput = String(Number(Math.round(nData + "e" + nDecimalPlaces) + "e-" + nDecimalPlaces));
  262. nDotIndex = sOutput.lastIndexOf(".");
  263. if (nDecimalPlaces > 0) {
  264. // Add the decimal separator
  265. if (nDotIndex < 0) {
  266. sOutput += sDecimalSeparator;
  267. nDotIndex = sOutput.length - 1;
  268. } else if (sDecimalSeparator !== ".") { // Replace the "."
  269. sOutput = sOutput.replace(".", sDecimalSeparator);
  270. }
  271. // Add missing zeros
  272. while ((sOutput.length - 1 - nDotIndex) < nDecimalPlaces) {
  273. sOutput += "0";
  274. }
  275. }
  276. }
  277. if (opts.thousandsSeparator) {
  278. var sThousandsSeparator = opts.thousandsSeparator;
  279. nDotIndex = sOutput.lastIndexOf(sDecimalSeparator);
  280. nDotIndex = (nDotIndex > -1) ? nDotIndex : sOutput.length;
  281. // we cut the part after the point for integer numbers
  282. // it will prevent storing/restoring of wrong numbers during inline editing
  283. var sNewOutput = opts.decimalSeparator === undefined ? "" : sOutput.substring(nDotIndex);
  284. var nCount = -1, i;
  285. for (i = nDotIndex; i > 0; i--) {
  286. nCount++;
  287. if ((nCount % 3 === 0) && (i !== nDotIndex) && (!bNegative || (i > 1))) {
  288. sNewOutput = sThousandsSeparator + sNewOutput;
  289. }
  290. sNewOutput = sOutput.charAt(i - 1) + sNewOutput;
  291. }
  292. sOutput = sNewOutput;
  293. }
  294. return sOutput;
  295. }
  296. return nData;
  297. }
  298. });
  299. var $FnFmatter = function (formatType, cellval, opts, rwd, act) {
  300. // build main options before element iteration
  301. var v = cellval;
  302. opts = $.extend({}, getGridRes.call($(this), "formatter"), opts);
  303. try {
  304. v = $.fn.fmatter[formatType].call(this, cellval, opts, rwd, act);
  305. } catch (ignore) { }
  306. return v;
  307. };
  308. $.fn.fmatter = $FnFmatter;
  309. $FnFmatter.getCellBuilder = function (formatType, opts, act) {
  310. var cellBuilder = $.fn.fmatter[formatType] != null ? $.fn.fmatter[formatType].getCellBuilder : null;
  311. return $.isFunction(cellBuilder) ?
  312. cellBuilder.call(this, $.extend({}, getGridRes.call($(this), "formatter"), opts), act) :
  313. null;
  314. };
  315. $FnFmatter.defaultFormat = function (cellval, opts) {
  316. return (fmatter.isValue(cellval) && cellval !== "") ? cellval : opts.defaultValue || "&#160;";
  317. };
  318. var defaultFormat = $FnFmatter.defaultFormat,
  319. formatCheckboxValue = function (cellValue, checkboxOptions, colModel) {
  320. if (cellValue === undefined || fmatter.isEmpty(cellValue)) {
  321. var defaultValue = getOptionByName(colModel, "defaultValue");
  322. if (defaultValue === undefined) {
  323. defaultValue = checkboxOptions.no;
  324. }
  325. cellValue = defaultValue;
  326. }
  327. // see http://jsperf.com/regex-vs-indexof-vs-in/12
  328. cellValue = String(cellValue).toLowerCase();
  329. return yesObject[cellValue] || cellValue === checkboxOptions.yes.toLowerCase() ?
  330. checkboxOptions.checked :
  331. checkboxOptions.unchecked;
  332. };
  333. $FnFmatter.email = function (cellval, opts) {
  334. if (!fmatter.isEmpty(cellval)) {
  335. return "<a href='mailto:" + encodeAttr(cellval) + "'>" + cellval + "</a>";
  336. }
  337. return defaultFormat(cellval, opts);
  338. };
  339. $FnFmatter.checkbox = function (cellValue, options) {
  340. var checkboxOptions = parseCheckboxOptions.call(this, options);
  341. return formatCheckboxValue(cellValue, checkboxOptions, options.colModel);
  342. };
  343. $FnFmatter.checkbox.getCellBuilder = function (options) {
  344. var checkboxOptions, colModel = options.colModel;
  345. options.colName = options.colName || this.p.colNames[options.pos];
  346. checkboxOptions = parseCheckboxOptions.call(this, options);
  347. return function (cellValue) {
  348. return formatCheckboxValue(cellValue, checkboxOptions, colModel);
  349. };
  350. };
  351. $FnFmatter.checkbox.unformat = function (cellValue, options, elem) {
  352. var checkboxOptions = parseCheckboxOptions.call(this, options),
  353. $elem = $(elem);
  354. return (checkboxOptions.checkedClasses ?
  355. jgrid.hasAllClasses($elem.children("i,svg"), checkboxOptions.checkedClasses) :
  356. $elem.children("input").is(":checked")) ?
  357. checkboxOptions.yes :
  358. checkboxOptions.no;
  359. };
  360. $FnFmatter.checkboxFontAwesome4 = $FnFmatter.checkbox;
  361. $FnFmatter.checkboxFontAwesome4.getCellBuilder = $FnFmatter.checkbox.getCellBuilder;
  362. $FnFmatter.checkboxFontAwesome4.unformat = $FnFmatter.checkbox.unformat;
  363. $FnFmatter.link = function (cellval, opts) {
  364. var colModel = opts.colModel, target = "", op = { target: opts.target };
  365. if (colModel != null) {
  366. op = $.extend({}, op, colModel.formatoptions || {});
  367. }
  368. if (op.target) { target = "target=" + op.target; }
  369. if (!fmatter.isEmpty(cellval)) {
  370. return "<a " + target + " href='" + encodeAttr(cellval) + "'>" + cellval + "</a>";
  371. }
  372. return defaultFormat(cellval, op);
  373. };
  374. $FnFmatter.showlink = function (cellval, opts, rowData) {
  375. var self = this, colModel = opts.colModel,
  376. op = {
  377. baseLinkUrl: opts.baseLinkUrl,
  378. showAction: opts.showAction,
  379. addParam: opts.addParam || "",
  380. target: opts.target,
  381. idName: opts.idName,
  382. hrefDefaultValue: "#"
  383. },
  384. target = "",
  385. idUrl,
  386. idParam,
  387. addParam,
  388. getOptionValue = function (option) {
  389. return $.isFunction(option) ?
  390. option.call(self, {
  391. cellValue: cellval,
  392. rowid: opts.rowId,
  393. rowData: rowData,
  394. options: op
  395. }) :
  396. option || "";
  397. };
  398. if (colModel != null) {
  399. op = $.extend({}, op, colModel.formatoptions || {});
  400. }
  401. if (op.target) {
  402. target = "target=" + getOptionValue(op.target);
  403. }
  404. idUrl = getOptionValue(op.baseLinkUrl) + getOptionValue(op.showAction);
  405. idParam = op.idName ? encodeURIComponent(getOptionValue(op.idName)) + "=" + encodeURIComponent(getOptionValue(op.rowId) || opts.rowId) : "";
  406. addParam = getOptionValue(op.addParam);
  407. if (typeof addParam === "object" && addParam !== null) {
  408. // add "&" only in case of usage object for of addParam
  409. addParam = (idParam !== "" ? "&" : "") + $.param(addParam);
  410. }
  411. idUrl += !idParam && !addParam ? "" : "?" + idParam + addParam;
  412. if (idUrl === "") {
  413. idUrl = getOptionValue(op.hrefDefaultValue);
  414. }
  415. if (typeof cellval === "string" || fmatter.isNumber(cellval) || $.isFunction(op.cellValue)) {
  416. //add this one even if cellval is blank string
  417. return "<a " + target + " href='" + encodeAttr(idUrl) + "'>" +
  418. ($.isFunction(op.cellValue) ? getOptionValue(op.cellValue) : cellval) +
  419. "</a>";
  420. }
  421. // the code below will be called typically for undefined cellval or
  422. // if cellval have null value or some other unclear value like an object
  423. // and no cellValue callback function are defined "to decode" the value
  424. return defaultFormat(cellval, op);
  425. };
  426. $FnFmatter.showlink.getCellBuilder = function (opts1) {
  427. var op = {
  428. baseLinkUrl: opts1.baseLinkUrl,
  429. showAction: opts1.showAction,
  430. addParam: opts1.addParam || "",
  431. target: opts1.target,
  432. idName: opts1.idName,
  433. hrefDefaultValue: "#"
  434. },
  435. colModel = opts1.colModel;
  436. if (colModel != null) {
  437. op = $.extend({}, op, colModel.formatoptions || {});
  438. }
  439. return function (cellval, opts, rowData) {
  440. var self = this, rowid = opts.rowId, target = "", idUrl, idParam, addParam,
  441. getOptionValue = function (option) {
  442. return $.isFunction(option) ?
  443. option.call(self, {
  444. cellValue: cellval,
  445. rowid: rowid,
  446. rowData: rowData,
  447. options: op
  448. }) :
  449. option || "";
  450. };
  451. if (op.target) {
  452. target = "target=" + getOptionValue(op.target);
  453. }
  454. idUrl = getOptionValue(op.baseLinkUrl) + getOptionValue(op.showAction);
  455. idParam = op.idName ? encodeURIComponent(getOptionValue(op.idName)) + "=" + encodeURIComponent(getOptionValue(rowid) || opts.rowId) : "";
  456. addParam = getOptionValue(op.addParam);
  457. if (typeof addParam === "object" && addParam !== null) {
  458. // add "&" only in case of usage object for of addParam
  459. addParam = (idParam !== "" ? "&" : "") + $.param(addParam);
  460. }
  461. idUrl += !idParam && !addParam ? "" : "?" + idParam + addParam;
  462. if (idUrl === "") {
  463. idUrl = getOptionValue(op.hrefDefaultValue);
  464. }
  465. if (typeof cellval === "string" || fmatter.isNumber(cellval) || $.isFunction(op.cellValue)) {
  466. //add this one even if cellval is blank string
  467. return "<a " + target + " href='" + encodeAttr(idUrl) + "'>" +
  468. ($.isFunction(op.cellValue) ? getOptionValue(op.cellValue) : cellval) +
  469. "</a>";
  470. }
  471. // the code below will be called typically for undefined cellval or
  472. // if cellval have null value or some other unclear value like an object
  473. // and no cellValue callback function are defined "to decode" the value
  474. return defaultFormat(cellval, op);
  475. };
  476. };
  477. $FnFmatter.showlink.pageFinalization = function (iCol) {
  478. var $self = $(this), p = this.p, cm = p.colModel[iCol],
  479. wrapperClassName = p.autoResizing.wrapperClassName,
  480. iRow, rows = this.rows, nRows = rows.length, row, td,
  481. onClick = function (e) {
  482. var $td = $(this).closest("tr.jqgrow>td"), $tr = $td.parent(), iCol = $td[0].cellIndex, cm = p.colModel[iCol];
  483. if ($tr.length > 0) {
  484. return cm.formatoptions.onClick.call($self[0], {
  485. iCol: iCol,
  486. iRow: $tr[0].rowIndex,
  487. rowid: $tr.attr("id"),
  488. cm: cm,
  489. cmName: cm.name,
  490. cellValue: $(this).text(),
  491. a: this,
  492. event: e
  493. });
  494. }
  495. };
  496. if (cm.formatoptions != null && $.isFunction(cm.formatoptions.onClick)) {
  497. for (iRow = 0; iRow < nRows; iRow++) {
  498. row = rows[iRow];
  499. if ($(row).hasClass("jqgrow")) {
  500. td = row.cells[iCol];
  501. if (cm.autoResizable && td != null && $(td.firstChild).hasClass(wrapperClassName)) {
  502. td = td.firstChild;
  503. }
  504. if (td != null) {
  505. $(td.firstChild).on("click", onClick);
  506. }
  507. }
  508. }
  509. }
  510. };
  511. var insertPrefixAndSuffix = function (sOutput, opts) {
  512. // Prepend prefix
  513. sOutput = (opts.prefix) ? opts.prefix + sOutput : sOutput;
  514. // Append suffix
  515. return (opts.suffix) ? sOutput + opts.suffix : sOutput;
  516. },
  517. numberHelper = function (cellval, opts, formatType) {
  518. var colModel = opts.colModel, op = $.extend({}, opts[formatType]);
  519. if (colModel != null) {
  520. op = $.extend({}, op, colModel.formatoptions || {});
  521. }
  522. if (fmatter.isEmpty(cellval)) {
  523. return insertPrefixAndSuffix(op.defaultValue, op);
  524. }
  525. return insertPrefixAndSuffix(fmatter.NumberFormat(cellval, op), op);
  526. };
  527. $FnFmatter.integer = function (cellval, opts) {
  528. return numberHelper(cellval, opts, "integer");
  529. };
  530. $FnFmatter.number = function (cellval, opts) {
  531. return numberHelper(cellval, opts, "number");
  532. };
  533. $FnFmatter.currency = function (cellval, opts) {
  534. return numberHelper(cellval, opts, "currency");
  535. };
  536. var numberCellBuilder = function (opts, formatType) {
  537. var colModel = opts.colModel, op = $.extend({}, opts[formatType]);
  538. if (colModel != null) {
  539. op = $.extend({}, op, colModel.formatoptions || {});
  540. }
  541. var numberFormat = fmatter.NumberFormat,
  542. defaultValue = op.defaultValue ? insertPrefixAndSuffix(op.defaultValue, op) : "";
  543. return function (cellValue) {
  544. if (fmatter.isEmpty(cellValue)) { return defaultValue; }
  545. return insertPrefixAndSuffix(numberFormat(cellValue, op), op);
  546. };
  547. };
  548. $FnFmatter.integer.getCellBuilder = function (options) {
  549. return numberCellBuilder(options, "integer");
  550. };
  551. $FnFmatter.number.getCellBuilder = function (options) {
  552. return numberCellBuilder(options, "number");
  553. };
  554. $FnFmatter.currency.getCellBuilder = function (options) {
  555. return numberCellBuilder(options, "currency");
  556. };
  557. $FnFmatter.date = function (cellval, opts, rwd, act) {
  558. var colModel = opts.colModel, op = $.extend({}, opts.date);
  559. if (colModel != null) {
  560. op = $.extend({}, op, colModel.formatoptions || {});
  561. }
  562. if (!op.reformatAfterEdit && act === "edit") {
  563. return defaultFormat(cellval, op);
  564. }
  565. if (!fmatter.isEmpty(cellval)) {
  566. return jgrid.parseDate.call(this, op.srcformat, cellval, op.newformat, op);
  567. }
  568. return defaultFormat(cellval, op);
  569. };
  570. $FnFmatter.date.getCellBuilder = function (opts, act) {
  571. var op = $.extend({}, opts.date);
  572. if (opts.colModel != null) {
  573. op = $.extend({}, op, opts.colModel.formatoptions || {});
  574. }
  575. var parseDate = jgrid.parseDate,
  576. srcformat = op.srcformat, newformat = op.newformat;
  577. if (!op.reformatAfterEdit && act === "edit") {
  578. return function (cellValue) {
  579. return defaultFormat(cellValue, op);
  580. };
  581. }
  582. return function (cellValue) {
  583. return fmatter.isEmpty(cellValue) ?
  584. defaultFormat(cellValue, op) :
  585. parseDate.call(this, srcformat, cellValue, newformat, op);
  586. };
  587. };
  588. $FnFmatter.select = function (cellval, opts) {
  589. var ret = [], colModel = opts.colModel, defaultValue,
  590. op = $.extend({}, colModel.editoptions || {}, colModel.formatoptions || {}),
  591. oSelect = typeof op.value === "function" ? op.value() : op.value, sep = op.separator || ":", delim = op.delimiter || ";";
  592. if (oSelect) {
  593. var msl = op.multiple === true ? true : false, scell = [], sv,
  594. mapFunc = function (n, j) { if (j > 0) { return n; } };
  595. if (msl) {
  596. scell = $.map(String(cellval).split(","), function (n) { return $.trim(n); });
  597. }
  598. if (typeof oSelect === "string") {
  599. // maybe here we can use some caching with care ????
  600. var so = oSelect.split(delim), i, v;
  601. for (i = 0; i < so.length; i++) {
  602. sv = so[i].split(sep);
  603. if (sv.length > 2) {
  604. sv[1] = $.map(sv, mapFunc).join(sep);
  605. }
  606. v = $.trim(sv[0]);
  607. if (op.defaultValue === v) {
  608. defaultValue = sv[1];
  609. }
  610. if (msl) {
  611. if ($.inArray(v, scell) > -1) {
  612. ret.push(sv[1]);
  613. }
  614. } else if (v === $.trim(cellval)) {
  615. ret = [sv[1]];
  616. break;
  617. }
  618. }
  619. } else if (fmatter.isObject(oSelect)) {
  620. defaultValue = oSelect[op.defaultValue];
  621. if (msl) {
  622. ret = $.map(scell, function (n) {
  623. return oSelect[n];
  624. });
  625. } else {
  626. ret = [oSelect[cellval] === undefined ? "" : oSelect[cellval]];
  627. }
  628. }
  629. }
  630. cellval = ret.join(", ");
  631. return cellval !== "" ? cellval :
  632. (op.defaultValue !== undefined ? defaultValue : defaultFormat(cellval, op));
  633. };
  634. $FnFmatter.select.getCellBuilder = function (opts) {
  635. // jqGrid specific
  636. var colModel = opts.colModel, $fnDefaultFormat = $FnFmatter.defaultFormat,
  637. op = $.extend({}, colModel.editoptions || {}, colModel.formatoptions || {}),
  638. oSelect = typeof op.value === "function" ? op.value() : op.value, sep = op.separator || ":", delim = op.delimiter || ";",
  639. defaultValue, defaultValueDefined = op.defaultValue !== undefined,
  640. isMultiple = op.multiple === true ? true : false, sv, so, i, nOpts, selOptions = {},
  641. mapFunc = function (n, j) { if (j > 0) { return n; } };
  642. if (typeof oSelect === "string") {
  643. // maybe here we can use some caching with care ????
  644. so = oSelect.split(delim);
  645. nOpts = so.length;
  646. for (i = nOpts - 1; i >= 0; i--) {
  647. sv = so[i].split(sep);
  648. if (sv.length > 2) {
  649. sv[1] = $.map(sv, mapFunc).join(sep);
  650. }
  651. selOptions[$.trim(sv[0])] = sv[1];
  652. }
  653. } else if (fmatter.isObject(oSelect)) {
  654. selOptions = oSelect;
  655. } else {
  656. return function (cellValue) {
  657. return cellValue ? String(cellValue) : $fnDefaultFormat(cellValue, op);
  658. };
  659. }
  660. if (defaultValueDefined) {
  661. defaultValue = selOptions[op.defaultValue];
  662. }
  663. return isMultiple ?
  664. function (cellValue) {
  665. var ret = [], iOpt,
  666. splitedCell = $.map(String(cellValue).split(","), function (n) { return $.trim(n); });
  667. for (iOpt = 0; iOpt < splitedCell.length; iOpt++) {
  668. cellValue = splitedCell[iOpt];
  669. if (selOptions.hasOwnProperty(cellValue)) {
  670. ret.push(selOptions[cellValue]);
  671. }
  672. }
  673. cellValue = ret.join(", ");
  674. return cellValue !== "" ? cellValue :
  675. (defaultValueDefined ? defaultValue : $fnDefaultFormat(cellValue, op));
  676. } :
  677. function (cellValue) {
  678. var ret = selOptions[String(cellValue)];
  679. return ret !== "" && ret !== undefined ? ret :
  680. (defaultValueDefined ? defaultValue : $fnDefaultFormat(cellValue, op));
  681. };
  682. };
  683. $FnFmatter.rowactions = function (e, act) {
  684. var $td = $(this).closest("tr.jqgrow>td"), $tr = $td.parent(), rid = $tr.attr("id"),
  685. $id = $(this).closest("table.ui-jqgrid-btable").attr("id").replace(/_frozen([^_]*)$/, "$1"),
  686. $grid = $("#" + jgrid.jqID($id)), $t = $grid[0], p = $t.p, i, n, customAction, actop,
  687. relativeTop = jgrid.getRelativeRect.call($t, $tr).top,
  688. cm = p.colModel[$td[0].cellIndex],
  689. op = $.extend(true, { extraparam: {} }, jgrid.actionsNav || {}, p.actionsNavOptions || {}, cm.formatoptions || {});
  690. if (p.editOptions !== undefined) {
  691. op.editOptions = $.extend(true, op.editOptions || {}, p.editOptions);
  692. }
  693. if (p.delOptions !== undefined) {
  694. op.delOptions = p.delOptions;
  695. }
  696. if ($tr.hasClass("jqgrid-new-row")) {
  697. op.extraparam[p.prmNames.oper] = p.prmNames.addoper;
  698. }
  699. actop = {
  700. keys: op.keys,
  701. oneditfunc: op.onEdit,
  702. successfunc: op.onSuccess,
  703. url: op.url,
  704. extraparam: op.extraparam,
  705. aftersavefunc: op.afterSave,
  706. errorfunc: op.onError,
  707. afterrestorefunc: op.afterRestore,
  708. restoreAfterError: op.restoreAfterError,
  709. mtype: op.mtype
  710. };
  711. if ((!p.multiselect && rid !== p.selrow) || (p.multiselect && $.inArray(rid, p.selarrrow) < 0)) {
  712. $grid.jqGrid("setSelection", rid, true, e);
  713. } else {
  714. jgrid.fullBoolFeedback.call($t, "onSelectRow", "jqGridSelectRow", rid, true, e);
  715. }
  716. switch (act) {
  717. case "edit":
  718. $grid.jqGrid("editRow", rid, actop);
  719. break;
  720. case "save":
  721. $grid.jqGrid("saveRow", rid, actop);
  722. break;
  723. case "cancel":
  724. $grid.jqGrid("restoreRow", rid, op.afterRestore);
  725. break;
  726. case "del":
  727. op.delOptions = op.delOptions || {};
  728. if (op.delOptions.top === undefined) {
  729. op.delOptions.top = relativeTop;
  730. }
  731. $grid.jqGrid("delGridRow", rid, op.delOptions);
  732. break;
  733. case "formedit":
  734. op.editOptions = op.editOptions || {};
  735. if (op.editOptions.top === undefined) {
  736. op.editOptions.top = relativeTop;
  737. op.editOptions.recreateForm = true;
  738. }
  739. $grid.jqGrid("editGridRow", rid, op.editOptions);
  740. break;
  741. default:
  742. if (op.custom != null && op.custom.length > 0) {
  743. n = op.custom.length;
  744. for (i = 0; i < n; i++) {
  745. customAction = op.custom[i];
  746. if (customAction.action === act && $.isFunction(customAction.onClick)) {
  747. customAction.onClick.call($t, { rowid: rid, event: e, action: act, options: customAction });
  748. }
  749. }
  750. }
  751. }
  752. if (e.stopPropagation) {
  753. e.stopPropagation();
  754. }
  755. return false; // prevent other processing of the click on the row
  756. };
  757. $FnFmatter.actions = function (cellval, opts, rwd, act) {
  758. var rowid = opts.rowId, str = "", $t = this, $self = $($t), i, info, customAction, displayMask = {},
  759. edit = getGridRes.call($self, "edit") || {},
  760. op = $.extend({
  761. editbutton: true,
  762. delbutton: true,
  763. editformbutton: false,
  764. commonIconClass: "ui-icon",
  765. editicon: "ui-icon-pencil",
  766. delicon: "ui-icon-trash",
  767. saveicon: "ui-icon-disk",
  768. cancelicon: "ui-icon-cancel",
  769. savetitle: edit.bSubmit || "",
  770. canceltitle: edit.bCancel || ""
  771. },
  772. getGridRes.call($self, "nav") || {},
  773. jgrid.nav || {},
  774. $t.p.navOptions || {},
  775. getGridRes.call($self, "actionsNav") || {},
  776. jgrid.actionsNav || {},
  777. $t.p.actionsNavOptions || {},
  778. (opts.colModel || {}).formatoptions || {}),
  779. cssIconClass = function (name) {
  780. return jgrid.mergeCssClasses(op.commonIconClass, op[name + "icon"]);
  781. },
  782. buttonInfos = [
  783. { action: "edit", actionName: "formedit", display: op.editformbutton },
  784. { action: "edit", display: !op.editformbutton && op.editbutton },
  785. { action: "del", idPrefix: "Delete", display: op.delbutton },
  786. { action: "save", display: op.editformbutton || op.editbutton, hidden: true },
  787. { action: "cancel", display: op.editformbutton || op.editbutton, hidden: true }
  788. ],
  789. actionButton = function (options) {
  790. var action = options.action, actionName = options.actionName || action,
  791. idPrefix = options.idPrefix !== undefined ? options.idPrefix : (action.charAt(0).toUpperCase() + action.substring(1));
  792. return "<div title='" + encodeAttr(op[action + "title"]) +
  793. (options.hidden ? "' style='display:none;" : "") +
  794. "' class='" + encodeAttr($self.jqGrid("getGuiStyles", "actionsButton", "ui-pg-div ui-inline-" + action)) + "' " +
  795. (idPrefix !== null ? "id='j" + encodeAttr(idPrefix + "Button_" + rowid) : "") +
  796. "' data-jqactionname=\"" + actionName + "\" " +
  797. (options.noHovering ? "" : "' data-jqhovering=\"1\" ") +
  798. "><span class='" +
  799. encodeAttr(cssIconClass(action)) + "'></span></div>";
  800. },
  801. n = op.custom != null ? op.custom.length - 1 : -1;
  802. if (rowid === undefined || fmatter.isEmpty(rowid)) { return ""; }
  803. if ($.isFunction(op.isDisplayButtons)) {
  804. try {
  805. displayMask = op.isDisplayButtons.call(this, op, rwd, act) || {};
  806. } catch (ignore) {}
  807. }
  808. while (n >= 0) {
  809. customAction = op.custom[n--];
  810. buttonInfos[customAction.position === "first" ? "unshift" : "push"](customAction);
  811. }
  812. for (i = 0, n = buttonInfos.length; i < n; i++) {
  813. info = $.extend({}, buttonInfos[i], displayMask[buttonInfos[i].action] || {});
  814. if (info.display !== false) {
  815. str += actionButton(info);
  816. }
  817. }
  818. return "<div class='" + encodeAttr($self.jqGrid("getGuiStyles", "actionsDiv", "ui-jqgrid-actions")) + "'>" + str + "</div>";
  819. };
  820. $FnFmatter.actions.pageFinalization = function (iCol) {
  821. var $self = $(this), p = this.p, cm = p.colModel[iCol],
  822. wrapperClassName = p.autoResizing.wrapperClassName,
  823. hoverClass = $self.jqGrid("getGuiStyles", "states.hover"),
  824. iRow, rows = this.rows, fbRows = this.grid.fbRows, nRows = rows.length, row,
  825. showHideEditDelete = (function (cmName) {
  826. return function (show, tr) {
  827. var maxfrozen = 0, $actionsDiv, colModel = p.colModel, len = colModel.length, i, iCol = p.iColByName[cmName];
  828. for (i = 0; i < len; i++) {
  829. // from left, no breaking frozen
  830. if (colModel[i].frozen !== true) {
  831. break;
  832. }
  833. maxfrozen = i;
  834. }
  835. if (tr != null && tr.cells != null) {
  836. $actionsDiv = $(tr.cells[iCol]).children(".ui-jqgrid-actions");
  837. if (colModel[iCol].frozen && p.frozenColumns && iCol <= maxfrozen) {
  838. // uses the corresponding tr from frozen div with the same rowIndex ADDITIONALLY
  839. // to the standard action div
  840. $actionsDiv = $actionsDiv
  841. .add($($self[0].grid.fbRows[tr.rowIndex].cells[iCol])
  842. .children(".ui-jqgrid-actions"));
  843. }
  844. if (show) {
  845. $actionsDiv.find(">.ui-inline-edit,>.ui-inline-del").show();
  846. $actionsDiv.find(">.ui-inline-save,>.ui-inline-cancel").hide();
  847. } else {
  848. $actionsDiv.find(">.ui-inline-edit,>.ui-inline-del").hide();
  849. $actionsDiv.find(">.ui-inline-save,>.ui-inline-cancel").show();
  850. }
  851. }
  852. };
  853. })(cm.name),
  854. showEditDelete = function (e, rowid) {
  855. var tr = $self.jqGrid("getGridRowById", rowid);
  856. showHideEditDelete(true, tr);
  857. return false;
  858. },
  859. hideEditDelete = function (e, rowid) {
  860. var tr = $self.jqGrid("getGridRowById", rowid);
  861. showHideEditDelete(false, tr);
  862. return false;
  863. },
  864. onMouseOver = function (e) {
  865. if ($(e.target).closest("div.ui-pg-div").data("jqhovering") === 1) {
  866. $(this).addClass(hoverClass);
  867. }
  868. },
  869. onMouseOut = function (e) {
  870. if ($(e.target).closest("div.ui-pg-div").data("jqhovering") === 1) {
  871. $(this).removeClass(hoverClass);
  872. }
  873. },
  874. onClick = function (e) {
  875. return $FnFmatter.rowactions.call(this, e, $(e.target).closest("div.ui-pg-div").data("jqactionname"));
  876. },
  877. bindEvents = function (td, autoResizable) {
  878. if (autoResizable && td != null && $(td.firstChild).hasClass(wrapperClassName)) {
  879. td = td.firstChild;
  880. }
  881. if (td != null) {
  882. $(td.firstChild).on("click", onClick);
  883. $(td.firstChild).children("div.ui-pg-div")
  884. .on("mouseover", onMouseOver)
  885. .on("mouseout", onMouseOut);
  886. }
  887. },
  888. bindRowEvents = (function (cmName) {
  889. return function (e, options) {
  890. var iColToBind = p.iColByName[cmName]; // it could be changed index because of reordering of columns
  891. bindEvents(options.tr.cells[iColToBind], p.colModel[iColToBind].autoResizable);
  892. };
  893. })(cm.name);
  894. if (cm.formatoptions == null || !cm.formatoptions.editformbutton) {
  895. // we use unbind to be sure that we don't register the same events multiple times
  896. $self.off("jqGridInlineAfterRestoreRow.jqGridFormatter jqGridInlineAfterSaveRow.jqGridFormatter", showEditDelete);
  897. $self.on("jqGridInlineAfterRestoreRow.jqGridFormatter jqGridInlineAfterSaveRow.jqGridFormatter", showEditDelete);
  898. $self.off("jqGridInlineEditRow.jqGridFormatter", hideEditDelete);
  899. $self.on("jqGridInlineEditRow.jqGridFormatter", hideEditDelete);
  900. $self.off("jqGridAfterAddRow.jqGridFormatter", bindRowEvents);
  901. $self.on("jqGridAfterAddRow.jqGridFormatter", bindRowEvents);
  902. }
  903. for (iRow = 0; iRow < nRows; iRow++) {
  904. row = rows[iRow];
  905. if ($(row).hasClass("jqgrow")) {
  906. bindEvents(row.cells[iCol], cm.autoResizable);
  907. if (fbRows != null && fbRows[iRow] != null) {
  908. bindEvents(fbRows[iRow].cells[iCol], cm.autoResizable);
  909. }
  910. }
  911. }
  912. };
  913. $.unformat = function (cellval, options, pos, cnt) {
  914. // specific for jqGrid only
  915. var ret, colModel = options.colModel, formatType = colModel.formatter, p = this.p,
  916. op = colModel.formatoptions || {},// sep,
  917. //re = /([\.\*\_\'\(\)\{\}\+\?\\])/g,
  918. unformatFunc = colModel.unformat || ($FnFmatter[formatType] && $FnFmatter[formatType].unformat);
  919. if (cellval instanceof jQuery && cellval.length > 0) {
  920. cellval = cellval[0];
  921. }
  922. if (p.treeGrid && cellval != null && $(cellval.firstChild).hasClass("tree-wrap") && ($(cellval.lastChild).hasClass("cell-wrapper") || $(cellval.lastChild).hasClass("cell-wrapperleaf"))) {
  923. cellval = cellval.lastChild;
  924. }
  925. if (colModel.autoResizable && cellval != null && $(cellval.firstChild).hasClass(p.autoResizing.wrapperClassName)) {
  926. cellval = cellval.firstChild;
  927. }
  928. if (unformatFunc !== undefined && $.isFunction(unformatFunc)) {
  929. ret = unformatFunc.call(this, $(cellval).text(), options, cellval);
  930. } else if (formatType !== undefined && typeof formatType === "string") {
  931. //var opts = $.extend(true, {}, getRes(locales[p.locale], "formatter"), jgrid.formatter || {}), stripTag;
  932. var $self = $(this), //stripTag, //opts = getGridRes.call($self, "formatter"),
  933. getFormaterOption = function (formatterName, optionName) {
  934. return op[optionName] !== undefined ?
  935. op[optionName] :
  936. getGridRes.call($self, "formatter." + formatterName + "." + optionName);
  937. },
  938. cutThousandsSeparator = function (formatterName, val) {
  939. var separator = getFormaterOption(formatterName, "thousandsSeparator")
  940. .replace(/([\.\*\_\'\(\)\{\}\+\?\\])/g, "\\$1");
  941. return val.replace(new RegExp(separator, "g"), "");
  942. };
  943. switch (formatType) {
  944. case "integer":
  945. ret = cutThousandsSeparator("integer", $(cellval).text());
  946. break;
  947. case "number":
  948. ret = cutThousandsSeparator("number", $(cellval).text())
  949. .replace(getFormaterOption("number", "decimalSeparator"), ".");
  950. break;
  951. case "currency":
  952. ret = $(cellval).text();
  953. var prefix = getFormaterOption("currency", "prefix"),
  954. suffix = getFormaterOption("currency", "suffix");
  955. if (prefix && prefix.length) {
  956. ret = ret.substr(prefix.length);
  957. }
  958. if (suffix && suffix.length) {
  959. ret = ret.substr(0, ret.length - suffix.length);
  960. }
  961. ret = cutThousandsSeparator("number", ret)
  962. .replace(getFormaterOption("number", "decimalSeparator"), ".");
  963. break;
  964. case "checkbox":
  965. ret = $FnFmatter.checkbox.unformat(cellval, options, cellval);
  966. break;
  967. case "select":
  968. ret = $.unformat.select(cellval, options, pos, cnt);
  969. break;
  970. case "actions":
  971. return "";
  972. default:
  973. ret = $(cellval).text();
  974. }
  975. }
  976. ret = ret !== undefined ? ret : cnt === true ? $(cellval).text() : jgrid.htmlDecode($(cellval).html());
  977. return ret;
  978. };
  979. $.unformat.select = function (cellval, options, pos, cnt) {
  980. // Spacial case when we have local data and perform a sort
  981. // cnt is set to true only in sortDataArray
  982. var ret = [], cell = $(cellval).text(), colModel = options.colModel;
  983. if (cnt === true) { return cell; }
  984. var op = $.extend({}, colModel.editoptions || {}, colModel.formatoptions || {}),
  985. sep = op.separator === undefined ? ":" : op.separator,
  986. delim = op.delimiter === undefined ? ";" : op.delimiter;
  987. if (op.value) {
  988. var oSelect = typeof op.value === "function" ? op.value() : op.value,
  989. msl = op.multiple === true ? true : false,
  990. scell = [], sv, mapFunc = function (n, k) { if (k > 0) { return n; } };
  991. if (msl) { scell = cell.split(","); scell = $.map(scell, function (n) { return $.trim(n); }); }
  992. if (typeof oSelect === "string") {
  993. var so = oSelect.split(delim), j = 0, i;
  994. for (i = 0; i < so.length; i++) {
  995. sv = so[i].split(sep);
  996. if (sv.length > 2) {
  997. sv[1] = $.map(sv, mapFunc).join(sep);
  998. }
  999. if (msl) {
  1000. if ($.inArray($.trim(sv[1]), scell) > -1) {
  1001. ret[j] = sv[0];
  1002. j++;
  1003. }
  1004. } else if ($.trim(sv[1]) === $.trim(cell)) {
  1005. ret[0] = sv[0];
  1006. break;
  1007. }
  1008. }
  1009. } else if (fmatter.isObject(oSelect) || $.isArray(oSelect)) {
  1010. if (!msl) { scell[0] = cell; }
  1011. ret = $.map(scell, function (n) {
  1012. var rv;
  1013. $.each(oSelect, function (k, val) {
  1014. if (val === n) {
  1015. rv = k;
  1016. return false;
  1017. }
  1018. });
  1019. if (rv !== undefined) { return rv; }
  1020. });
  1021. }
  1022. return ret.join(", ");
  1023. }
  1024. return cell || "";
  1025. };
  1026. $.unformat.date = function (cellval, opts) {
  1027. // TODO
  1028. var op = $.extend(true, {},
  1029. getGridRes.call($(this), "formatter.date"),
  1030. jgrid.formatter.date || {},
  1031. opts.formatoptions || {});
  1032. return !fmatter.isEmpty(cellval) ?
  1033. jgrid.parseDate.call(this, op.newformat, cellval, op.srcformat, op) :
  1034. "";
  1035. };
  1036. // end module jquery.fmatter
  1037. }));