grid.formedit.js 94 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536
  1. /**
  2. * jqGrid extension for form editing Grid Data
  3. * Copyright (c) 2008-2014, Tony Tomov, tony@trirand.com, http://trirand.com/blog/
  4. * Copyright (c) 2014-2018, Oleg Kiriljuk, oleg.kiriljuk@ok-soft-gmbh.com
  5. * Dual licensed under the MIT and GPL licenses:
  6. * http://www.opensource.org/licenses/mit-license.php
  7. * http://www.gnu.org/licenses/gpl-2.0.html
  8. **/
  9. /*jshint eqeqeq:false, eqnull:true, devel:true */
  10. /*jslint browser: true, eqeq: true, plusplus: true, unparam: true, vars: true, nomen: true, continue: true, white: true, todo: true */
  11. /*global jQuery, define, exports, module, require */
  12. (function (global, factory) {
  13. "use strict";
  14. if (typeof define === "function" && define.amd) {
  15. // AMD. Register as an anonymous module.
  16. //console.log("grid.formedit AMD");
  17. define([
  18. "jquery",
  19. "./grid.base",
  20. "./jquery.fmatter",
  21. "./grid.common",
  22. "./grid.filter"
  23. ], function ($) {
  24. //console.log("grid.formedit AMD: define callback");
  25. return factory($, global, global.document);
  26. });
  27. } else if (typeof module === "object" && module.exports) {
  28. // Node/CommonJS
  29. //console.log("grid.formedit CommonJS, typeof define=" + typeof define + ", define=" + define);
  30. module.exports = function (root, $) {
  31. //console.log("grid.formedit CommonJS: in module.exports");
  32. if (!root) {
  33. root = window;
  34. }
  35. //console.log("grid.formedit CommonJS: before require('jquery')");
  36. if ($ === undefined) {
  37. // require("jquery") returns a factory that requires window to
  38. // build a jQuery instance, we normalize how we use modules
  39. // that require this pattern but the window provided is a noop
  40. // if it's defined (how jquery works)
  41. $ = typeof window !== "undefined" ?
  42. require("jquery") :
  43. require("jquery")(root);
  44. }
  45. //console.log("grid.formedit CommonJS: before require('./grid.base')");
  46. require("./grid.base");
  47. //console.log("grid.formedit CommonJS: before require('./jquery.fmatter')");
  48. require("./jquery.fmatter");
  49. //console.log("grid.formedit CommonJS: before require('./grid.common')");
  50. require("./grid.common");
  51. //console.log("grid.formedit CommonJS: before require('./grid.filter')");
  52. require("./grid.filter");
  53. //console.log("grid.formedit CommonJS: before factory");
  54. factory($, root, root.document);
  55. return $;
  56. };
  57. } else {
  58. // Browser globals
  59. //console.log("grid.formedit Browser: before factory");
  60. factory(jQuery, global, global.document);
  61. }
  62. }(typeof window !== "undefined" ? window : this, function ($, window, document) {
  63. "use strict";
  64. var jgrid = $.jgrid, jqID = jgrid.jqID, base = $.fn.jqGrid, getGuiStyles = base.getGuiStyles,
  65. mergeCssClasses = jgrid.mergeCssClasses, hasOneFromClasses = jgrid.hasOneFromClasses;
  66. // begin module grid.formedit
  67. var jgridFeedback = jgrid.feedback, fullBoolFeedback = jgrid.fullBoolFeedback, builderFmButon = jgrid.builderFmButon,
  68. addFormIcon = function ($fmButton, iconInfos, commonIcon) {
  69. var iconspan;
  70. if (iconInfos[0] === true) {
  71. iconspan = "<span class='" + mergeCssClasses("fm-button-icon", commonIcon, iconInfos[2]) + "'></span>";
  72. if (iconInfos[1] === "right") {
  73. $fmButton.addClass("fm-button-icon-right").append(iconspan);
  74. } else {
  75. $fmButton.addClass("fm-button-icon-left").prepend(iconspan);
  76. }
  77. }
  78. },
  79. getGuiStateStyles = function (path) {
  80. return getGuiStyles.call(this, "states." + path);
  81. },
  82. hideRowsWithoutVissibleCells = function ($tb) {
  83. $tb.find("tr[data-rowpos]").each(function () {
  84. var vissible = 0;
  85. $(this).children("td").each(function () {
  86. if ($(this).css("visibility") !== "hidden") {
  87. vissible++;
  88. }
  89. });
  90. if (!vissible) {
  91. $(this).hide();
  92. }
  93. });
  94. },
  95. isEmptyString = function (htmlStr) {
  96. return htmlStr === "&nbsp;" || htmlStr === "&#160;" || (htmlStr.length === 1 && htmlStr.charCodeAt(0) === 160);
  97. };
  98. jgrid.extend({
  99. searchGrid: function (oMuligrid) {
  100. // if one uses jQuery wrapper with multiple grids, then oMuligrid specify the object with common options
  101. return this.each(function () {
  102. var $t = this, $self = $($t), p = $t.p;
  103. if (!$t.grid || p == null) { return; }
  104. // make new copy of the options and use it for ONE specific grid.
  105. // p.searching can contains grid specific options
  106. // we will don't modify the input options oMuligrid
  107. var o = $.extend(true,
  108. {
  109. drag: true,
  110. sField: "searchField",
  111. sValue: "searchString",
  112. sOper: "searchOper",
  113. sFilter: p.prmNames.filters,
  114. loadDefaults: true, // this options activates loading of default filters from grid's postData for Multipe Search only.
  115. beforeShowSearch: null,
  116. afterShowSearch: null,
  117. onInitializeSearch: null,
  118. afterRedraw: null,
  119. afterChange: null,
  120. closeAfterSearch: false,
  121. closeAfterReset: false,
  122. closeOnEscape: false,
  123. searchOnEnter: false,
  124. multipleSearch: false,
  125. multipleGroup: false,
  126. // we can't use srort names like resetIcon because of conflict with existing "x" of filterToolbar
  127. top: 0,
  128. left: 0,
  129. removemodal: true,
  130. //jqModal : true,
  131. //modal: false,
  132. resize: true,
  133. width: 450,
  134. height: "auto",
  135. dataheight: "auto",
  136. showQuery: false,
  137. errorcheck: true,
  138. sopt: null,
  139. stringResult: undefined,
  140. onClose: null,
  141. onSearch: null,
  142. onReset: null,
  143. //toTop : false,
  144. //overlay : 30,
  145. columns: [],
  146. tmplNames: null,
  147. tmplFilters: null,
  148. tmplLabel: " Template: ",
  149. showOnLoad: false,
  150. layer: null,
  151. operands: {
  152. eq: "=",
  153. ne: "<>",
  154. lt: "<",
  155. le: "<=",
  156. gt: ">",
  157. ge: ">=",
  158. bw: "LIKE",
  159. bn: "NOT LIKE",
  160. "in": "IN",
  161. ni: "NOT IN",
  162. ew: "LIKE",
  163. en: "NOT LIKE",
  164. cn: "LIKE",
  165. nc: "NOT LIKE",
  166. nu: "IS NULL",
  167. nn: "IS NOT NULL"
  168. }
  169. },
  170. base.getGridRes.call($self, "search"),
  171. jgrid.search || {},
  172. p.searching || {},
  173. oMuligrid || {});
  174. var fid = "fbox_" + p.id, commonIconClass = o.commonIconClass,
  175. ids = { themodal: "searchmod" + fid, modalhead: "searchhd" + fid, modalcontent: "searchcnt" + fid, resizeAlso: fid },
  176. themodalSelector = "#" + jqID(ids.themodal), gboxSelector = p.gBox, gviewSelector = p.gView, each = $.each,
  177. defaultFilters = p.postData[o.sFilter],
  178. searchFeedback = function () {
  179. var args = $.makeArray(arguments);
  180. args.unshift("Search");
  181. args.unshift("Filter");
  182. args.unshift(o);
  183. return jgridFeedback.apply($t, args);
  184. },
  185. hideModel = function () {
  186. jgrid.hideModal(themodalSelector, {
  187. gb: gboxSelector,
  188. jqm: o.jqModal,
  189. onClose: o.onClose,
  190. removemodal: o.removemodal
  191. });
  192. };
  193. if (typeof defaultFilters === "string") {
  194. defaultFilters = $.trim(defaultFilters) !== "" ? $.parseJSON(defaultFilters) : undefined;
  195. }
  196. $(themodalSelector).remove();
  197. function showFilter($filter) {
  198. if (searchFeedback("beforeShow", $filter)) {
  199. $(themodalSelector).data("onClose", o.onClose);
  200. jgrid.viewModal.call($t, themodalSelector, {
  201. gbox: gboxSelector,
  202. jqm: o.jqModal,
  203. overlay: o.overlay,
  204. modal: o.modal,
  205. overlayClass: o.overlayClass,
  206. toTop: o.toTop,
  207. onHide: function (h) {
  208. h.w.remove();
  209. if (h.o) { h.o.remove(); }
  210. }
  211. });
  212. searchFeedback("afterShow", $filter);
  213. }
  214. }
  215. if ($(themodalSelector)[0] !== undefined) {
  216. showFilter($("#fbox_" + jqID(p.id)));
  217. } else {
  218. var fil = $("<div><div id='" + fid + "' class='" +
  219. getGuiStyles.call($t, "dialog.body", "searchFilter") +
  220. "' style='overflow:auto'></div></div>").insertBefore(gviewSelector);
  221. if (p.direction === "rtl") {
  222. fil.attr("dir", "rtl");
  223. }
  224. var bQ = "", tmpl = "", colnm, found = false, bt, cmi = -1, columns = $.extend([], p.colModel),
  225. bS = builderFmButon.call($t, fid + "_search", o.Find, mergeCssClasses(commonIconClass, o.findDialogIcon), "right"),
  226. bC = builderFmButon.call($t, fid + "_reset", o.Reset, mergeCssClasses(commonIconClass, o.resetDialogIcon), "left");
  227. if (o.showQuery) {
  228. bQ = builderFmButon.call($t, fid + "_query", "Query", mergeCssClasses(commonIconClass, o.queryDialogIcon), "left") +
  229. "&#160;";
  230. }
  231. if (o.searchForAdditionalProperties) {
  232. each(p.additionalProperties, function () {
  233. var cm = typeof this === "string" ? { name: this } : this;
  234. if (!cm.label) {
  235. cm.label = cm.name;
  236. }
  237. cm.isAddProp = true,
  238. columns.push(cm);
  239. });
  240. }
  241. if (!o.columns.length) {
  242. each(columns, function (i, n) {
  243. if (!n.label) {
  244. n.label = n.isAddProp ? n.name : p.colNames[i];
  245. }
  246. // find first searchable column and set it if no default filter
  247. if (!found) {
  248. var searchable = (n.search === undefined) ? true : n.search,
  249. hidden = (n.hidden === true),
  250. ignoreHiding = (n.searchoptions && n.searchoptions.searchhidden === true);
  251. if ((ignoreHiding && searchable) || (searchable && !hidden)) {
  252. found = true;
  253. colnm = n.index || n.name;
  254. cmi = i;
  255. }
  256. }
  257. });
  258. } else {
  259. columns = o.columns;
  260. cmi = 0;
  261. colnm = columns[0].index || columns[0].name;
  262. }
  263. // old behaviour
  264. if ((!defaultFilters && colnm) || o.multipleSearch === false) {
  265. var cmop = "eq";
  266. if (cmi >= 0 && columns[cmi].searchoptions && columns[cmi].searchoptions.sopt) {
  267. cmop = columns[cmi].searchoptions.sopt[0];
  268. } else if (o.sopt && o.sopt.length) {
  269. cmop = o.sopt[0];
  270. }
  271. defaultFilters = { groupOp: "AND", rules: [{ field: colnm, op: cmop, data: "" }] };
  272. }
  273. found = false;
  274. if (o.tmplNames && o.tmplNames.length) {
  275. found = true;
  276. tmpl = o.tmplLabel;
  277. tmpl += "<select class='ui-template'>";
  278. tmpl += "<option value='default'>Default</option>";
  279. each(o.tmplNames, function (i, n) {
  280. tmpl += "<option value='" + i + "'>" + n + "</option>";
  281. });
  282. tmpl += "</select>";
  283. }
  284. bt = "<div class='" + getGuiStyles.call($t, "dialog.footer") + "'><table class='EditTable' style='border:0px none;margin-top:5px' id='" + fid + "_2'><tbody><tr><td colspan='2'><hr class='" +
  285. getGuiStyles.call($t, "dialog.hr") + "' style='margin:1px'/></td></tr><tr><td class='EditButton EditButton-" + p.direction + "' style='float:" + (p.direction === "rtl" ? "right" : "left") + ";'>" + bC + tmpl + "</td><td class='EditButton EditButton-" + p.direction + "'>" + bQ + bS + "</td></tr></tbody></table></div>";
  286. fid = jqID(fid);
  287. o.gbox = gboxSelector; //"#gbox_" + fid;
  288. o.height = "auto";
  289. fid = "#" + fid;
  290. $(fid).jqFilter({
  291. columns: columns,
  292. filter: o.loadDefaults ? defaultFilters : null,
  293. showQuery: o.showQuery,
  294. errorcheck: o.errorcheck,
  295. sopt: o.sopt,
  296. groupButton: o.multipleGroup,
  297. ruleButtons: o.multipleSearch,
  298. afterRedraw: o.afterRedraw,
  299. ops: o.odata,
  300. cops: p.customSortOperations,
  301. operands: o.operands,
  302. ajaxSelectOptions: p.ajaxSelectOptions,
  303. groupOps: o.groupOps,
  304. onChange: function (filterOptions, filterDiv) {
  305. if (filterOptions.showQuery) {
  306. $(".query", filterDiv).text(filterDiv.toUserFriendlyString());
  307. }
  308. fullBoolFeedback.call($t, o.afterChange, "jqGridFilterAfterChange", $(fid), o, filterOptions, filterDiv);
  309. },
  310. direction: p.direction,
  311. id: p.id
  312. });
  313. fil.append(bt);
  314. if (found && o.tmplFilters && o.tmplFilters.length) {
  315. $(".ui-template", fil).on("change", function () {
  316. var curtempl = $(this).val();
  317. if (curtempl === "default") {
  318. $(fid).jqFilter("addFilter", defaultFilters);
  319. } else {
  320. $(fid).jqFilter("addFilter", o.tmplFilters[parseInt(curtempl, 10)]);
  321. }
  322. return false;
  323. });
  324. }
  325. if (o.multipleGroup === true) { o.multipleSearch = true; }
  326. searchFeedback("onInitialize", $(fid));
  327. if (o.layer) {
  328. jgrid.createModal.call($t, ids, fil, o, gviewSelector, $(gboxSelector)[0], "#" + jqID(o.layer), { position: "relative" });
  329. } else {
  330. jgrid.createModal.call($t, ids, fil, o, gviewSelector, $(gboxSelector)[0]);
  331. }
  332. if (o.searchOnEnter || o.closeOnEscape) {
  333. $(themodalSelector).keydown(function (e) {
  334. var $target = $(e.target);
  335. if (o.searchOnEnter && e.which === 13 && // 13 === $.ui.keyCode.ENTER
  336. !$target.hasClass("add-group") && !$target.hasClass("add-rule") &&
  337. !$target.hasClass("delete-group") && !$target.hasClass("delete-rule") &&
  338. (!$target.hasClass("fm-button") || !$target.is("[id$=_query]"))) {
  339. $(fid + "_search").click();
  340. return false;
  341. }
  342. if (o.closeOnEscape && e.which === 27) { // 27 === $.ui.keyCode.ESCAPE
  343. $("#" + jqID(ids.modalhead)).find(".ui-jqdialog-titlebar-close").click();
  344. return false;
  345. }
  346. });
  347. }
  348. if (bQ) {
  349. $(fid + "_query").on("click", function () {
  350. $(".queryresult", fil).toggle();
  351. return false;
  352. });
  353. }
  354. if (o.stringResult === undefined) {
  355. // to provide backward compatibility, inferring stringResult value from multipleSearch
  356. o.stringResult = o.multipleSearch;
  357. }
  358. $(fid + "_search").on("click", function () {
  359. var sdata = {}, res = "", filters, fl = $(fid), $inputs = fl.find(".input-elm");
  360. if ($inputs.filter(":focus")) {
  361. $inputs = $inputs.filter(":focus");
  362. }
  363. $inputs.change();
  364. filters = fl.jqFilter("filterData");
  365. if (o.errorcheck) {
  366. fl[0].hideError();
  367. if (!o.showQuery) { fl.jqFilter("toSQLString"); }
  368. if (fl[0].p.error) {
  369. fl[0].showError();
  370. return false;
  371. }
  372. }
  373. if (o.stringResult || p.datatype === "local") {
  374. try {
  375. res = JSON.stringify(filters);
  376. } catch (ignore) { }
  377. if (typeof res === "string") {
  378. sdata[o.sFilter] = res;
  379. each([o.sField, o.sValue, o.sOper], function () { sdata[this] = ""; });
  380. }
  381. } else {
  382. if (o.multipleSearch) {
  383. sdata[o.sFilter] = filters;
  384. each([o.sField, o.sValue, o.sOper], function () { sdata[this] = ""; });
  385. } else {
  386. sdata[o.sField] = filters.rules[0].field;
  387. sdata[o.sValue] = filters.rules[0].data;
  388. sdata[o.sOper] = filters.rules[0].op;
  389. sdata[o.sFilter] = "";
  390. }
  391. }
  392. $.extend(p.postData, sdata);
  393. if (fullBoolFeedback.call($t, o.onSearch, "jqGridFilterSearch", p.filters)) {
  394. p.search = true;
  395. $self.trigger("reloadGrid", [$.extend({ page: 1 }, o.reloadGridSearchOptions || {})]);
  396. }
  397. if (o.closeAfterSearch) {
  398. hideModel();
  399. }
  400. return false;
  401. });
  402. $(fid + "_reset").on("click", function () {
  403. var sdata = {}, fl1 = $(fid);
  404. p.search = false;
  405. p.resetsearch = true;
  406. if (o.multipleSearch === false) {
  407. sdata[o.sField] = sdata[o.sValue] = sdata[o.sOper] = "";
  408. } else {
  409. sdata[o.sFilter] = "";
  410. }
  411. fl1[0].resetFilter();
  412. if (found) {
  413. $(".ui-template", fil).val("default");
  414. }
  415. $.extend(p.postData, sdata);
  416. if (fullBoolFeedback.call($t, o.onReset, "jqGridFilterReset")) {
  417. $self.trigger("reloadGrid", [$.extend({ page: 1 }, o.reloadGridResetOptions || {})]);
  418. }
  419. if (o.closeAfterReset) {
  420. hideModel();
  421. }
  422. return false;
  423. });
  424. showFilter($(fid));
  425. var hoverClasses = getGuiStateStyles.call($t, "hover");
  426. // !!! The next row will not work if "states.disabled" is defined using more as one CSS class
  427. $(".fm-button:not(." + getGuiStateStyles.call($t, "disabled").split(" ").join(".") + ")", fil).hover(
  428. function () { $(this).addClass(hoverClasses); },
  429. function () { $(this).removeClass(hoverClasses); }
  430. );
  431. }
  432. });
  433. },
  434. editGridRow: function (rowid, oMuligrid) { // if one uses jQuery wrapper with multiple grids, then oMultiple specify the object with common options
  435. return this.each(function () {
  436. var $t = this, $self = $($t), p = $t.p;
  437. if (!$t.grid || p == null || !rowid) { return; }
  438. // make new copy of the options oMuligrid and use it for ONE specific grid.
  439. // p.formEditing can contains grid specific options
  440. // we will don't modify the input options oMuligrid
  441. var gridId = p.id, getGridRes = base.getGridRes, setSelection = base.setSelection,
  442. o = $.extend(true,
  443. {
  444. top: 0,
  445. left: 0,
  446. width: 300,
  447. datawidth: "auto",
  448. height: "auto",
  449. dataheight: "auto",
  450. //modal: false,
  451. //toTop : false,
  452. //overlay : 30,
  453. drag: true,
  454. resize: true,
  455. url: null,
  456. mtype: "POST",
  457. clearAfterAdd: true,
  458. closeAfterEdit: false,
  459. reloadAfterSubmit: true,
  460. onInitializeForm: null,
  461. beforeInitData: null,
  462. beforeShowForm: null,
  463. afterShowForm: null,
  464. beforeSubmit: null,
  465. afterSubmit: null,
  466. onclickSubmit: null,
  467. afterComplete: null,
  468. onclickPgButtons: null,
  469. afterclickPgButtons: null,
  470. editData: {},
  471. //jqModal : true,
  472. closeOnEscape: false,
  473. addedrow: "first",
  474. topinfo: "",
  475. bottominfo: "",
  476. labelswidth: "",
  477. savekey: [false, 13],
  478. navkeys: [false, 38, 40],
  479. checkOnSubmit: false,
  480. checkOnUpdate: false,
  481. _savedData: {},
  482. processing: false,
  483. onClose: null,
  484. ajaxEditOptions: {},
  485. serializeEditData: null,
  486. viewPagerButtons: true,
  487. overlayClass: getGuiStyles.call(this, "overlay"),
  488. removemodal: true,
  489. skipPostTypes: ["image", "file"],
  490. saveui: "enable",
  491. savetext: getGridRes.call($self, "defaults.savetext") || "Saving..."
  492. },
  493. getGridRes.call($self, "edit"),
  494. jgrid.edit,
  495. p.formEditing || {},
  496. oMuligrid || {});
  497. var frmgr = "FrmGrid_" + gridId, frmgrId = frmgr, frmtborg = "TblGrid_" + gridId, frmtb = "#" + jqID(frmtborg), frmtb2 = frmtb + "_2",
  498. ids = { themodal: "editmod" + gridId, modalhead: "edithd" + gridId, modalcontent: "editcnt" + gridId, resizeAlso: frmgr },
  499. themodalSelector = "#" + jqID(ids.themodal), gboxSelector = p.gBox, colModel = p.colModel, iColByName = p.iColByName,
  500. maxCols = 1, maxRows = 0, postdata, diff, editOrAdd, commonIconClass = o.commonIconClass,
  501. hideModal = function () {
  502. jgrid.hideModal(themodalSelector, {
  503. gb: gboxSelector,
  504. jqm: o.jqModal,
  505. onClose: o.onClose,
  506. removemodal: o.removemodal
  507. });
  508. },
  509. errcap = getGridRes.call($self, "errors.errcap"),
  510. editFeedback = function () {
  511. var args = $.makeArray(arguments);
  512. args.unshift("");
  513. args.unshift("AddEdit");
  514. args.unshift(o);
  515. return jgridFeedback.apply($t, args);
  516. },
  517. hoverClasses = getGuiStateStyles.call($t, "hover"),
  518. disabledClass = getGuiStateStyles.call($t, "disabled"),
  519. highlightClass = getGuiStateStyles.call($t, "select"),
  520. activeClass = getGuiStateStyles.call($t, "active"),
  521. errorClass = getGuiStateStyles.call($t, "error");
  522. $(themodalSelector).remove();
  523. frmgr = "#" + jqID(frmgr);
  524. if (rowid === "new") {
  525. rowid = "_empty";
  526. editOrAdd = "add";
  527. o.caption = o.addCaption;
  528. } else {
  529. o.caption = o.editCaption;
  530. editOrAdd = "edit";
  531. }
  532. var closeovrl = true;
  533. if (o.checkOnUpdate && (o.jqModal === true || o.jqModal === undefined) && !o.modal) {
  534. closeovrl = false;
  535. }
  536. function getFormData() {
  537. $(frmtb + " > tbody > tr > td .FormElement").each(function () {
  538. var $celm = $(".customelement", this),
  539. nm = $celm.length ? $celm.attr("name") : this.name,
  540. iCol = iColByName[nm],
  541. cm = iCol !== undefined ? colModel[iCol] || {} : {},
  542. editoptions = cm.editoptions || {},
  543. formatoptions, newformat, type;
  544. if ($celm.length && $.isFunction(editoptions.custom_value)) {
  545. try {
  546. postdata[nm] = editoptions.custom_value.call($t, $("#" + jqID(nm), frmtb), "get");
  547. if (postdata[nm] === undefined) { throw "e1"; }
  548. } catch (e) {
  549. if (e === "e1") {
  550. jgrid.info_dialog.call($t, errcap, "function 'custom_value' " + o.msg.novalue, o.bClose);
  551. } else {
  552. jgrid.info_dialog.call($t, errcap, e.message, o.bClose);
  553. }
  554. }
  555. return true;
  556. } else {
  557. type = $(this)[0].type;
  558. switch (type) {
  559. case "checkbox":
  560. var checkBoxValues = typeof editoptions.value === "string" ?
  561. editoptions.value.split(":") :
  562. ["Yes", "No"];
  563. postdata[nm] = $(this).is(":checked") ? checkBoxValues[0] : checkBoxValues[1];
  564. break;
  565. case "select-one":
  566. postdata[nm] = $("option:selected", this).val();
  567. break;
  568. case "select-multiple":
  569. postdata[nm] = $(this).val();
  570. postdata[nm] = postdata[nm] ? postdata[nm].join(",") : "";
  571. var selectedText = [];
  572. $("option:selected", this).each(
  573. function (i, selected) {
  574. selectedText[i] = $(selected).text();
  575. }
  576. );
  577. break;
  578. case "date":
  579. postdata[nm] = $(this).val();
  580. if (String(postdata[nm]).split("-").length === 3) {
  581. formatoptions = cm.formatoptions || {};
  582. newformat = formatoptions.newformat || getGridRes.call($self, "formatter.date.newformat");
  583. postdata[nm] = jgrid.parseDate.call($self[0], "Y-m-d", postdata[nm], newformat);
  584. }
  585. break;
  586. default:
  587. if (type !== undefined && $.inArray(type, o.skipPostTypes) < 0) {
  588. postdata[nm] = $(this).val();
  589. }
  590. break;
  591. }
  592. }
  593. });
  594. return true;
  595. }
  596. function createData(rowid1, tb, maxcols) {
  597. var cnt = 0, retpos = [], ind = false, $tb = $(tb),
  598. labelsWidth = String(o.labelswidth) + (!o.labelswidth || isNaN(o.labelswidth) ? "" : "px"),
  599. tdtmpl = "<td class='CaptionTD" +
  600. (labelsWidth ? "' style='width:" + labelsWidth + ";" : "") +
  601. "'>&#160;</td><td class='DataTD'>&#160;</td>", tmpl = "", i; //*2
  602. for (i = 1; i <= maxcols; i++) {
  603. tmpl += tdtmpl;
  604. }
  605. if (rowid1 !== "_empty") {
  606. ind = base.getInd.call($self, rowid1);
  607. }
  608. $(colModel).each(function (iCol) {
  609. var cm = this, nm = cm.name, $td, hc, trdata, tmp, elc, editable = cm.editable, disabled = false, readonly = false,
  610. mode = rowid1 === "_empty" ? "addForm" : "editForm";
  611. if ($.isFunction(editable)) {
  612. editable = editable.call($t, {
  613. rowid: rowid1,
  614. iCol: iCol,
  615. iRow: ind, // can be false for Add operation
  616. cmName: nm,
  617. cm: cm,
  618. mode: mode
  619. });
  620. }
  621. // hidden fields are included in the form
  622. if (cm.editrules && cm.editrules.edithidden === true) {
  623. hc = false;
  624. } else {
  625. hc = cm.hidden === true || editable === "hidden" ? true : false;
  626. }
  627. switch (String(editable).toLowerCase()) {
  628. case "hidden":
  629. editable = true;
  630. break;
  631. case "disabled":
  632. editable = true;
  633. disabled = true;
  634. break;
  635. case "readonly":
  636. editable = true;
  637. readonly = true;
  638. break;
  639. }
  640. if (nm !== "cb" && nm !== "subgrid" && editable === true && nm !== "rn") {
  641. if (ind === false) {
  642. tmp = "";
  643. } else {
  644. $td = $($t.rows[ind].cells[iCol]); // $("td[role=gridcell]:eq(" + i + ")", $t.rows[ind])
  645. try {
  646. tmp = $.unformat.call($t, $td, { rowId: rowid1, colModel: cm }, iCol);
  647. } catch (_) {
  648. tmp = (cm.edittype && cm.edittype === "textarea") ? $td.text() : $td.html();
  649. }
  650. if (isEmptyString(tmp)) { tmp = ""; }
  651. }
  652. var opt = $.extend({}, cm.editoptions || {},
  653. { id: nm, name: nm, rowId: rowid1, mode: mode, cm: cm, iCol: iCol }),
  654. frmopt = $.extend({}, { elmprefix: "", elmsuffix: "", rowabove: false, rowcontent: "" }, cm.formoptions || {}),
  655. rp = parseInt(frmopt.rowpos, 10) || cnt + 1,
  656. cp = parseInt((parseInt(frmopt.colpos, 10) || 1) * 2, 10);
  657. if (rowid1 === "_empty" && opt.defaultValue) {
  658. tmp = $.isFunction(opt.defaultValue) ? opt.defaultValue.call($t) : opt.defaultValue;
  659. }
  660. if (!cm.edittype) { cm.edittype = "text"; }
  661. if (p.autoEncodeOnEdit) { tmp = jgrid.oldDecodePostedData(tmp); }
  662. elc = jgrid.createEl.call($t, cm.edittype, opt, tmp, false, $.extend({}, jgrid.ajaxOptions, p.ajaxSelectOptions || {}));
  663. //if(tmp === "" && cm.edittype == "checkbox") {tmp = $(elc).data("offval");}
  664. //if(tmp === "" && cm.edittype == "select") {tmp = $("option:eq(0)",elc).text();}
  665. if (o.checkOnSubmit || o.checkOnUpdate) { o._savedData[nm] = tmp; }
  666. $(elc).addClass("FormElement");
  667. if ($.inArray(cm.edittype, ["text", "textarea", "checkbox", "password", "select"]) > -1) {
  668. $(elc).addClass(getGuiStyles.call($t, "dialog.dataField"));
  669. }
  670. trdata = $tb.find("tr[data-rowpos=" + rp + "]");
  671. if (frmopt.rowabove) {
  672. var newdata = $("<tr><td class='contentinfo' colspan='" + (maxcols * 2) + "'>" + frmopt.rowcontent + "</td></tr>");
  673. $tb.append(newdata);
  674. newdata[0].rp = rp;
  675. }
  676. if (trdata.length === 0) {
  677. trdata = $("<tr data-rowpos='" + rp + "'></tr>").addClass("FormData").attr("id", "tr_" + nm);
  678. $(trdata).append(tmpl);
  679. $tb.append(trdata);
  680. trdata[0].rp = rp;
  681. }
  682. var $label = $("td:eq(" + (cp - 2) + ")", trdata[0]),
  683. $data = $("td:eq(" + (cp - 1) + ")", trdata[0]);
  684. $label.html(frmopt.label === undefined ? p.colNames[iCol] : frmopt.label || "&#160;");
  685. var $dataCell = $data[isEmptyString($data.html()) ? "html" : "append"](frmopt.elmprefix);
  686. $dataCell.append(elc).append(frmopt.elmsuffix);
  687. if (elc.tagName.toUpperCase() === "INPUT" && cm.createColumnIndex && opt.generateDatalist) {
  688. var $datalist = $self.jqGrid("generateDatalistFromColumnIndex", cm.name);
  689. if ($datalist != null && $datalist.length > 0) {
  690. $(elc).attr("list", "dl_" + elc.id);
  691. $dataCell.append($datalist.attr("id", "dl_" + elc.id));
  692. }
  693. }
  694. if (disabled) {
  695. $label.addClass(disabledClass);
  696. $data.addClass(disabledClass);
  697. $(elc).prop("readonly", true);
  698. $(elc).prop("disabled", true);
  699. } else if (readonly) {
  700. $(elc).prop("readonly", true);
  701. }
  702. if (cm.edittype === "custom" && $.isFunction(opt.custom_value)) {
  703. opt.custom_value.call($t, $("#" + jqID(nm), frmgr), "set", tmp);
  704. }
  705. jgrid.bindEv.call($t, elc, opt);
  706. if (hc) {
  707. $label.add($data).css("visibility", "hidden");
  708. }
  709. retpos[cnt] = iCol;
  710. cnt++;
  711. }
  712. });
  713. hideRowsWithoutVissibleCells($tb);
  714. if (cnt > 0) {
  715. var idrow = $("<tr class='FormData' style='display:none'><td class='CaptionTD'>&#160;</td><td colspan='" + (maxcols * 2 - 1) + "' class='DataTD'><input class='FormElement' id='id_g' type='text' name='" + gridId + "_id' value='" + rowid1 + "'/></td></tr>");
  716. idrow[0].rp = cnt + 999;
  717. $tb.append(idrow);
  718. if (o.checkOnSubmit || o.checkOnUpdate) { o._savedData[gridId + "_id"] = rowid1; }
  719. }
  720. return retpos;
  721. }
  722. function fillData(rowid1, fmid) {
  723. var nm, cnt = 0, fld, opt, vl, vlc;
  724. if (o.checkOnSubmit || o.checkOnUpdate) { o._savedData = {}; o._savedData[gridId + "_id"] = rowid1; }
  725. var cm = p.colModel;
  726. if (rowid1 === "_empty") {
  727. $(cm).each(function () {
  728. nm = this.name;
  729. opt = $.extend({}, this.editoptions || {});
  730. fld = $("#" + jqID(nm), fmid);
  731. if (fld && fld.length && fld[0] !== null) {
  732. vl = "";
  733. if (this.edittype === "custom" && $.isFunction(opt.custom_value)) {
  734. opt.custom_value.call($t, fld, "set", vl);
  735. } else if (opt.defaultValue) {
  736. vl = $.isFunction(opt.defaultValue) ? opt.defaultValue.call($t) : opt.defaultValue;
  737. if (fld[0].type === "checkbox") {
  738. vlc = vl.toLowerCase();
  739. if (vlc.search(/(false|f|0|no|n|off|undefined)/i) < 0 && vlc !== "") {
  740. fld[0].checked = true;
  741. fld[0].defaultChecked = true;
  742. fld[0].value = vl;
  743. } else {
  744. fld[0].checked = false;
  745. fld[0].defaultChecked = false;
  746. }
  747. } else { fld.val(vl); }
  748. } else {
  749. if (fld[0].type === "checkbox") {
  750. fld[0].checked = false;
  751. fld[0].defaultChecked = false;
  752. vl = $(fld).data("offval");
  753. } else if (fld[0].type && fld[0].type.substr(0, 6) === "select") {
  754. fld[0].selectedIndex = 0;
  755. } else {
  756. fld.val(vl);
  757. }
  758. }
  759. if (o.checkOnSubmit === true || o.checkOnUpdate) { o._savedData[nm] = vl; }
  760. }
  761. });
  762. $("#id_g", fmid).val(rowid1);
  763. return;
  764. }
  765. var tre = base.getInd.call($self, rowid1, true);
  766. if (!tre) { return; }
  767. //$("td[role=gridcell]", tre)
  768. $(tre.cells).filter("td[role=gridcell]").each(function (i) {
  769. var tmp;
  770. nm = cm[i].name;
  771. // hidden fields are included in the form
  772. if (nm !== "cb" && nm !== "subgrid" && nm !== "rn" && cm[i].editable === true) {
  773. try {
  774. tmp = $.unformat.call($t, $(this), { rowId: rowid1, colModel: cm[i] }, i);
  775. } catch (_) {
  776. tmp = cm[i].edittype === "textarea" ? $(this).text() : $(this).html();
  777. }
  778. if (p.autoEncodeOnEdit) { tmp = jgrid.oldDecodePostedData(tmp); }
  779. if (o.checkOnSubmit === true || o.checkOnUpdate) { o._savedData[nm] = tmp; }
  780. nm = "#" + jqID(nm);
  781. switch (cm[i].edittype) {
  782. case "password":
  783. case "text":
  784. case "button":
  785. case "image":
  786. case "textarea":
  787. if (isEmptyString(tmp)) { tmp = ""; }
  788. $(nm, fmid).val(tmp);
  789. break;
  790. case "select":
  791. var valuesToSelect = tmp.split(",");
  792. valuesToSelect = $.map(valuesToSelect, function (n) { return $.trim(n); });
  793. // first of all we try to select options testing the valuesToSelect,
  794. // we will remove the values from valuesToSelect, which will be found by value
  795. // In the next step we go through all options once more time and select the options
  796. // testing there by text. In other words selection by text will be used only for
  797. // values from valuesToSelect, which not exist as option by value
  798. $(nm + " option", fmid).each(function () {
  799. var selOpt = this, $selOpt = $(selOpt), optVal = $.trim($selOpt.val()), iVal;
  800. if (!cm[i].editoptions.multiple && valuesToSelect[0] === optVal) {
  801. valuesToSelect.splice(0, 1);
  802. selOpt.selected = true;
  803. } else if (cm[i].editoptions.multiple) {
  804. iVal = $.inArray(optVal, valuesToSelect);
  805. if (iVal > -1) {
  806. valuesToSelect.splice(iVal, 1);
  807. selOpt.selected = true;
  808. } else {
  809. selOpt.selected = false;
  810. }
  811. } else {
  812. selOpt.selected = false;
  813. }
  814. if (valuesToSelect.length === 0) { return false; }
  815. });
  816. if (valuesToSelect.length > 0) {
  817. $(nm + " option", fmid).each(function () {
  818. var selOpt = this, $selOpt = $(selOpt), optText = $.trim($selOpt.text()), iVal;
  819. if (!cm[i].editoptions.multiple && ($.trim(tmp) === optText || valuesToSelect[0] === optText)) {
  820. valuesToSelect.splice(0, 1);
  821. selOpt.selected = true;
  822. } else if (cm[i].editoptions.multiple) {
  823. iVal = $.inArray(optText, valuesToSelect);
  824. if (iVal > -1) {
  825. valuesToSelect.splice(iVal, 1);
  826. selOpt.selected = true;
  827. }
  828. }
  829. if (valuesToSelect.length === 0) { return false; }
  830. });
  831. }
  832. break;
  833. case "checkbox":
  834. tmp = String(tmp);
  835. // tmp will be set below (in the if-else) to Boolean true or false
  836. if (cm[i].editoptions && cm[i].editoptions.value) {
  837. tmp = cm[i].editoptions.value.split(":")[0] === tmp;
  838. } else {
  839. tmp = tmp.toLowerCase();
  840. tmp = tmp.search(/(false|f|0|no|n|off|undefined)/i) < 0 && tmp !== "";
  841. }
  842. $(nm, fmid).prop({ checked: tmp, defaultChecked: tmp });
  843. break;
  844. case "custom":
  845. try {
  846. if (cm[i].editoptions && $.isFunction(cm[i].editoptions.custom_value)) {
  847. cm[i].editoptions.custom_value.call($t, $(nm, fmid), "set", tmp);
  848. } else { throw "e1"; }
  849. } catch (e) {
  850. if (e === "e1") {
  851. jgrid.info_dialog.call($t, errcap, "function 'custom_value' " + o.msg.nodefined, o.bClose);
  852. } else {
  853. jgrid.info_dialog.call($t, errcap, e.message, o.bClose);
  854. }
  855. }
  856. break;
  857. }
  858. cnt++;
  859. }
  860. });
  861. if (cnt > 0) { $("#id_g", frmtb).val(rowid1); }
  862. }
  863. function setNullsOrUnformat() {
  864. var url = o.url || p.editurl;
  865. $.each(colModel, function (i, cm) {
  866. var cmName = cm.name;
  867. if (postdata.hasOwnProperty(cmName)) {
  868. if (cm.formatter === "date" && (cm.formatoptions == null || cm.formatoptions.sendFormatted !== true)) {
  869. // TODO: call all other predefined formatters!!! Not only formatter: "date" have the problem.
  870. // Floating point separator for example
  871. postdata[cmName] = $.unformat.date.call($t, postdata[cmName], cm);
  872. }
  873. if (url !== "clientArray" && cm.editoptions && cm.editoptions.NullIfEmpty === true && postdata[cmName] === "") {
  874. postdata[cmName] = "null";
  875. }
  876. }
  877. });
  878. }
  879. function postIt() {
  880. var successResult = [true, "", ""], ret = successResult, onClickSubmitResult = {}, opers = p.prmNames, idname, oper, key, selr, i, url, itm, iCol,
  881. iRow = base.getInd.call($self, rowid),
  882. tr = iRow === false ? null : $t.rows[iRow],
  883. retvals = $self.triggerHandler("jqGridAddEditBeforeCheckValues", [postdata, $(frmgr), editOrAdd]);
  884. if (retvals && typeof retvals === "object") { postdata = retvals; }
  885. iRow = iRow === false ? -1 : iRow;
  886. if ($.isFunction(o.beforeCheckValues)) {
  887. retvals = o.beforeCheckValues.call($t, postdata, $(frmgr), editOrAdd);
  888. if (retvals && typeof retvals === "object") { postdata = retvals; }
  889. }
  890. for (key in postdata) {
  891. if (postdata.hasOwnProperty(key)) {
  892. iCol = p.iColByName[key];
  893. ret = jgrid.checkValues.call($t, postdata[key], key, undefined, undefined, {
  894. oldValue: rowid === "_empty" ? null : base.getCell.call($self, rowid, iCol),
  895. newValue: postdata[key],
  896. cmName: key,
  897. rowid: rowid,
  898. cm: colModel[iCol],
  899. iCol: iCol,
  900. iRow: iRow,
  901. tr: tr,
  902. td: tr == null ? null : tr.cells[iCol],
  903. mode: rowid === "_empty" ? "addForm" : "editForm"
  904. });
  905. if (ret == null || ret === true) { ret = successResult; }
  906. if (ret[0] === false) { break; }
  907. }
  908. }
  909. setNullsOrUnformat();
  910. if (ret[0]) {
  911. onClickSubmitResult = $self.triggerHandler("jqGridAddEditClickSubmit", [o, postdata, editOrAdd]);
  912. if (onClickSubmitResult === undefined && $.isFunction(o.onclickSubmit)) {
  913. onClickSubmitResult = o.onclickSubmit.call($t, o, postdata, editOrAdd) || {};
  914. }
  915. ret = $self.triggerHandler("jqGridAddEditBeforeSubmit", [postdata, $(frmgr), editOrAdd]);
  916. if (ret == null || ret === true) { ret = successResult; }
  917. if (ret[0] && $.isFunction(o.beforeSubmit)) {
  918. ret = o.beforeSubmit.call($t, postdata, $(frmgr), editOrAdd);
  919. if (ret == null || ret === true) { ret = successResult; }
  920. }
  921. }
  922. if (ret[0] && !o.processing) {
  923. o.processing = true;
  924. $("#sData", frmtb2).addClass(activeClass);
  925. url = o.url || p.editurl;
  926. oper = opers.oper;
  927. idname = url === "clientArray" && p.keyName !== false ? p.keyName : opers.id;
  928. // we add to pos data array the action - the name is oper
  929. postdata[oper] = ($.trim(postdata[gridId + "_id"]) === "_empty") ? opers.addoper : opers.editoper;
  930. if (postdata[oper] !== opers.addoper) {
  931. postdata[idname] = postdata[gridId + "_id"];
  932. } else {
  933. // check to see if we have allredy this field in the form and if yes lieve it
  934. if (postdata[idname] === undefined) { postdata[idname] = postdata[gridId + "_id"]; }
  935. }
  936. delete postdata[gridId + "_id"];
  937. postdata = $.extend(postdata, o.editData, onClickSubmitResult);
  938. if (p.treeGrid === true) {
  939. if (postdata[oper] === opers.addoper) {
  940. selr = p.selrow;
  941. var parentIdField = p.treeGridModel === "adjacency" ? p.treeReader.parent_id_field : "parent_id";
  942. postdata[parentIdField] = selr;
  943. }
  944. for (i in p.treeReader) {
  945. if (p.treeReader.hasOwnProperty(i)) {
  946. itm = p.treeReader[i];
  947. if (postdata.hasOwnProperty(itm)) {
  948. if (postdata[oper] === opers.addoper && i === "parent_id_field") { continue; }
  949. delete postdata[itm];
  950. }
  951. }
  952. }
  953. }
  954. postdata[idname] = jgrid.stripPref(p.idPrefix, postdata[idname]);
  955. if (p.autoEncodeOnEdit) {
  956. $.each(postdata, function (n, v) {
  957. if (!$.isFunction(v)) {
  958. postdata[n] = jgrid.oldEncodePostedData(v);
  959. }
  960. });
  961. }
  962. var ajaxOptions = $.extend({
  963. url: $.isFunction(url) ? url.call($t, postdata[idname], editOrAdd, postdata, o) : url,
  964. type: $.isFunction(o.mtype) ? o.mtype.call($t, editOrAdd, o, postdata[idname], postdata) : o.mtype,
  965. //data: $.isFunction(o.serializeEditData) ? o.serializeEditData.call($t,postdata) : postdata,
  966. data: jgrid.serializeFeedback.call($t,
  967. $.isFunction(o.serializeEditData) ? o.serializeEditData : p.serializeEditData,
  968. "jqGridAddEditSerializeEditData",
  969. postdata),
  970. complete: function (jqXHR, textStatus) {
  971. $self.jqGrid("progressBar", { method: "hide", loadtype: o.saveui });
  972. $("#sData", frmtb2).removeClass(activeClass);
  973. postdata[idname] = $("#id_g", frmtb).val();
  974. if ((jqXHR.status >= 300 && jqXHR.status !== 304) || (jqXHR.status === 0 && jqXHR.readyState === 4)) {
  975. ret[0] = false;
  976. ret[1] = $self.triggerHandler("jqGridAddEditErrorTextFormat", [jqXHR, editOrAdd]);
  977. if ($.isFunction(o.errorTextFormat)) {
  978. ret[1] = o.errorTextFormat.call($t, jqXHR, editOrAdd);
  979. } else {
  980. ret[1] = textStatus + " Status: '" + jqXHR.statusText + "'. Error code: " + jqXHR.status;
  981. }
  982. } else {
  983. // data is posted successful
  984. // execute aftersubmit with the returned data from server
  985. ret = $self.triggerHandler("jqGridAddEditAfterSubmit", [jqXHR, postdata, editOrAdd]);
  986. if (ret == null || ret === true) { ret = successResult; }
  987. if (ret[0] && $.isFunction(o.afterSubmit)) {
  988. ret = o.afterSubmit.call($t, jqXHR, postdata, editOrAdd);
  989. if (ret == null || ret === true) { ret = successResult; }
  990. }
  991. }
  992. if (ret[0] === false) {
  993. $("#FormError>td", frmtb).html(ret[1]);
  994. $("#FormError", frmtb).show();
  995. } else {
  996. if (p.autoEncodeOnEdit) {
  997. $.each(postdata, function (n, v) {
  998. postdata[n] = jgrid.oldDecodePostedData(v);
  999. });
  1000. }
  1001. //o.reloadAfterSubmit = o.reloadAfterSubmit && $t.o.datatype != "local";
  1002. // the action is add
  1003. var reloadGridOptions = [$.extend({}, o.reloadGridOptions || {})];
  1004. if (postdata[oper] === opers.addoper) {
  1005. //id processing
  1006. // user not set the id ret[2]
  1007. if (!ret[2]) { ret[2] = jgrid.randId(); }
  1008. if (postdata[idname] == null || postdata[idname] === "_empty" || postdata[oper] === opers.addoper) {
  1009. postdata[idname] = ret[2];
  1010. } else {
  1011. ret[2] = postdata[idname];
  1012. }
  1013. if (o.reloadAfterSubmit) {
  1014. $self.trigger("reloadGrid", reloadGridOptions);
  1015. } else {
  1016. if (p.treeGrid === true) {
  1017. base.addChildNode.call($self, ret[2], selr, postdata);
  1018. } else {
  1019. base.addRowData.call($self, ret[2], postdata, o.addedrow);
  1020. }
  1021. }
  1022. if (o.closeAfterAdd) {
  1023. if (p.treeGrid !== true) {
  1024. setSelection.call($self, ret[2]);
  1025. }
  1026. hideModal();
  1027. } else if (o.clearAfterAdd) {
  1028. fillData("_empty", frmgr);
  1029. }
  1030. } else {
  1031. // the action is update
  1032. if (o.reloadAfterSubmit) {
  1033. $self.trigger("reloadGrid", reloadGridOptions);
  1034. if (!o.closeAfterEdit) { setTimeout(function () { setSelection.call($self, postdata[idname]); }, 1000); }
  1035. } else {
  1036. if (p.treeGrid === true) {
  1037. base.setTreeRow.call($self, postdata[idname], postdata);
  1038. } else {
  1039. base.setRowData.call($self, postdata[idname], postdata);
  1040. }
  1041. }
  1042. if (o.closeAfterEdit) {
  1043. hideModal();
  1044. }
  1045. }
  1046. if ($.isFunction(o.afterComplete)) {
  1047. var copydata = jqXHR;
  1048. setTimeout(function () {
  1049. $self.triggerHandler("jqGridAddEditAfterComplete", [copydata, postdata, $(frmgr), editOrAdd]);
  1050. o.afterComplete.call($t, copydata, postdata, $(frmgr), editOrAdd);
  1051. copydata = null;
  1052. }, 50);
  1053. }
  1054. if (o.checkOnSubmit || o.checkOnUpdate) {
  1055. $(frmgr).data("disabled", false);
  1056. if (o._savedData[gridId + "_id"] !== "_empty") {
  1057. var key1;
  1058. for (key1 in o._savedData) {
  1059. if (o._savedData.hasOwnProperty(key1) && postdata[key1]) {
  1060. o._savedData[key1] = postdata[key1];
  1061. }
  1062. }
  1063. }
  1064. }
  1065. }
  1066. o.processing = false;
  1067. try {
  1068. $(frmgr).find("input,textarea,select,button,object,*[tabindex]")
  1069. .filter(":input:visible:not(:disabled)")
  1070. .first()
  1071. .focus();
  1072. } catch (ignore) { }
  1073. }
  1074. }, jgrid.ajaxOptions, o.ajaxEditOptions);
  1075. if (!ajaxOptions.url && !o.useDataProxy) {
  1076. if ($.isFunction(p.dataProxy)) {
  1077. o.useDataProxy = true;
  1078. } else {
  1079. ret[0] = false;
  1080. ret[1] += " " + jgrid.errors.nourl;
  1081. }
  1082. }
  1083. if (ret[0]) {
  1084. $self.jqGrid("progressBar", { method: "show", loadtype: o.saveui, htmlcontent: o.savetext });
  1085. if (o.useDataProxy) {
  1086. var dpret = p.dataProxy.call($t, ajaxOptions, "set_" + gridId);
  1087. if (dpret === undefined) {
  1088. dpret = [true, ""];
  1089. }
  1090. if (dpret[0] === false) {
  1091. ret[0] = false;
  1092. ret[1] = dpret[1] || "Error deleting the selected row!";
  1093. } else {
  1094. if (ajaxOptions.data.oper === opers.addoper && o.closeAfterAdd) {
  1095. hideModal();
  1096. }
  1097. if (ajaxOptions.data.oper === opers.editoper && o.closeAfterEdit) {
  1098. hideModal();
  1099. }
  1100. }
  1101. } else {
  1102. if (ajaxOptions.url === "clientArray") {
  1103. o.reloadAfterSubmit = false;
  1104. postdata = ajaxOptions.data;
  1105. ajaxOptions.complete({ status: 200, statusText: "" }, "");
  1106. } else {
  1107. $.ajax(ajaxOptions);
  1108. }
  1109. }
  1110. }
  1111. }
  1112. if (ret[0] === false) {
  1113. $("#FormError>td", frmtb).html(ret[1]);
  1114. $("#FormError", frmtb).show();
  1115. // return;
  1116. }
  1117. }
  1118. function compareData(nObj, oObj) {
  1119. var ret = false, key;
  1120. for (key in nObj) {
  1121. if (nObj.hasOwnProperty(key) && String(nObj[key]) !== String(oObj[key])) {
  1122. ret = true;
  1123. break;
  1124. }
  1125. }
  1126. return ret;
  1127. }
  1128. function checkUpdates() {
  1129. var stat = true;
  1130. $("#FormError", frmtb).hide();
  1131. if (o.checkOnUpdate) {
  1132. postdata = {};
  1133. getFormData();
  1134. diff = compareData(postdata, o._savedData);
  1135. if (diff) {
  1136. $(frmgr).data("disabled", true);
  1137. $(".confirm", themodalSelector).show();
  1138. stat = false;
  1139. }
  1140. }
  1141. return stat;
  1142. }
  1143. function restoreInline() {
  1144. var editingInfo = jgrid.detectRowEditing.call($t, rowid);
  1145. if (editingInfo != null) {
  1146. if (editingInfo.mode === "inlineEditing") {
  1147. base.restoreRow.call($self, rowid);
  1148. } else {
  1149. var savedRowInfo = editingInfo.savedRow, tr = $t.rows[savedRowInfo.id];
  1150. base.restoreCell.call($self, savedRowInfo.id, savedRowInfo.ic);
  1151. // remove highlighting of the cell
  1152. $(tr.cells[savedRowInfo.ic]).removeClass("edit-cell " + highlightClass);
  1153. $(tr).addClass(highlightClass).attr({ "aria-selected": "true", "tabindex": "0" });
  1154. }
  1155. }
  1156. }
  1157. function updateNav(cr, posarr) {
  1158. var totr = posarr[1].length - 1;
  1159. if (cr === 0) {
  1160. $("#pData", frmtb2).addClass(disabledClass);
  1161. } else if (posarr[1][cr - 1] !== undefined && hasOneFromClasses($("#" + jqID(posarr[1][cr - 1])), disabledClass)) {
  1162. $("#pData", frmtb2).addClass(disabledClass);
  1163. } else {
  1164. $("#pData", frmtb2).removeClass(disabledClass);
  1165. }
  1166. if (cr === totr) {
  1167. $("#nData", frmtb2).addClass(disabledClass);
  1168. } else if (posarr[1][cr + 1] !== undefined && hasOneFromClasses($("#" + jqID(posarr[1][cr + 1])), disabledClass)) {
  1169. $("#nData", frmtb2).addClass(disabledClass);
  1170. } else {
  1171. $("#nData", frmtb2).removeClass(disabledClass);
  1172. }
  1173. }
  1174. function getCurrPos() {
  1175. var rowsInGrid = base.getDataIDs.call($self),
  1176. selrow = $("#id_g", frmtb).val(),
  1177. pos = $.inArray(selrow, rowsInGrid);
  1178. return [pos, rowsInGrid];
  1179. }
  1180. var dh = isNaN(o.dataheight) ? o.dataheight : o.dataheight + "px",
  1181. dw = isNaN(o.datawidth) ? o.datawidth : o.datawidth + "px",
  1182. frm = $("<form name='FormPost' id='" + frmgrId + "' class='FormGrid' onSubmit='return false;' style='width:" + dw + ";overflow:auto;position:relative;height:" + dh + ";'></form>").data("disabled", false),
  1183. tbl = $("<table id='" + frmtborg + "' class='EditTable'><tbody></tbody></table>");
  1184. $(colModel).each(function () {
  1185. var fmto = this.formoptions;
  1186. maxCols = Math.max(maxCols, fmto ? fmto.colpos || 0 : 0);
  1187. maxRows = Math.max(maxRows, fmto ? fmto.rowpos || 0 : 0);
  1188. });
  1189. $(frm).append(tbl);
  1190. var flr = $("<tr id='FormError' style='display:none'><td class='" + errorClass + "' colspan='" + (maxCols * 2) + "'>&#160;</td></tr>");
  1191. flr[0].rp = 0;
  1192. $(tbl).append(flr);
  1193. //topinfo
  1194. flr = $("<tr style='display:none' class='tinfo'><td class='topinfo' colspan='" + (maxCols * 2) + "'>" + (o.topinfo || "&#160;") + "</td></tr>");
  1195. flr[0].rp = 0;
  1196. $(tbl).append(flr);
  1197. if (!editFeedback("beforeInitData", frm, editOrAdd)) { return; }
  1198. restoreInline();
  1199. // set the id.
  1200. // use carefull only to change here colproperties.
  1201. // create data
  1202. var rtlb = p.direction === "rtl" ? true : false,
  1203. bp = rtlb ? "nData" : "pData",
  1204. bn = rtlb ? "pData" : "nData";
  1205. createData(rowid, tbl, maxCols);
  1206. // buttons at footer
  1207. var bP = builderFmButon.call($t, bp, "", mergeCssClasses(commonIconClass, o.prevIcon), "", "left"),
  1208. bN = builderFmButon.call($t, bn, "", mergeCssClasses(commonIconClass, o.nextIcon), "", "right"),
  1209. bS = builderFmButon.call($t, "sData", o.bSubmit),
  1210. bC = builderFmButon.call($t, "cData", o.bCancel),
  1211. bt = "<div class='" + getGuiStyles.call($t, "dialog.footer") + "'><table class='EditTable' id='" + frmtborg + "_2'><tbody><tr><td colspan='2'><hr class='" +
  1212. getGuiStyles.call($t, "dialog.hr") + "' style='margin:1px'/></td></tr><tr id='Act_Buttons'><td class='navButton navButton-" + p.direction + "'>" + (rtlb ? bN + bP : bP + bN) + "</td><td class='EditButton EditButton-" + p.direction + "'>" + bS + "&#160;" + bC + "</td></tr>";
  1213. bt += "<tr style='display:none' class='binfo'><td class='bottominfo' colspan='2'>" + (o.bottominfo || "&#160;") + "</td></tr>";
  1214. bt += "</tbody></table></div>";
  1215. if (maxRows > 0) {
  1216. var sd = [];
  1217. $.each($(tbl)[0].rows, function (i, r) {
  1218. sd[i] = r;
  1219. });
  1220. sd.sort(function (a, b) {
  1221. if (a.rp > b.rp) { return 1; }
  1222. if (a.rp < b.rp) { return -1; }
  1223. return 0;
  1224. });
  1225. $.each(sd, function (index, row) {
  1226. $("tbody", tbl).append(row);
  1227. });
  1228. }
  1229. o.gbox = gboxSelector;
  1230. var cle = false;
  1231. if (o.closeOnEscape === true) {
  1232. o.closeOnEscape = false;
  1233. cle = true;
  1234. }
  1235. var tms = $("<div></div>").append($("<div class='" + getGuiStyles.call($t, "dialog.body") + "'></div>").append(frm)).append(bt);
  1236. jgrid.createModal.call($t, ids, tms, o, p.gView, $(gboxSelector)[0]);
  1237. // TODO: remove the call of jgrid.bindEv and probably call of opt.custom_value from createData
  1238. // and place the calls here AFTER the form are placed on the HTML page
  1239. if (o.topinfo) { $(".tinfo", frmtb).show(); }
  1240. if (o.bottominfo) { $(".binfo", frmtb2).show(); }
  1241. tms = null;
  1242. bt = null;
  1243. $(themodalSelector).keydown(function (e) {
  1244. var wTagName = (e.target.tagName || "").toUpperCase(), $focused, idFocused;
  1245. if ($(frmgr).data("disabled") === true) { return false; }//??
  1246. if (e.which === 13) {
  1247. if (wTagName !== "TEXTAREA") {
  1248. $focused = $(frmtb2).find(":focus");
  1249. idFocused = $focused.attr("id");
  1250. if ($focused.length > 0 && $.inArray(idFocused, ["pData", "nData", "cData"]) >= 0) {
  1251. $focused.trigger("click");
  1252. return false;
  1253. }
  1254. if (o.savekey[0] === true && o.savekey[1] === 13) {
  1255. $("#sData", frmtb2).trigger("click");
  1256. return false;
  1257. }
  1258. }
  1259. }
  1260. if (o.savekey[0] === true && e.which === o.savekey[1]) { // save
  1261. if (wTagName !== "TEXTAREA") {
  1262. $("#sData", frmtb2).trigger("click");
  1263. return false;
  1264. }
  1265. }
  1266. if (e.which === 27) {
  1267. if (!checkUpdates()) { return false; }
  1268. if (cle) {
  1269. hideModal();
  1270. }
  1271. return false;
  1272. }
  1273. if (o.navkeys[0] === true) {
  1274. if ($("#id_g", frmtb).val() === "_empty") { return true; }
  1275. if (e.which === o.navkeys[1]) { //up
  1276. $("#pData", frmtb2).trigger("click");
  1277. return false;
  1278. }
  1279. if (e.which === o.navkeys[2]) { //down
  1280. $("#nData", frmtb2).trigger("click");
  1281. return false;
  1282. }
  1283. }
  1284. });
  1285. if (o.checkOnUpdate) {
  1286. $("a.ui-jqdialog-titlebar-close span", themodalSelector).removeClass("jqmClose");
  1287. $("a.ui-jqdialog-titlebar-close", themodalSelector).off("click")
  1288. .click(function () {
  1289. if (!checkUpdates()) {
  1290. return false;
  1291. }
  1292. hideModal();
  1293. return false;
  1294. });
  1295. }
  1296. addFormIcon($("#sData", frmtb2), o.saveicon, commonIconClass);
  1297. addFormIcon($("#cData", frmtb2), o.closeicon, commonIconClass);
  1298. if (o.checkOnSubmit || o.checkOnUpdate) {
  1299. bS = builderFmButon.call($t, "sNew", o.bYes);
  1300. bN = builderFmButon.call($t, "nNew", o.bNo);
  1301. bC = builderFmButon.call($t, "cNew", o.bExit);
  1302. var zI = o.zIndex || 999;
  1303. zI++;
  1304. $("<div class='" + o.overlayClass + " jqgrid-overlay confirm' style='z-index:" + zI + ";display:none;'>&#160;</div><div class='" + getGuiStyles.call($t, "dialog.content", "confirm ui-jqconfirm") + "' style='z-index:" + (zI + 1) + "'>" + o.saveData + "<br/><br/>" + bS + bN + bC + "</div>").insertAfter(frmgr);
  1305. $("#sNew", themodalSelector).click(function () {
  1306. // if the form will be hidden at the first usage and it will be shown at the next usage
  1307. // then the execution context click handler and all other functions like postIt()
  1308. // will contains the variables (like rowid, postdata and so on) from THE FIRST call
  1309. // of editGridRow. One should be very careful in the code of postIt()
  1310. postIt();
  1311. $(frmgr).data("disabled", false);
  1312. $(".confirm", themodalSelector).hide();
  1313. return false;
  1314. });
  1315. $("#nNew", themodalSelector).click(function () {
  1316. $(".confirm", themodalSelector).hide();
  1317. $(frmgr).data("disabled", false);
  1318. setTimeout(function () {
  1319. $(frmgr).find("input,textarea,select,button,object,*[tabindex]")
  1320. .filter(":input:visible:not(:disabled)")
  1321. .first()
  1322. .focus();
  1323. }, 0);
  1324. return false;
  1325. });
  1326. $("#cNew", themodalSelector).click(function () {
  1327. // if the form will be hidden at the first usage and it will be shown at the next usage
  1328. // then the execution context click handler and all other functions like postIt()
  1329. // will contains the variables (like o) from THE FIRST call
  1330. $(".confirm", themodalSelector).hide();
  1331. $(frmgr).data("disabled", false);
  1332. hideModal();
  1333. return false;
  1334. });
  1335. }
  1336. // here initform - only once
  1337. editFeedback("onInitializeForm", $(frmgr), editOrAdd);
  1338. if (rowid === "_empty" || !o.viewPagerButtons) {
  1339. $("#pData,#nData", frmtb2).hide();
  1340. } else {
  1341. $("#pData,#nData", frmtb2).show();
  1342. }
  1343. editFeedback("beforeShowForm", $(frmgr), editOrAdd);
  1344. $(themodalSelector).data("onClose", o.onClose);
  1345. jgrid.viewModal.call($t, themodalSelector, {
  1346. gbox: gboxSelector,
  1347. jqm: o.jqModal,
  1348. overlay: o.overlay,
  1349. modal: o.modal,
  1350. overlayClass: o.overlayClass,
  1351. toTop: o.toTop,
  1352. onHide: function (h) {
  1353. h.w.remove();
  1354. if (h.o) { h.o.remove(); }
  1355. }
  1356. });
  1357. if (!closeovrl) {
  1358. $("." + jqID(o.overlayClass)).click(function () {
  1359. if (!checkUpdates()) { return false; }
  1360. hideModal();
  1361. return false;
  1362. });
  1363. }
  1364. $(".fm-button", themodalSelector).hover(
  1365. function () { $(this).addClass(hoverClasses); },
  1366. function () { $(this).removeClass(hoverClasses); }
  1367. );
  1368. $("#sData", frmtb2).click(function () {
  1369. postdata = {};
  1370. $("#FormError", frmtb).hide();
  1371. // all depend on ret array
  1372. //ret[0] - succes
  1373. //ret[1] - msg if not succes
  1374. //ret[2] - the id that will be set if reload after submit false
  1375. getFormData();
  1376. if (postdata[gridId + "_id"] === "_empty") {
  1377. postIt();
  1378. } else if (o.checkOnSubmit === true) {
  1379. diff = compareData(postdata, o._savedData);
  1380. if (diff) {
  1381. $(frmgr).data("disabled", true);
  1382. $(".confirm", themodalSelector).show();
  1383. } else {
  1384. postIt();
  1385. }
  1386. } else {
  1387. postIt();
  1388. }
  1389. return false;
  1390. });
  1391. $("#cData", frmtb2).click(function () {
  1392. if (!checkUpdates()) { return false; }
  1393. hideModal();
  1394. return false;
  1395. });
  1396. $("#nData", frmtb2).click(function () {
  1397. if (!checkUpdates()) { return false; }
  1398. $("#FormError", frmtb).hide();
  1399. var npos = getCurrPos();
  1400. npos[0] = parseInt(npos[0], 10);
  1401. if (npos[0] !== -1 && npos[1][npos[0] + 1]) {
  1402. if (!editFeedback("onclickPgButtons", "next", $(frmgr), npos[1][npos[0]])) { return false; }
  1403. fillData(npos[1][npos[0] + 1], frmgr);
  1404. setSelection.call($self, npos[1][npos[0] + 1]);
  1405. editFeedback("afterclickPgButtons", "next", $(frmgr), npos[1][npos[0] + 1]);
  1406. updateNav(npos[0] + 1, npos);
  1407. }
  1408. return false;
  1409. });
  1410. $("#pData", frmtb2).click(function () {
  1411. if (!checkUpdates()) { return false; }
  1412. $("#FormError", frmtb).hide();
  1413. var ppos = getCurrPos();
  1414. if (ppos[0] !== -1 && ppos[1][ppos[0] - 1]) {
  1415. if (!editFeedback("onclickPgButtons", "prev", $(frmgr), ppos[1][ppos[0]])) { return false; }
  1416. if (hasOneFromClasses($("#" + jqID(ppos[1][ppos[0] - 1])), disabledClass)) { return false; }
  1417. fillData(ppos[1][ppos[0] - 1], frmgr);
  1418. setSelection.call($self, ppos[1][ppos[0] - 1]);
  1419. editFeedback("afterclickPgButtons", "prev", $(frmgr), ppos[1][ppos[0] - 1]);
  1420. updateNav(ppos[0] - 1, ppos);
  1421. }
  1422. return false;
  1423. });
  1424. editFeedback("afterShowForm", $(frmgr), editOrAdd);
  1425. var posInit = getCurrPos();
  1426. updateNav(posInit[0], posInit);
  1427. });
  1428. },
  1429. viewGridRow: function (rowid, oMuligrid) {
  1430. return this.each(function () {
  1431. var $t = this, $self = $($t), p = $t.p;
  1432. if (!$t.grid || p == null || !rowid) { return; }
  1433. // make new copy of the options oMuligrid and use it for ONE specific grid.
  1434. // p.formViewing can contains grid specific options
  1435. // we will don't modify the input options oMuligrid
  1436. var gridId = p.id,
  1437. o = $.extend(true,
  1438. {
  1439. top: 0,
  1440. left: 0,
  1441. width: 0,
  1442. datawidth: "auto",
  1443. height: "auto",
  1444. dataheight: "auto",
  1445. //modal: false,
  1446. //toTop : false,
  1447. //overlay: 30,
  1448. drag: true,
  1449. resize: true,
  1450. //jqModal: true,
  1451. closeOnEscape: false,
  1452. labelswidth: "", //"30%",
  1453. navkeys: [false, 38, 40],
  1454. onClose: null,
  1455. beforeShowForm: null,
  1456. beforeInitData: null,
  1457. viewPagerButtons: true,
  1458. removemodal: true
  1459. },
  1460. base.getGridRes.call($self, "view"),
  1461. jgrid.view || {},
  1462. p.formViewing || {},
  1463. oMuligrid || {});
  1464. var frmgr = "#ViewGrid_" + jqID(gridId), frmtb = "#ViewTbl_" + jqID(gridId), frmtb2 = frmtb + "_2",
  1465. frmgrId = "ViewGrid_" + gridId, frmtbId = "ViewTbl_" + gridId, commonIconClass = o.commonIconClass,
  1466. ids = { themodal: "viewmod" + gridId, modalhead: "viewhd" + gridId, modalcontent: "viewcnt" + gridId, resizeAlso: frmgrId },
  1467. themodalSelector = "#" + jqID(ids.themodal), gboxSelector = p.gBox, colModel = p.colModel,
  1468. maxCols = 1, maxRows = 0,
  1469. viewFeedback = function () {
  1470. var args = $.makeArray(arguments);
  1471. args.unshift("");
  1472. args.unshift("View");
  1473. args.unshift(o);
  1474. return jgridFeedback.apply($t, args);
  1475. },
  1476. hideModal = function () {
  1477. jgrid.hideModal(themodalSelector, {
  1478. gb: gboxSelector,
  1479. jqm: o.jqModal,
  1480. onClose: o.onClose,
  1481. removemodal: o.removemodal
  1482. });
  1483. },
  1484. hoverClasses = getGuiStateStyles.call($t, "hover"),
  1485. disabledClass = getGuiStateStyles.call($t, "disabled");
  1486. function focusaref() { //Sfari 3 issues
  1487. if (o.closeOnEscape === true || o.navkeys[0] === true) {
  1488. setTimeout(function () { $("#cData").focus(); }, 0);
  1489. }
  1490. }
  1491. function createData(rowid1, tb, maxcols) {
  1492. var nm, hc, $trdata, cnt = 0, tmp, retpos = [], ind = base.getInd.call($self, rowid1), i,
  1493. viewDataClasses = getGuiStyles.call($t, "dialog.viewData"), $tb = $(tb),
  1494. viewLabelClasses = getGuiStyles.call($t, "dialog.viewLabel"),
  1495. labelsWidth = String(o.labelswidth) + (!o.labelswidth || isNaN(o.labelswidth) ? "" : "px"),
  1496. tdtmpl = "<td class='" +
  1497. getGuiStyles.call($t, "dialog.viewCellLabel", "CaptionTD form-view-label") +
  1498. (labelsWidth ? "' style='width:" + labelsWidth + ";" : "") +
  1499. "'>&#160;</td><td class='" +
  1500. getGuiStyles.call($t, "dialog.viewCellData", "DataTD form-view-data") +
  1501. "'>&#160;</td>",
  1502. tmpl = "", fmtnum = ["integer", "number", "currency"], max1 = 0, max2 = 0, maxw, setme, viewfld;
  1503. for (i = 0; i < maxcols; i++) {
  1504. tmpl += tdtmpl;
  1505. }
  1506. // find max number align right with property formatter
  1507. $(colModel).each(function () {
  1508. var cm = this;
  1509. if (cm.editrules && cm.editrules.edithidden === true) {
  1510. hc = false;
  1511. } else {
  1512. hc = cm.hidden === true ? true : false;
  1513. }
  1514. if (!hc && cm.align === "right") {
  1515. if (cm.formatter && $.inArray(cm.formatter, fmtnum) !== -1) {
  1516. max1 = Math.max(max1, parseInt(cm.width, 10));
  1517. } else {
  1518. max2 = Math.max(max2, parseInt(cm.width, 10));
  1519. }
  1520. }
  1521. });
  1522. maxw = max1 !== 0 ? max1 : max2 !== 0 ? max2 : 0;
  1523. $(colModel).each(function (iCol) {
  1524. var cm = this;
  1525. nm = cm.name;
  1526. setme = false;
  1527. // hidden fields are included in the form
  1528. if (cm.editrules && cm.editrules.edithidden === true) {
  1529. hc = false;
  1530. } else {
  1531. hc = cm.hidden === true ? true : false;
  1532. }
  1533. viewfld = (typeof cm.viewable !== "boolean") ? true : cm.viewable;
  1534. if (nm !== "cb" && nm !== "subgrid" && nm !== "rn" && viewfld) {
  1535. tmp = ind === false ? "" : jgrid.getDataFieldOfCell.call($t, $t.rows[ind], iCol).html();
  1536. setme = cm.align === "right" && maxw !== 0 ? true : false;
  1537. var frmopt = $.extend({}, { rowabove: false, rowcontent: "" }, cm.formoptions || {}),
  1538. rp = parseInt(frmopt.rowpos, 10) || cnt + 1,
  1539. cp = parseInt((parseInt(frmopt.colpos, 10) || 1) * 2, 10);
  1540. if (frmopt.rowabove) {
  1541. var newdata = $("<tr><td class='contentinfo' colspan='" + (maxcols * 2) + "'>" + frmopt.rowcontent + "</td></tr>");
  1542. $tb.append(newdata);
  1543. newdata[0].rp = rp;
  1544. }
  1545. $trdata = $tb.find("tr[data-rowpos=" + rp + "]");
  1546. if ($trdata.length === 0) {
  1547. $trdata = $("<tr data-rowpos='" + rp + "'></tr>")
  1548. .addClass("FormData")
  1549. .attr("id", "trv_" + nm);
  1550. $trdata.append(tmpl);
  1551. $tb.append($trdata);
  1552. $trdata[0].rp = rp;
  1553. }
  1554. var labelText = (frmopt.label === undefined ? p.colNames[iCol] : frmopt.label),
  1555. $data = $("td:eq(" + (cp - 1) + ")", $trdata[0]),
  1556. $label = $("td:eq(" + (cp - 2) + ")", $trdata[0]);
  1557. $label.html("<label for='" + nm + "'" +
  1558. (viewLabelClasses ? " class='" + viewLabelClasses + "'>" : ">") +
  1559. (labelText || "&nbsp;") + "</label>");
  1560. $data[isEmptyString($data.html()) ? "html" : "append"]("<span id='" + nm + "'" +
  1561. (viewDataClasses ? " class='" + viewDataClasses + "'>" : ">") +
  1562. (tmp || "&nbsp;") + "</span>").attr("id", "v_" + nm);
  1563. if (setme) {
  1564. $("td:eq(" + (cp - 1) + ") span", $trdata[0]).css({ "text-align": "right", width: maxw + "px" });
  1565. }
  1566. if (hc) {
  1567. $label.add($data).css("visibility", "hidden");
  1568. }
  1569. retpos[cnt] = iCol;
  1570. cnt++;
  1571. }
  1572. });
  1573. hideRowsWithoutVissibleCells($tb);
  1574. if (cnt > 0) {
  1575. var idrow = $("<tr class='FormData' style='display:none'><td class='CaptionTD'>&#160;</td><td colspan='" + (maxcols * 2 - 1) + "' class='DataTD'><input class='FormElement' id='id_g' type='text' name='id' value='" + rowid1 + "'/></td></tr>");
  1576. idrow[0].rp = cnt + 99;
  1577. $tb.append(idrow);
  1578. }
  1579. return retpos;
  1580. }
  1581. function fillData(rowid1) {
  1582. var nm, cnt = 0, trv = base.getInd.call($self, rowid1, true), cm;
  1583. if (!trv) { return; }
  1584. $("td", trv).each(function (i) {
  1585. cm = colModel[i];
  1586. nm = cm.name;
  1587. if (nm !== "cb" && nm !== "subgrid" && nm !== "rn") {
  1588. nm = jqID("v_" + nm);
  1589. $("#" + nm + " span", frmtb).html(jgrid.getDataFieldOfCell.call($t, trv, i).html());
  1590. cnt++;
  1591. }
  1592. });
  1593. //hideRowsWithoutVissibleCells($(frmtb));
  1594. if (cnt > 0) { $("#id_g", frmtb).val(rowid1); }
  1595. }
  1596. function updateNav(cr, posarr) {
  1597. var totr = posarr[1].length - 1;
  1598. if (cr === 0) {
  1599. $("#pData", frmtb2).addClass(disabledClass);
  1600. } else if (posarr[1][cr - 1] !== undefined && hasOneFromClasses($("#" + jqID(posarr[1][cr - 1])), disabledClass)) {
  1601. $("#pData", frmtb2).addClass(disabledClass);
  1602. } else {
  1603. $("#pData", frmtb2).removeClass(disabledClass);
  1604. }
  1605. if (cr === totr) {
  1606. $("#nData", frmtb2).addClass(disabledClass);
  1607. } else if (posarr[1][cr + 1] !== undefined && hasOneFromClasses($("#" + jqID(posarr[1][cr + 1])), disabledClass)) {
  1608. $("#nData", frmtb2).addClass(disabledClass);
  1609. } else {
  1610. $("#nData", frmtb2).removeClass(disabledClass);
  1611. }
  1612. }
  1613. function getCurrPos() {
  1614. var rowsInGrid = base.getDataIDs.call($self),
  1615. selrow = $("#id_g", frmtb).val(),
  1616. pos = $.inArray(selrow, rowsInGrid);
  1617. return [pos, rowsInGrid];
  1618. }
  1619. var dh = isNaN(o.dataheight) ? o.dataheight : o.dataheight + "px",
  1620. dw = isNaN(o.datawidth) ? o.datawidth : o.datawidth + "px",
  1621. frmDiv = $("<div class='" + getGuiStyles.call($t, "dialog.body") + "'><form name='FormPost' id='" + frmgrId +
  1622. "' class='FormGrid' style='width:" + dw + ";overflow:auto;position:relative;height:" + dh + ";'></form></div>"),
  1623. frm = frmDiv.children("form.FormGrid"),
  1624. tbl = $("<table id='" + frmtbId +
  1625. "' class='EditTable'><tbody></tbody></table>");
  1626. $(themodalSelector).remove();
  1627. $(colModel).each(function () {
  1628. var fmto = this.formoptions;
  1629. maxCols = Math.max(maxCols, fmto ? fmto.colpos || 0 : 0);
  1630. maxRows = Math.max(maxRows, fmto ? fmto.rowpos || 0 : 0);
  1631. });
  1632. // set the id.
  1633. frm.append(tbl);
  1634. if (!viewFeedback("beforeInitData", frm)) { return; }
  1635. createData(rowid, tbl, maxCols);
  1636. var rtlb = p.direction === "rtl" ? true : false,
  1637. bp = rtlb ? "nData" : "pData",
  1638. bn = rtlb ? "pData" : "nData",
  1639. // buttons at footer
  1640. bP = builderFmButon.call($t, bp, "", mergeCssClasses(commonIconClass, o.prevIcon), "", "left"),
  1641. bN = builderFmButon.call($t, bn, "", mergeCssClasses(commonIconClass, o.nextIcon), "", "right"),
  1642. bC = builderFmButon.call($t, "cData", o.bClose);
  1643. if (maxRows > 0) {
  1644. var sd = [];
  1645. $.each($(tbl)[0].rows, function (i, r) {
  1646. sd[i] = r;
  1647. });
  1648. sd.sort(function (a, b) {
  1649. if (a.rp > b.rp) { return 1; }
  1650. if (a.rp < b.rp) { return -1; }
  1651. return 0;
  1652. });
  1653. $.each(sd, function (index, row) {
  1654. $("tbody", tbl).append(row);
  1655. });
  1656. }
  1657. o.gbox = gboxSelector;
  1658. var bt = $("<div></div>").append(frmDiv).append("<div class='" + getGuiStyles.call($t, "dialog.footer") + "'><table border='0' class='EditTable' id='" + frmtbId + "_2'><tbody><tr id='Act_Buttons'><td class='navButton navButton-" + p.direction + "' width='" + (o.labelswidth || "auto") + "'>" + (rtlb ? bN + bP : bP + bN) + "</td><td class='EditButton EditButton-" + p.direction + "'>" + bC + "</td></tr></tbody></table></div>");
  1659. jgrid.createModal.call($t, ids, bt, o, p.gView, $(p.gView)[0]);
  1660. if (!o.viewPagerButtons) { $("#pData, #nData", frmtb2).hide(); }
  1661. bt = null;
  1662. $(themodalSelector).keydown(function (e) {
  1663. var $focused, idFocused;
  1664. if ($(frmgr).data("disabled") === true) { return false; }//??
  1665. if (e.which === 13) {
  1666. $focused = $(frmtb2).find(":focus");
  1667. idFocused = $focused.attr("id");
  1668. if ($focused.length > 0 && $.inArray(idFocused, ["pData", "nData", "cData"]) >= 0) {
  1669. $focused.trigger("click");
  1670. return false;
  1671. }
  1672. }
  1673. if (e.which === 27) {
  1674. if (o.closeOnEscape) {
  1675. hideModal();
  1676. }
  1677. return false;
  1678. }
  1679. if (o.navkeys[0] === true) {
  1680. if (e.which === o.navkeys[1]) { //up
  1681. $("#pData", frmtb2).trigger("click");
  1682. return false;
  1683. }
  1684. if (e.which === o.navkeys[2]) { //down
  1685. $("#nData", frmtb2).trigger("click");
  1686. return false;
  1687. }
  1688. }
  1689. });
  1690. addFormIcon($("#cData", frmtb2), o.closeicon, commonIconClass);
  1691. viewFeedback("beforeShowForm", $(frmgr));
  1692. jgrid.viewModal.call($t, themodalSelector, {
  1693. gbox: gboxSelector,
  1694. jqm: o.jqModal,
  1695. overlay: o.overlay,
  1696. toTop: o.toTop,
  1697. modal: o.modal,
  1698. onHide: function (h) {
  1699. h.w.remove();
  1700. if (h.o) { h.o.remove(); }
  1701. }
  1702. });
  1703. $(".fm-button:not(." + disabledClass.split(" ").join(".") + ")", frmtb2).hover(
  1704. function () { $(this).addClass(hoverClasses); },
  1705. function () { $(this).removeClass(hoverClasses); }
  1706. );
  1707. focusaref();
  1708. $("#cData", frmtb2).click(function () {
  1709. hideModal();
  1710. return false;
  1711. });
  1712. $("#nData", frmtb2).click(function () {
  1713. $("#FormError", frmtb).hide();
  1714. var npos = getCurrPos();
  1715. npos[0] = parseInt(npos[0], 10);
  1716. if (npos[0] !== -1 && npos[1][npos[0] + 1]) {
  1717. if (!viewFeedback("onclickPgButtons", "next", $(frmgr), npos[1][npos[0]])) { return false; }
  1718. fillData(npos[1][npos[0] + 1]);
  1719. base.setSelection.call($self, npos[1][npos[0] + 1]);
  1720. viewFeedback("afterclickPgButtons", "next", $(frmgr), npos[1][npos[0] + 1]);
  1721. updateNav(npos[0] + 1, npos);
  1722. }
  1723. focusaref();
  1724. return false;
  1725. });
  1726. $("#pData", frmtb2).click(function () {
  1727. $("#FormError", frmtb).hide();
  1728. var ppos = getCurrPos();
  1729. if (ppos[0] !== -1 && ppos[1][ppos[0] - 1]) {
  1730. if (!viewFeedback("onclickPgButtons", "prev", $(frmgr), ppos[1][ppos[0]])) { return false; }
  1731. fillData(ppos[1][ppos[0] - 1]);
  1732. base.setSelection.call($self, ppos[1][ppos[0] - 1]);
  1733. viewFeedback("afterclickPgButtons", "prev", $(frmgr), ppos[1][ppos[0] - 1]);
  1734. updateNav(ppos[0] - 1, ppos);
  1735. }
  1736. focusaref();
  1737. return false;
  1738. });
  1739. var posInit = getCurrPos();
  1740. updateNav(posInit[0], posInit);
  1741. });
  1742. },
  1743. delGridRow: function (rowids, oMuligrid) {
  1744. return this.each(function () {
  1745. var $t = this, p = $t.p, $self = $($t);
  1746. if (!$t.grid || p == null || !rowids) { return; }
  1747. // make new copy of the options oMuligrid and use it for ONE specific grid.
  1748. // p.formDeleting can contains grid specific options
  1749. // we will don't modify the input options oMuligrid
  1750. var gridId = p.id,
  1751. o = $.extend(true,
  1752. {
  1753. top: 0,
  1754. left: 0,
  1755. width: 240,
  1756. removemodal: true,
  1757. height: "auto",
  1758. dataheight: "auto",
  1759. datawidth: "auto",
  1760. //modal: false,
  1761. //toTop: false,
  1762. //overlay: 30,
  1763. drag: true,
  1764. resize: true,
  1765. url: "",
  1766. mtype: "POST",
  1767. reloadAfterSubmit: true,
  1768. beforeShowForm: null,
  1769. beforeInitData: null,
  1770. afterShowForm: null,
  1771. beforeSubmit: null,
  1772. onclickSubmit: null,
  1773. afterSubmit: null,
  1774. //jqModal : true,
  1775. closeOnEscape: false,
  1776. delData: {},
  1777. idSeparator: ",",
  1778. onClose: null,
  1779. ajaxDelOptions: {},
  1780. processing: false,
  1781. serializeDelData: null,
  1782. useDataProxy: false,
  1783. delui: "disable", // "enable", "enable" or "block"
  1784. deltext: base.getGridRes.call($self, "defaults.deltext") || "Deleting..."
  1785. },
  1786. base.getGridRes.call($self, "del"),
  1787. jgrid.del || {},
  1788. p.formDeleting || {},
  1789. oMuligrid || {});
  1790. var dtblId = "DelTbl_" + gridId, dtbl = "#DelTbl_" + jqID(gridId), postd, idname, opers, oper,
  1791. ids = { themodal: "delmod" + gridId, modalhead: "delhd" + gridId, modalcontent: "delcnt" + gridId, resizeAlso: dtblId },
  1792. themodalSelector = "#" + jqID(ids.themodal), gboxSelector = p.gBox, commonIconClass = o.commonIconClass,
  1793. deleteFeedback = function () {
  1794. var args = $.makeArray(arguments);
  1795. args.unshift("");
  1796. args.unshift("Delete");
  1797. args.unshift(o);
  1798. return jgridFeedback.apply($t, args);
  1799. },
  1800. hoverClasses = getGuiStateStyles.call($t, "hover"),
  1801. activeClass = getGuiStateStyles.call($t, "active"),
  1802. errorClass = getGuiStateStyles.call($t, "error");
  1803. if (!$.isArray(rowids)) { rowids = [String(rowids)]; }
  1804. if ($(themodalSelector)[0] !== undefined) {
  1805. if (!deleteFeedback("beforeInitData", $(dtbl))) { return; }
  1806. $("#DelData>td", dtbl).text(rowids.join(o.idSeparator)).data("rowids", rowids);
  1807. $("#DelError", dtbl).hide();
  1808. if (o.processing === true) {
  1809. o.processing = false;
  1810. $("#dData", dtbl).removeClass(activeClass);
  1811. }
  1812. deleteFeedback("beforeShowForm", $(dtbl));
  1813. jgrid.viewModal.call($t, themodalSelector, {
  1814. gbox: gboxSelector,
  1815. jqm: o.jqModal,
  1816. jqM: false,
  1817. overlay: o.overlay,
  1818. toTop: o.toTop,
  1819. modal: o.modal
  1820. });
  1821. deleteFeedback("afterShowForm", $(dtbl));
  1822. } else {
  1823. var dh = isNaN(o.dataheight) ? o.dataheight : o.dataheight + "px",
  1824. dw = isNaN(o.datawidth) ? o.datawidth : o.datawidth + "px",
  1825. tbl = "<div class='" + getGuiStyles.call($t, "dialog.body") + "'><div id='" + dtblId + "' class='formdata' style='width:" + dw + ";overflow:auto;position:relative;height:" + dh + ";'>";
  1826. tbl += "<table class='DelTable'><tbody>";
  1827. // error data
  1828. tbl += "<tr id='DelError' style='display:none'><td class='" + errorClass + "'></td></tr>";
  1829. tbl += "<tr id='DelData' style='display:none'><td >" + rowids.join(o.idSeparator) + "</td></tr>";
  1830. tbl += "<tr><td class='delmsg'>" + o.msg + "</td></tr>";
  1831. // buttons at footer
  1832. tbl += "</tbody></table></div></div>";
  1833. var bS = builderFmButon.call($t, "dData", o.bSubmit),
  1834. bC = builderFmButon.call($t, "eData", o.bCancel);
  1835. tbl += "<div class='" + getGuiStyles.call($t, "dialog.footer") + "'><table class='EditTable' id='" +
  1836. dtblId + "_2'><tbody><tr><td><hr class='" +
  1837. getGuiStyles.call($t, "dialog.hr") + "' style='margin:1px'/></td></tr><tr><td class='DelButton EditButton EditButton-" +
  1838. p.direction + "'>" + bS + "&#160;" + bC + "</td></tr></tbody></table></div>";
  1839. o.gbox = gboxSelector;
  1840. jgrid.createModal.call($t, ids, tbl, o, p.gView, $(p.gView)[0]);
  1841. $("#DelData>td", dtbl).data("rowids", rowids);
  1842. if (!deleteFeedback("beforeInitData", $(tbl))) { return; }
  1843. $(".fm-button", dtbl + "_2").hover(
  1844. function () { $(this).addClass(hoverClasses); },
  1845. function () { $(this).removeClass(hoverClasses); }
  1846. );
  1847. addFormIcon($("#dData", dtbl + "_2"), o.delicon, commonIconClass);
  1848. addFormIcon($("#eData", dtbl + "_2"), o.cancelicon, commonIconClass);
  1849. $("#dData", dtbl + "_2").click(function () {
  1850. var ret = [true, ""], pk, $delData = $("#DelData>td", dtbl),
  1851. postdata = $delData.text(), //the pair is name=val1,val2,...
  1852. formRowIds = $delData.data("rowids"),
  1853. cs = {};
  1854. if ($.isFunction(o.onclickSubmit)) { cs = o.onclickSubmit.call($t, o, postdata, formRowIds) || {}; }
  1855. if ($.isFunction(o.beforeSubmit)) { ret = o.beforeSubmit.call($t, postdata, formRowIds) || ret; }
  1856. if (ret[0] && !o.processing) {
  1857. o.processing = true;
  1858. opers = p.prmNames;
  1859. postd = $.extend({}, o.delData, cs);
  1860. oper = opers.oper;
  1861. postd[oper] = opers.deloper;
  1862. idname = opers.id;
  1863. postdata = formRowIds.slice();
  1864. if (!postdata.length) { return false; }
  1865. for (pk in postdata) {
  1866. if (postdata.hasOwnProperty(pk)) {
  1867. postdata[pk] = jgrid.stripPref(p.idPrefix, postdata[pk]);
  1868. }
  1869. }
  1870. postd[idname] = postdata.join(o.idSeparator);
  1871. $(this).addClass(activeClass);
  1872. var url = o.url || p.editurl,
  1873. ajaxOptions = $.extend({
  1874. url: $.isFunction(url) ? url.call($t, postd[idname], postd, o, formRowIds) : url,
  1875. type: o.mtype,
  1876. data: $.isFunction(o.serializeDelData) ? o.serializeDelData.call($t, postd, formRowIds) : postd,
  1877. complete: function (jqXHR, textStatus) {
  1878. var i;
  1879. $self.jqGrid("progressBar", { method: "hide", loadtype: o.delui });
  1880. $("#dData", dtbl + "_2").removeClass(activeClass);
  1881. if ((jqXHR.status >= 300 && jqXHR.status !== 304) || (jqXHR.status === 0 && jqXHR.readyState === 4)) {
  1882. ret[0] = false;
  1883. if ($.isFunction(o.errorTextFormat)) {
  1884. ret[1] = o.errorTextFormat.call($t, jqXHR);
  1885. } else {
  1886. ret[1] = textStatus + " Status: '" + jqXHR.statusText + "'. Error code: " + jqXHR.status;
  1887. }
  1888. } else {
  1889. // data is posted successful
  1890. // execute aftersubmit with the returned data from server
  1891. if ($.isFunction(o.afterSubmit)) {
  1892. ret = o.afterSubmit.call($t, jqXHR, postd, formRowIds) || [true];
  1893. }
  1894. }
  1895. if (ret[0] === false) {
  1896. $("#DelError>td", dtbl).html(ret[1]);
  1897. $("#DelError", dtbl).show();
  1898. } else {
  1899. if (p.datatype === "local" || p.treeGrid === true || !o.reloadAfterSubmit) {
  1900. if (p.treeGrid === true) {
  1901. try { base.delTreeNode.call($self, formRowIds[0]); } catch (ignore) { }
  1902. } else {
  1903. formRowIds = formRowIds.slice(); // make copy for save deleting
  1904. for (i = 0; i < formRowIds.length; i++) {
  1905. base.delRowData.call($self, formRowIds[i]);
  1906. }
  1907. }
  1908. }
  1909. if (o.reloadAfterSubmit) {
  1910. $self.trigger("reloadGrid", [$.extend({}, o.reloadGridOptions || {})]);
  1911. }
  1912. setTimeout(function () {
  1913. deleteFeedback("afterComplete", jqXHR, postdata, $(dtbl), formRowIds);
  1914. }, 50);
  1915. }
  1916. o.processing = false;
  1917. if (ret[0]) {
  1918. jgrid.hideModal(themodalSelector, {
  1919. gb: gboxSelector,
  1920. jqm: o.jqModal,
  1921. onClose: o.onClose,
  1922. removemodal: o.removemodal
  1923. });
  1924. }
  1925. }
  1926. }, jgrid.ajaxOptions, o.ajaxDelOptions);
  1927. if (!ajaxOptions.url && !o.useDataProxy) {
  1928. if ($.isFunction(p.dataProxy)) {
  1929. o.useDataProxy = true;
  1930. } else {
  1931. ret[0] = false;
  1932. ret[1] += " " + jgrid.errors.nourl;
  1933. }
  1934. }
  1935. if (ret[0]) {
  1936. $self.jqGrid("progressBar", { method: "show", loadtype: o.delui, htmlcontent: o.deltext });
  1937. if (o.useDataProxy) {
  1938. var dpret = p.dataProxy.call($t, ajaxOptions, "del_" + gridId);
  1939. if (dpret === undefined) {
  1940. dpret = [true, ""];
  1941. }
  1942. if (dpret[0] === false) {
  1943. ret[0] = false;
  1944. ret[1] = dpret[1] || "Error deleting the selected row!";
  1945. } else {
  1946. jgrid.hideModal(themodalSelector, {
  1947. gb: gboxSelector,
  1948. jqm: o.jqModal,
  1949. onClose: o.onClose,
  1950. removemodal: o.removemodal
  1951. });
  1952. }
  1953. } else {
  1954. if (ajaxOptions.url === "clientArray") {
  1955. postd = ajaxOptions.data;
  1956. ajaxOptions.complete({ status: 200, statusText: "" }, "");
  1957. } else {
  1958. $.ajax(ajaxOptions);
  1959. }
  1960. }
  1961. }
  1962. }
  1963. if (ret[0] === false) {
  1964. $("#DelError>td", dtbl).html(ret[1]);
  1965. $("#DelError", dtbl).show();
  1966. }
  1967. return false;
  1968. });
  1969. $("#eData", dtbl + "_2").click(function () {
  1970. jgrid.hideModal(themodalSelector, {
  1971. gb: gboxSelector,
  1972. jqm: o.jqModal,
  1973. onClose: o.onClose,
  1974. removemodal: o.removemodal
  1975. });
  1976. return false;
  1977. });
  1978. deleteFeedback("beforeShowForm", $(dtbl));
  1979. jgrid.viewModal.call($t, themodalSelector, {
  1980. gbox: gboxSelector,
  1981. jqm: o.jqModal,
  1982. overlay: o.overlay,
  1983. toTop: o.toTop,
  1984. modal: o.modal
  1985. });
  1986. deleteFeedback("afterShowForm", $(dtbl));
  1987. }
  1988. if (o.closeOnEscape === true) {
  1989. setTimeout(function () {
  1990. $(".ui-jqdialog-titlebar-close", "#" + jqID(ids.modalhead))
  1991. .attr("tabindex", "-1")
  1992. .focus();
  1993. }, 0);
  1994. }
  1995. });
  1996. },
  1997. navGrid: function (elem, oMuligrid, pEdit, pAdd, pDel, pSearch, pView) {
  1998. if (typeof elem === "object") {
  1999. // the option pager are skipped
  2000. pView = pSearch;
  2001. pSearch = pDel;
  2002. pDel = pAdd;
  2003. pAdd = pEdit;
  2004. pEdit = oMuligrid;
  2005. oMuligrid = elem;
  2006. elem = undefined;
  2007. }
  2008. pAdd = pAdd || {};
  2009. pEdit = pEdit || {};
  2010. pView = pView || {};
  2011. pDel = pDel || {};
  2012. pSearch = pSearch || {};
  2013. return this.each(function () {
  2014. var $t = this, p = $t.p, $self = $($t);
  2015. if (!$t.grid || p == null || ($t.nav && $(elem).find(".navtable").length > 0)) {
  2016. return; // error or the navigator bar already exists
  2017. }
  2018. // make new copy of the options oMuligrid and use it for ONE specific grid.
  2019. // p.navOptions can contains grid specific options
  2020. // we will don't modify the input options oMuligrid
  2021. var gridId = p.id,
  2022. o = $.extend(
  2023. {
  2024. edit: true,
  2025. add: true,
  2026. del: true,
  2027. search: true,
  2028. refresh: true,
  2029. refreshstate: "firstpage",
  2030. view: false,
  2031. closeOnEscape: true,
  2032. beforeRefresh: null,
  2033. afterRefresh: null,
  2034. cloneToTop: false,
  2035. hideEmptyPagerParts: true,
  2036. //jqModal: true,
  2037. alertwidth: 200,
  2038. alertheight: "auto",
  2039. alerttop: null,
  2040. //alertToTop: false,
  2041. removemodal: true,
  2042. alertleft: null,
  2043. alertzIndex: null,
  2044. iconsOverText: false
  2045. },
  2046. base.getGridRes.call($self, "nav"),
  2047. jgrid.nav || {},
  2048. p.navOptions || {},
  2049. oMuligrid || {}
  2050. );
  2051. // set default position depend of RTL/LTR direction of the grid
  2052. o.position = o.position || (p.direction === "rtl" ? "right" : "left");
  2053. var twd, tdw, gridIdEscaped = p.idSel, gboxSelector = p.gBox, commonIconClass = o.commonIconClass,
  2054. alertIDs = { themodal: "alertmod_" + gridId, modalhead: "alerthd_" + gridId, modalcontent: "alertcnt_" + gridId },
  2055. createModalAlert = function () {
  2056. return function () {
  2057. var documentElement = document.documentElement, w = window, left = 1024, top = 768,
  2058. offsetGbox = $self.closest(".ui-jqgrid").offset();
  2059. if ($("#" + jqID(alertIDs.themodal))[0] === undefined) {
  2060. if (!o.alerttop && !o.alertleft) {
  2061. if (w.innerWidth !== undefined) {
  2062. left = w.innerWidth;
  2063. top = w.innerHeight;
  2064. } else if (documentElement != null && documentElement.clientWidth !== undefined && documentElement.clientWidth !== 0) {
  2065. left = documentElement.clientWidth;
  2066. top = documentElement.clientHeight;
  2067. }
  2068. left = left / 2 - parseInt(o.alertwidth, 10) / 2 - offsetGbox.left +
  2069. ((w.pageXOffset !== undefined) ? w.pageXOffset : (documentElement || document.body.parentNode || document.body).scrollLeft);
  2070. top = top / 2 - 25 - offsetGbox.top +
  2071. ((w.pageYOffset !== undefined) ? w.pageYOffset : (documentElement || document.body.parentNode || document.body).scrollTop);
  2072. }
  2073. jgrid.createModal.call($t, alertIDs,
  2074. "<div class='" + getGuiStyles.call($t, "dialog.body") + "'><div>" + o.alerttext + "</div></div>",
  2075. {
  2076. gbox: gboxSelector,
  2077. jqModal: o.jqModal,
  2078. drag: true,
  2079. resize: true,
  2080. caption: o.alertcap,
  2081. top: o.alerttop != null ? o.alerttop : top,
  2082. left: o.alertleft != null ? o.alertleft : left,
  2083. width: o.alertwidth,
  2084. height: o.alertheight,
  2085. closeOnEscape: o.closeOnEscape,
  2086. zIndex: o.alertzIndex,
  2087. removemodal: o.removemodal
  2088. },
  2089. p.gView,
  2090. $(gboxSelector)[0],
  2091. false);
  2092. }
  2093. jgrid.viewModal.call($t, "#" + jqID(alertIDs.themodal), {
  2094. gbox: gboxSelector,
  2095. toTop: o.alertToTop,
  2096. jqm: o.jqModal
  2097. });
  2098. var $close = $("#" + jqID(alertIDs.modalhead)).find(".ui-jqdialog-titlebar-close");
  2099. $close.attr({ tabindex: "0", href: "#", role: "button" });
  2100. setTimeout(function () {
  2101. $close.focus();
  2102. }, 50);
  2103. };
  2104. },
  2105. viewModalAlert = createModalAlert(),
  2106. navtbl,
  2107. clickOnEnter = function (e) {
  2108. var $focused;
  2109. if (e.which === 13) {
  2110. $focused = $(this).find(".ui-pg-button").filter(":focus");
  2111. if ($focused.length > 0) {
  2112. // $focused[0].id == "view_list" or "view_list_top"
  2113. var focusedId = $focused[0].id,
  2114. actionName = focusedId.substr(0,
  2115. $(this).closest(".ui-jqgrid-toppager").length > 0 ?
  2116. focusedId.length - gridId.length - 5 : // "_" + "_top"
  2117. focusedId.length - gridId.length - 1), // view "_"
  2118. gialogId = actionName + "mod" + p.id, // "viewmodlist"
  2119. visibleDailogIds = $(".ui-jqdialog").filter(":visible").map(function () { return this.id; });
  2120. if ($.inArray(gialogId, visibleDailogIds) < 0) {
  2121. // simulate click only if the dialog is not already opened
  2122. $focused.trigger("click");
  2123. return false;
  2124. }
  2125. }
  2126. }
  2127. },
  2128. hoverClasses = getGuiStateStyles.call($t, "hover"),
  2129. disabledClass = getGuiStateStyles.call($t, "disabled"),
  2130. navButtonClass = getGuiStyles.call($t, "navButton", "ui-pg-button");
  2131. if (!$t.grid) {
  2132. return; // error
  2133. }
  2134. // set modalAlert which can be used inside of
  2135. $t.modalAlert = viewModalAlert;
  2136. if (elem === undefined) {
  2137. if (p.pager) {
  2138. elem = p.pager;
  2139. if (p.toppager) {
  2140. o.cloneToTop = true; // add buttons to both pagers
  2141. }
  2142. } else if (p.toppager) {
  2143. elem = p.toppager;
  2144. }
  2145. }
  2146. var clone = 1, i, tbd, pgid, elemids, iPart, pagerTable, $pagerPart, pagerParts = ["left", "center", "right"],
  2147. navButtonDisabledClass = getGuiStyles.call($t, "navButton", "ui-pg-button" + " " + getGuiStateStyles.call($t, "disabled")),
  2148. sep = "<div class='" + navButtonDisabledClass + "'><span class='ui-separator'></span></div>",
  2149. onHoverIn = function () {
  2150. if (!hasOneFromClasses(this, disabledClass)) {
  2151. $(this).addClass(hoverClasses);
  2152. }
  2153. },
  2154. onHoverOut = function () {
  2155. $(this).removeClass(hoverClasses);
  2156. },
  2157. onAdd = function () {
  2158. if (!hasOneFromClasses(this, disabledClass)) {
  2159. if ($.isFunction(o.addfunc)) {
  2160. o.addfunc.call($t, pAdd);
  2161. } else {
  2162. base.editGridRow.call($self, "new", pAdd);
  2163. }
  2164. }
  2165. return false;
  2166. },
  2167. editOrViewOfSelectedRow = function (func, methodName, param) {
  2168. if (!hasOneFromClasses(this, disabledClass)) {
  2169. var sr = p.selrow;
  2170. if (sr) {
  2171. if ($.isFunction(func)) {
  2172. func.call($t, sr, param);
  2173. } else {
  2174. base[methodName].call($self, sr, param);
  2175. }
  2176. } else {
  2177. viewModalAlert();
  2178. }
  2179. }
  2180. return false;
  2181. },
  2182. onEdit = function () {
  2183. return editOrViewOfSelectedRow.call(this, o.editfunc, "editGridRow", pEdit);
  2184. },
  2185. onView = function () {
  2186. return editOrViewOfSelectedRow.call(this, o.viewfunc, "viewGridRow", pView);
  2187. },
  2188. onDel = function () {
  2189. var dr;
  2190. if (!hasOneFromClasses(this, disabledClass)) {
  2191. if (p.multiselect) {
  2192. dr = p.selarrrow;
  2193. if (dr.length === 0) { dr = null; }
  2194. } else {
  2195. dr = p.selrow;
  2196. }
  2197. if (dr) {
  2198. if ($.isFunction(o.delfunc)) {
  2199. o.delfunc.call($t, dr, pDel);
  2200. } else {
  2201. base.delGridRow.call($self, dr, pDel);
  2202. }
  2203. } else {
  2204. viewModalAlert();
  2205. }
  2206. }
  2207. return false;
  2208. },
  2209. onSearch = function () {
  2210. if (!hasOneFromClasses(this, disabledClass)) {
  2211. if ($.isFunction(o.searchfunc)) {
  2212. o.searchfunc.call($t, pSearch);
  2213. } else {
  2214. base.searchGrid.call($self, pSearch);
  2215. }
  2216. }
  2217. return false;
  2218. },
  2219. onRefresh = function () {
  2220. if (!hasOneFromClasses(this, disabledClass)) {
  2221. if ($.isFunction(o.beforeRefresh)) { o.beforeRefresh.call($t); }
  2222. p.search = false;
  2223. p.resetsearch = true;
  2224. try {
  2225. if (o.refreshstate !== "currentfilter") {
  2226. p.postData.filters = "";
  2227. try {
  2228. $("#fbox_" + gridIdEscaped.substr(1)).jqFilter("resetFilter");
  2229. } catch (ignore) { }
  2230. if ($.isFunction($t.clearToolbar)) { $t.clearToolbar(false); }
  2231. }
  2232. } catch (ignore) { }
  2233. switch (o.refreshstate) {
  2234. case "firstpage":
  2235. $self.trigger("reloadGrid", [$.extend({}, o.reloadGridOptions || {}, { page: 1 })]);
  2236. break;
  2237. case "current":
  2238. case "currentfilter":
  2239. $self.trigger("reloadGrid", [$.extend({}, o.reloadGridOptions || {}, { current: true })]);
  2240. break;
  2241. }
  2242. if ($.isFunction(o.afterRefresh)) { o.afterRefresh.call($t); }
  2243. }
  2244. return false;
  2245. },
  2246. stdButtonActivation = function (name, id, onClick) {
  2247. var $button = $("<div class='" + navButtonClass + "' tabindex='0' role='button'></div>"),
  2248. iconClass = o[name + "icon"],
  2249. iconText = $.trim(o[name + "text"]);
  2250. $button.append("<div class='ui-pg-div'><span class='" +
  2251. (o.iconsOverText ?
  2252. mergeCssClasses("ui-pg-button-icon-over-text", commonIconClass, iconClass) :
  2253. mergeCssClasses(commonIconClass, iconClass)) +
  2254. "'></span>" +
  2255. (iconText ? "<span class='ui-pg-button-text" + (o.iconsOverText ? " ui-pg-button-icon-over-text" : "") + "'>" + iconText + "</span>" : "") +
  2256. "</div>");
  2257. $(navtbl).append($button);
  2258. $button.attr({ "title": o[name + "title"] || "", id: id || name + "_" + elemids })
  2259. .click(onClick)
  2260. .hover(onHoverIn, onHoverOut);
  2261. return $button;
  2262. };
  2263. if (o.cloneToTop && p.toppager) { clone = 2; }
  2264. for (i = 0; i < clone; i++) {
  2265. // we can set aria-activedescendant="idOfFirstButton" later
  2266. navtbl = $("<div" + " class='ui-pg-table navtable' role='toolbar' style='float:" +
  2267. (p.direction === "rtl" ? "right" : "left") +
  2268. ";table-layout:auto;'></div>");
  2269. if (i === 0) {
  2270. pgid = elem;
  2271. elemids = gridId;
  2272. if (pgid === p.toppager) {
  2273. elemids += "_top";
  2274. clone = 1;
  2275. }
  2276. } else {
  2277. pgid = p.toppager;
  2278. elemids = gridId + "_top";
  2279. }
  2280. if (o.add) {
  2281. stdButtonActivation("add", pAdd.id, onAdd);
  2282. }
  2283. if (o.edit) {
  2284. stdButtonActivation("edit", pEdit.id, onEdit);
  2285. }
  2286. if (o.view) {
  2287. stdButtonActivation("view", pView.id, onView);
  2288. }
  2289. if (o.del) {
  2290. stdButtonActivation("del", pDel.id, onDel);
  2291. }
  2292. if (o.add || o.edit || o.del || o.view) { $(navtbl).append(sep); }
  2293. if (o.search) {
  2294. tbd = stdButtonActivation("search", pSearch.id, onSearch);
  2295. if (pSearch.showOnLoad && pSearch.showOnLoad === true) {
  2296. $(tbd, navtbl).click();
  2297. }
  2298. }
  2299. if (o.refresh) {
  2300. stdButtonActivation("refresh", "", onRefresh);
  2301. }
  2302. // TODO use setWidthOfPagerTdWithPager or remove at all and use div structure with wrapping
  2303. tdw = $(".ui-jqgrid>.ui-jqgrid-view").css("font-size") || "11px";
  2304. $("body").append("<div id='testpg2' class='" + getGuiStyles.call($t, "gBox", "ui-jqgrid") + "' style='font-size:" + tdw + ";visibility:hidden;' ></div>");
  2305. twd = $(navtbl).clone().appendTo("#testpg2").width();
  2306. $("#testpg2").remove();
  2307. $(pgid + "_" + o.position, pgid).append(navtbl);
  2308. if (o.hideEmptyPagerParts) {
  2309. for (iPart = 0; iPart < pagerParts.length; iPart++) {
  2310. if (pagerParts[iPart] !== o.position) {
  2311. $pagerPart = $(pgid + "_" + pagerParts[iPart], pgid);
  2312. if ($pagerPart.length === 0 || $pagerPart[0].childNodes.length === 0) {
  2313. $pagerPart.hide();
  2314. } else if ($pagerPart[0].childNodes.length === 1) {
  2315. pagerTable = $pagerPart[0].firstChild;
  2316. if ($(pagerTable).is("table.ui-pg-table") && (pagerTable.rows === 0 || pagerTable.rows[0].cells.length === 0)) {
  2317. $pagerPart.hide();
  2318. }
  2319. }
  2320. }
  2321. }
  2322. }
  2323. if (p._nvtd) {
  2324. if (twd > p._nvtd[0]) {
  2325. $(pgid + "_" + o.position, pgid).width(twd);
  2326. p._nvtd[0] = twd;
  2327. }
  2328. p._nvtd[1] = twd;
  2329. }
  2330. $t.nav = true;
  2331. navtbl.on("keydown.jqGrid", clickOnEnter);
  2332. }
  2333. $self.triggerHandler("jqGridResetFrozenHeights");
  2334. });
  2335. },
  2336. navButtonAdd: function (elem, oMuligrid) {
  2337. if (typeof elem === "object") {
  2338. oMuligrid = elem;
  2339. elem = undefined;
  2340. }
  2341. return this.each(function () {
  2342. var $t = this, p = $t.p;
  2343. if (!$t.grid) { return; }
  2344. var o = $.extend(
  2345. {
  2346. caption: "newButton",
  2347. title: "",
  2348. onClickButton: null,
  2349. position: "last",
  2350. iconsOverText: false
  2351. },
  2352. base.getGridRes.call($($t), "nav"),
  2353. jgrid.nav || {},
  2354. p.navOptions || {},
  2355. oMuligrid || {}
  2356. ),
  2357. id = o.id,
  2358. hoverClasses = getGuiStateStyles.call($t, "hover"),
  2359. disabledClass = getGuiStateStyles.call($t, "disabled"),
  2360. navButtonClass = getGuiStyles.call($t, "navButton", "ui-pg-button");
  2361. if (elem === undefined) {
  2362. if (p.pager) {
  2363. base.navButtonAdd.call($($t), p.pager, o);
  2364. if (p.toppager) {
  2365. elem = p.toppager;
  2366. if (id) {
  2367. id += "_top";
  2368. }
  2369. } else {
  2370. return;
  2371. }
  2372. } else if (p.toppager) {
  2373. elem = p.toppager;
  2374. }
  2375. }
  2376. if (typeof elem === "string" && elem.indexOf("#") !== 0) { elem = "#" + jqID(elem); }
  2377. var findnav = $(".navtable", elem), commonIconClass = o.commonIconClass;
  2378. if (findnav.length > 0) {
  2379. if (id && findnav.find("#" + jqID(id)).length > 0) { return; }
  2380. var tbd = $("<div tabindex='0' role='button'></div>");
  2381. if (o.buttonicon.toString().toUpperCase() === "NONE") {
  2382. $(tbd).addClass(navButtonClass).append("<div class='ui-pg-div'>" +
  2383. (o.caption ? "<span class='ui-pg-button-text" + (o.iconsOverText ? " ui-pg-button-icon-over-text" : "") + "'>" + o.caption + "</span>" : "") +
  2384. "</div>");
  2385. } else {
  2386. $(tbd).addClass(navButtonClass).append("<div class='ui-pg-div'>" +
  2387. "<span class='" +
  2388. (o.iconsOverText ?
  2389. mergeCssClasses("ui-pg-button-icon-over-text", commonIconClass, o.buttonicon) :
  2390. mergeCssClasses(commonIconClass, o.buttonicon)) +
  2391. "'></span>" +
  2392. (o.caption ? "<span class='ui-pg-button-text" + (o.iconsOverText ? " ui-pg-button-icon-over-text" : "") + "'>" + o.caption + "</span>" : "") +
  2393. "</div>");
  2394. }
  2395. if (id) { $(tbd).attr("id", id); }
  2396. if (o.position === "first" && findnav.children("div.ui-pg-button").length > 0) {
  2397. findnav.children("div.ui-pg-button").first().before(tbd);
  2398. } else {
  2399. findnav.append(tbd);
  2400. }
  2401. $(tbd, findnav)
  2402. .attr("title", o.title || "")
  2403. .click(function (e) {
  2404. if (!hasOneFromClasses(this, disabledClass)) {
  2405. if ($.isFunction(o.onClickButton)) { o.onClickButton.call($t, o, e); }
  2406. }
  2407. return false;
  2408. })
  2409. .hover(
  2410. function () {
  2411. if (!hasOneFromClasses(this, disabledClass)) {
  2412. $(this).addClass(hoverClasses);
  2413. }
  2414. },
  2415. function () { $(this).removeClass(hoverClasses); }
  2416. );
  2417. $($t).triggerHandler("jqGridResetFrozenHeights");
  2418. }
  2419. });
  2420. },
  2421. navSeparatorAdd: function (elem, o) {
  2422. o = $.extend({
  2423. sepclass: "ui-separator",
  2424. sepcontent: "",
  2425. position: "last"
  2426. }, o || {});
  2427. return this.each(function () {
  2428. if (!this.grid) { return; }
  2429. var $t = this, p = $t.p,
  2430. navButtonClass = getGuiStyles.call($t, "navButton", "ui-pg-button" + " " + getGuiStateStyles.call($t, "disabled"));
  2431. if (elem === undefined) {
  2432. if (p.pager) {
  2433. base.navSeparatorAdd.call($($t), p.pager, o);
  2434. if (p.toppager) {
  2435. elem = p.toppager;
  2436. } else {
  2437. return;
  2438. }
  2439. } else if (p.toppager) {
  2440. elem = p.toppager;
  2441. }
  2442. }
  2443. if (typeof elem === "string" && elem.indexOf("#") !== 0) { elem = "#" + jqID(elem); }
  2444. var $nav = $(".navtable", elem);
  2445. if ($nav.length > 0) {
  2446. var sep = "<div class='" + navButtonClass + "'><span class='" + o.sepclass + "'></span>" + o.sepcontent + "</div>";
  2447. if (o.position === "first") {
  2448. if ($nav.children("div.ui-pg-button").length === 0) {
  2449. $nav.append(sep);
  2450. } else {
  2451. $nav.children("div.ui-pg-button").first().before(sep);
  2452. }
  2453. } else {
  2454. $nav.append(sep);
  2455. }
  2456. }
  2457. });
  2458. },
  2459. GridToForm: function (rowid, formid) {
  2460. return this.each(function () {
  2461. var $t = this, i, $field, iField, $fieldi;
  2462. if (!$t.grid) { return; }
  2463. var rowdata = base.getRowData.call($($t), rowid);
  2464. if (rowdata) {
  2465. for (i in rowdata) {
  2466. if (rowdata.hasOwnProperty(i)) {
  2467. $field = $("[name=" + jqID(i) + "]", formid);
  2468. if ($field.is("input:radio") || $field.is("input:checkbox")) {
  2469. for (iField = 0; iField < $field.length; iField++) {
  2470. $fieldi = $($field[iField]);
  2471. $fieldi.prop("checked", $fieldi.val() === String(rowdata[i]));
  2472. }
  2473. } else {
  2474. // this is very slow on big table and form.
  2475. $field.val(isEmptyString(rowdata[i]) ? "" : rowdata[i]);
  2476. }
  2477. }
  2478. }
  2479. }
  2480. });
  2481. },
  2482. FormToGrid: function (rowid, formid, mode, position) {
  2483. return this.each(function () {
  2484. var $t = this;
  2485. if (!$t.grid) { return; }
  2486. if (!mode) { mode = "set"; }
  2487. if (!position) { position = "first"; }
  2488. var fields = $(formid).serializeArray();
  2489. var griddata = {};
  2490. $.each(fields, function (i, field) {
  2491. griddata[field.name] = field.value;
  2492. });
  2493. if (mode === "add") {
  2494. base.addRowData.call($($t), rowid, griddata, position);
  2495. } else if (mode === "set") {
  2496. base.setRowData.call($($t), rowid, griddata);
  2497. }
  2498. });
  2499. }
  2500. });
  2501. // end module grid.formedit
  2502. }));