jsgrid.min.js 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583
  1. /*
  2. * jsGrid v1.4.1 (http://js-grid.com) (c) 2016 Artem Tabalin Licensed under MIT
  3. * (https://github.com/tabalinas/jsgrid/blob/master/LICENSE)
  4. */
  5. !function(a, b, c) {
  6. function d(a, c) {
  7. var d = b(a);
  8. d.data(f, this), this._container = d, this.data = [], this.fields = [], this._editingRow = null, this._sortField = null, this._sortOrder = i, this._firstDisplayingPage = 1, this
  9. ._init(c), this.render()
  10. }
  11. var e = "JSGrid", f = e, g = "JSGridItem", h = "JSGridEditRow", i = "asc", j = "desc", k = "{first}", l = "{pages}", m = "{prev}", n = "{next}", o = "{last}", p = "{pageIndex}", q = "{pageCount}", r = "{itemCount}", s = "javascript:void(0);", t = function(
  12. a, c) {
  13. return b.isFunction(a)
  14. ? a.apply(c, b.makeArray(arguments).slice(2))
  15. : a
  16. }, u = {
  17. loadData : b.noop,
  18. insertItem : b.noop,
  19. updateItem : b.noop,
  20. deleteItem : b.noop
  21. };
  22. d.prototype = {
  23. width : "auto",
  24. height : "auto",
  25. updateOnResize : !0,
  26. rowClass : b.noop,
  27. rowRenderer : null,
  28. rowClick : function(a) {
  29. this.editing && this.editItem(b(a.event.target).closest("tr"))
  30. },
  31. rowDoubleClick : b.noop,
  32. noDataContent : "Not found",
  33. noDataRowClass : "jsgrid-nodata-row",
  34. heading : !0,
  35. headerRowRenderer : null,
  36. headerRowClass : "jsgrid-header-row",
  37. filtering : !1,
  38. filterRowRenderer : null,
  39. filterRowClass : "jsgrid-filter-row",
  40. inserting : !1,
  41. insertRowRenderer : null,
  42. insertRowClass : "jsgrid-insert-row",
  43. editing : !1,
  44. editRowRenderer : null,
  45. editRowClass : "jsgrid-edit-row",
  46. confirmDeleting : !0,
  47. deleteConfirm : "Are you sure?",
  48. selecting : !0,
  49. selectedRowClass : "jsgrid-selected-row",
  50. oddRowClass : "jsgrid-row",
  51. evenRowClass : "jsgrid-alt-row",
  52. sorting : !1,
  53. sortableClass : "jsgrid-header-sortable",
  54. sortAscClass : "jsgrid-header-sort jsgrid-header-sort-asc",
  55. sortDescClass : "jsgrid-header-sort jsgrid-header-sort-desc",
  56. paging : !1,
  57. pagerContainer : null,
  58. pageIndex : 1,
  59. pageSize : 20,
  60. pageButtonCount : 15,
  61. pagerFormat : "Pages: {first} {prev} {pages} {next} {last}    {pageIndex} of {pageCount}",
  62. pagePrevText : "Prev",
  63. pageNextText : "Next",
  64. pageFirstText : "First",
  65. pageLastText : "Last",
  66. pageNavigatorNextText : "...",
  67. pageNavigatorPrevText : "...",
  68. pagerContainerClass : "jsgrid-pager-container",
  69. pagerClass : "jsgrid-pager",
  70. pagerNavButtonClass : "jsgrid-pager-nav-button",
  71. pagerNavButtonInactiveClass : "jsgrid-pager-nav-inactive-button",
  72. pageClass : "jsgrid-pager-page",
  73. currentPageClass : "jsgrid-pager-current-page",
  74. customLoading : !1,
  75. pageLoading : !1,
  76. autoload : !1,
  77. controller : u,
  78. loadIndication : !0,
  79. loadIndicationDelay : 500,
  80. loadMessage : "Please, wait...",
  81. loadShading : !0,
  82. invalidMessage : "Invalid data entered!",
  83. invalidNotify : function(c) {
  84. var d = b.map(c.errors, function(a) {
  85. return a.message || null
  86. });
  87. a.alert([this.invalidMessage].concat(d).join("\n"))
  88. },
  89. onRefreshing : b.noop,
  90. onRefreshed : b.noop,
  91. onItemDeleting : b.noop,
  92. onItemDeleted : b.noop,
  93. onItemInserting : b.noop,
  94. onItemInserted : b.noop,
  95. onItemEditing : b.noop,
  96. onItemUpdating : b.noop,
  97. onItemUpdated : b.noop,
  98. onItemInvalid : b.noop,
  99. onDataLoading : b.noop,
  100. onDataLoaded : b.noop,
  101. onOptionChanging : b.noop,
  102. onOptionChanged : b.noop,
  103. onError : b.noop,
  104. invalidClass : "jsgrid-invalid",
  105. containerClass : "jsgrid",
  106. tableClass : "jsgrid-table",
  107. gridHeaderClass : "jsgrid-grid-header",
  108. gridBodyClass : "jsgrid-grid-body",
  109. _init : function(a) {
  110. b.extend(this, a), this._initLoadStrategy(), this._initController(), this
  111. ._initFields(), this._attachWindowLoadResize(), this
  112. ._attachWindowResizeCallback()
  113. },
  114. loadStrategy : function() {
  115. return this.pageLoading
  116. ? new jsGrid.loadStrategies.PageLoadingStrategy(this)
  117. : new jsGrid.loadStrategies.DirectLoadingStrategy(this)
  118. },
  119. _initLoadStrategy : function() {
  120. this._loadStrategy = t(this.loadStrategy, this)
  121. },
  122. _initController : function() {
  123. this._controller = b.extend({}, u, t(this.controller, this))
  124. },
  125. loadIndicator : function(a) {
  126. return new jsGrid.LoadIndicator(a)
  127. },
  128. validation : function(a) {
  129. return jsGrid.Validation && new jsGrid.Validation(a)
  130. },
  131. _initFields : function() {
  132. var a = this;
  133. a.fields = b.map(a.fields, function(c) {
  134. if (b.isPlainObject(c)) {
  135. var d = c.type && jsGrid.fields[c.type]
  136. || jsGrid.Field;
  137. c = new d(c)
  138. }
  139. return c._grid = a, c
  140. })
  141. },
  142. _attachWindowLoadResize : function() {
  143. b(a).on("load", b.proxy(this._refreshSize, this))
  144. },
  145. _attachWindowResizeCallback : function() {
  146. this.updateOnResize
  147. && b(a).on("resize", b.proxy(this._refreshSize, this))
  148. },
  149. _detachWindowResizeCallback : function() {
  150. b(a).off("resize", this._refreshSize)
  151. },
  152. option : function(a, b) {
  153. var c, d;
  154. return 1 === arguments.length ? this[a] : (c = {
  155. option : a,
  156. oldValue : this[a],
  157. newValue : b
  158. }, this._callEventHandler(this.onOptionChanging, c), this
  159. ._handleOptionChange(c.option, c.newValue), d = {
  160. option : c.option,
  161. value : c.newValue
  162. }, void this._callEventHandler(this.onOptionChanged, d))
  163. },
  164. fieldOption : function(a, b, c) {
  165. return a = this._normalizeField(a), 2 === arguments.length
  166. ? a[b]
  167. : (a[b] = c, void this._renderGrid())
  168. },
  169. _handleOptionChange : function(a, b) {
  170. switch (this[a] = b, a) {
  171. case "width" :
  172. case "height" :
  173. this._refreshSize();
  174. break;
  175. case "rowClass" :
  176. case "rowRenderer" :
  177. case "rowClick" :
  178. case "rowDoubleClick" :
  179. case "noDataText" :
  180. case "noDataRowClass" :
  181. case "noDataContent" :
  182. case "selecting" :
  183. case "selectedRowClass" :
  184. case "oddRowClass" :
  185. case "evenRowClass" :
  186. this._refreshContent();
  187. break;
  188. case "pageButtonCount" :
  189. case "pagerFormat" :
  190. case "pagePrevText" :
  191. case "pageNextText" :
  192. case "pageFirstText" :
  193. case "pageLastText" :
  194. case "pageNavigatorNextText" :
  195. case "pageNavigatorPrevText" :
  196. case "pagerClass" :
  197. case "pagerNavButtonClass" :
  198. case "pageClass" :
  199. case "currentPageClass" :
  200. case "pagerRenderer" :
  201. this._refreshPager();
  202. break;
  203. case "fields" :
  204. this._initFields(), this.render();
  205. break;
  206. case "data" :
  207. case "editing" :
  208. case "heading" :
  209. case "filtering" :
  210. case "inserting" :
  211. case "paging" :
  212. this.refresh();
  213. break;
  214. case "loadStrategy" :
  215. case "pageLoading" :
  216. this._initLoadStrategy(), this.search();
  217. break;
  218. case "pageIndex" :
  219. this.openPage(b);
  220. break;
  221. case "pageSize" :
  222. this.refresh(), this.search();
  223. break;
  224. case "editRowRenderer" :
  225. case "editRowClass" :
  226. this.cancelEdit();
  227. break;
  228. case "updateOnResize" :
  229. this._detachWindowResizeCallback(), this
  230. ._attachWindowResizeCallback();
  231. break;
  232. case "invalidNotify" :
  233. case "invalidMessage" :
  234. break;
  235. default :
  236. this.render()
  237. }
  238. },
  239. destroy : function() {
  240. this._detachWindowResizeCallback(), this._clear(), this._container
  241. .removeData(f)
  242. },
  243. render : function() {
  244. return this._renderGrid(), this.autoload ? this.loadData() : b
  245. .Deferred().resolve().promise()
  246. },
  247. _renderGrid : function() {
  248. this._clear(), this._container.addClass(this.containerClass).css(
  249. "position", "relative").append(this._createHeader())
  250. .append(this._createBody()), this._pagerContainer = this
  251. ._createPagerContainer(), this._loadIndicator = this
  252. ._createLoadIndicator(), this._validation = this
  253. ._createValidation(), this.refresh()
  254. },
  255. _createLoadIndicator : function() {
  256. return t(this.loadIndicator, this, {
  257. message : this.loadMessage,
  258. shading : this.loadShading,
  259. container : this._container
  260. })
  261. },
  262. _createValidation : function() {
  263. return t(this.validation, this)
  264. },
  265. _clear : function() {
  266. this.cancelEdit(), clearTimeout(this._loadingTimer), this._pagerContainer
  267. && this._pagerContainer.empty(), this._container.empty()
  268. .css({
  269. position : "",
  270. width : "",
  271. height : ""
  272. })
  273. },
  274. _createHeader : function() {
  275. var a = this._headerRow = this._createHeaderRow(), c = this._filterRow = this
  276. ._createFilterRow(), d = this._insertRow = this
  277. ._createInsertRow(), e = this._headerGrid = b("<table>")
  278. .addClass(this.tableClass).append(a).append(c).append(d), f = this._header = b("<div>")
  279. .addClass(this.gridHeaderClass)
  280. .addClass(this._scrollBarWidth()
  281. ? "jsgrid-header-scrollbar"
  282. : "").append(e);
  283. return f
  284. },
  285. _createBody : function() {
  286. var a = this._content = b("<tbody>"), c = this._bodyGrid = b("<table>")
  287. .addClass(this.tableClass).append(a), d = this._body = b("<div>")
  288. .addClass(this.gridBodyClass).append(c).on("scroll",
  289. b.proxy(function(a) {
  290. this._header
  291. .scrollLeft(a.target.scrollLeft)
  292. }, this));
  293. return d
  294. },
  295. _createPagerContainer : function() {
  296. var a = this.pagerContainer || b("<div>").appendTo(this._container);
  297. return b(a).addClass(this.pagerContainerClass)
  298. },
  299. _eachField : function(a) {
  300. var c = this;
  301. b.each(this.fields, function(b, d) {
  302. d.visible && a.call(c, d, b)
  303. })
  304. },
  305. _createHeaderRow : function() {
  306. if (b.isFunction(this.headerRowRenderer))
  307. return b(this.headerRowRenderer());
  308. var a = b("<tr>").addClass(this.headerRowClass);
  309. return this._eachField(function(c, d) {
  310. var e = this._prepareCell("<th>", c, "headercss")
  311. .append(c.headerTemplate
  312. ? c.headerTemplate()
  313. : "").appendTo(a);
  314. this.sorting
  315. && c.sorting
  316. && e.addClass(this.sortableClass).on("click",
  317. b.proxy(function() {
  318. this.sort(d)
  319. }, this))
  320. }), a
  321. },
  322. _prepareCell : function(a, c, d) {
  323. return b(a).css("width", c.width).addClass(d && c[d] || c.css)
  324. .addClass(c.align ? "jsgrid-align-" + c.align : "")
  325. },
  326. _createFilterRow : function() {
  327. if (b.isFunction(this.filterRowRenderer))
  328. return b(this.filterRowRenderer());
  329. var a = b("<tr>").addClass(this.filterRowClass);
  330. return this._eachField(function(b) {
  331. this._prepareCell("<td>", b, "filtercss")
  332. .append(b.filterTemplate
  333. ? b.filterTemplate()
  334. : "").appendTo(a)
  335. }), a
  336. },
  337. _createInsertRow : function() {
  338. if (b.isFunction(this.insertRowRenderer))
  339. return b(this.insertRowRenderer());
  340. var a = b("<tr>").addClass(this.insertRowClass);
  341. return this._eachField(function(b) {
  342. this._prepareCell("<td>", b, "insertcss")
  343. .append(b.insertTemplate
  344. ? b.insertTemplate()
  345. : "").appendTo(a)
  346. }), a
  347. },
  348. _callEventHandler : function(a, c) {
  349. return a.call(this, b.extend(c, {
  350. grid : this
  351. })), c
  352. },
  353. reset : function() {
  354. this._resetSorting(), this._resetPager(), this.refresh()
  355. },
  356. _resetPager : function() {
  357. this._firstDisplayingPage = 1, this._setPage(1)
  358. },
  359. _resetSorting : function() {
  360. this._sortField = null, this._sortOrder = i, this
  361. ._clearSortingCss()
  362. },
  363. refresh : function() {
  364. this._callEventHandler(this.onRefreshing), this.cancelEdit(), this
  365. ._refreshHeading(), this._refreshFiltering(), this
  366. ._refreshInserting(), this._refreshContent(), this
  367. ._refreshPager(), this._refreshSize(), this
  368. ._callEventHandler(this.onRefreshed)
  369. },
  370. _refreshHeading : function() {
  371. this._headerRow.toggle(this.heading)
  372. },
  373. _refreshFiltering : function() {
  374. this._filterRow.toggle(this.filtering)
  375. },
  376. _refreshInserting : function() {
  377. this._insertRow.toggle(this.inserting)
  378. },
  379. _refreshContent : function() {
  380. var a = this._content;
  381. if (a.empty(), !this.data.length)
  382. return a.append(this._createNoDataRow()), this;
  383. for (var b = this._loadStrategy.firstDisplayIndex(), c = this._loadStrategy
  384. .lastDisplayIndex(), d = b; c > d; d++) {
  385. var e = this.data[d];
  386. a.append(this._createRow(e, d))
  387. }
  388. },
  389. _createNoDataRow : function() {
  390. var a = t(this.noDataContent, this), c = 0;
  391. return this._eachField(function() {
  392. c++
  393. }), b("<tr>").addClass(this.noDataRowClass)
  394. .append(b("<td>").attr("colspan", c).append(a))
  395. },
  396. _createNoDataContent : function() {
  397. return b.isFunction(this.noDataRenderer)
  398. ? this.noDataRenderer()
  399. : this.noDataText
  400. },
  401. _createRow : function(a, c) {
  402. var d;
  403. return b.isFunction(this.rowRenderer) ? d = b(this
  404. .rowRenderer(a, c)) : (d = b("<tr>"), this._renderCells(d,
  405. a)), d.addClass(this._getRowClasses(a, c)).data(g, a).on(
  406. "click", b.proxy(function(b) {
  407. this.rowClick({
  408. item : a,
  409. itemIndex : c,
  410. event : b
  411. })
  412. }, this)).on("dblclick", b.proxy(function(b) {
  413. this.rowDoubleClick({
  414. item : a,
  415. itemIndex : c,
  416. event : b
  417. })
  418. }, this)), this.selecting
  419. && this._attachRowHover(d), d
  420. },
  421. _getRowClasses : function(a, b) {
  422. var c = [];
  423. return c.push((b + 1) % 2 ? this.oddRowClass : this.evenRowClass), c
  424. .push(t(this.rowClass, this, a, b)), c.join(" ")
  425. },
  426. _attachRowHover : function(a) {
  427. var c = this.selectedRowClass;
  428. a.hover(function() {
  429. b(this).addClass(c)
  430. }, function() {
  431. b(this).removeClass(c)
  432. })
  433. },
  434. _renderCells : function(a, b) {
  435. return this._eachField(function(c) {
  436. a.append(this._createCell(b, c))
  437. }), this
  438. },
  439. _createCell : function(a, c) {
  440. var d, e = this._getItemFieldValue(a, c);
  441. return d = b.isFunction(c.cellRenderer)
  442. ? b(c.cellRenderer(e, a))
  443. : b("<td>").append(c.itemTemplate
  444. ? c.itemTemplate(e, a)
  445. : e), this._prepareCell(d, c)
  446. },
  447. _getItemFieldValue : function(a, b) {
  448. for (var c = b.name.split("."), d = a[c.shift()]; d && c.length;)
  449. d = d[c.shift()];
  450. return d
  451. },
  452. _setItemFieldValue : function(a, b, c) {
  453. for (var d = b.name.split("."), e = a, f = d[0]; e && d.length;)
  454. a = e, f = d.shift(), e = a[f];
  455. if (!e)
  456. for (; d.length;)
  457. a = a[f] = {}, f = d.shift();
  458. a[f] = c
  459. },
  460. sort : function(a, c) {
  461. return b.isPlainObject(a) && (c = a.order, a = a.field), this
  462. ._clearSortingCss(), this._setSortingParams(a, c), this
  463. ._setSortingCss(), this._loadStrategy.sort()
  464. },
  465. _clearSortingCss : function() {
  466. this._headerRow.find("th").removeClass(this.sortAscClass)
  467. .removeClass(this.sortDescClass)
  468. },
  469. _setSortingParams : function(a, b) {
  470. a = this._normalizeField(a), b = b
  471. || (this._sortField === a ? this
  472. ._reversedSortOrder(this._sortOrder) : i), this._sortField = a, this._sortOrder = b
  473. },
  474. _normalizeField : function(a) {
  475. return b.isNumeric(a) ? this.fields[a] : "string" == typeof a ? b
  476. .grep(this.fields, function(b) {
  477. return b.name === a
  478. })[0] : a
  479. },
  480. _reversedSortOrder : function(a) {
  481. return a === i ? j : i
  482. },
  483. _setSortingCss : function() {
  484. var a = b.inArray(this._sortField, b.grep(this.fields, function(a) {
  485. return a.visible
  486. }));
  487. this._headerRow.find("th").eq(a).addClass(this._sortOrder === i
  488. ? this.sortAscClass
  489. : this.sortDescClass)
  490. },
  491. _sortData : function() {
  492. var a = this._sortFactor(), b = this._sortField;
  493. b && this.data.sort(function(c, d) {
  494. return a * b.sortingFunc(c[b.name], d[b.name])
  495. })
  496. },
  497. _sortFactor : function() {
  498. return this._sortOrder === i ? 1 : -1
  499. },
  500. _itemsCount : function() {
  501. return this._loadStrategy.itemsCount()
  502. },
  503. _pagesCount : function() {
  504. var a = this._itemsCount(), b = this.pageSize;
  505. return Math.floor(a / b) + (a % b ? 1 : 0)
  506. },
  507. _refreshPager : function() {
  508. var a = this._pagerContainer;
  509. a.empty(), this.paging && a.append(this._createPager());
  510. var b = this.paging && this._pagesCount() > 1;
  511. a.toggle(b)
  512. },
  513. _createPager : function() {
  514. var a;
  515. return a = b.isFunction(this.pagerRenderer) ? b(this.pagerRenderer(
  516. {
  517. pageIndex : this.pageIndex,
  518. pageCount : this._pagesCount()
  519. })) : b("<div>").append(this._createPagerByFormat()), a
  520. .addClass(this.pagerClass), a
  521. },
  522. _createPagerByFormat : function() {
  523. var a = this.pageIndex, c = this._pagesCount(), d = this
  524. ._itemsCount(), e = this.pagerFormat.split(" ");
  525. return b.map(e, b.proxy(function(e) {
  526. var f = e;
  527. return e === l ? f = this._createPages() : e === k
  528. ? f = this._createPagerNavButton(this.pageFirstText, 1,
  529. a > 1)
  530. : e === m ? f = this._createPagerNavButton(
  531. this.pagePrevText, a - 1, a > 1) : e === n
  532. ? f = this._createPagerNavButton(
  533. this.pageNextText, a + 1, c > a)
  534. : e === o ? f = this._createPagerNavButton(
  535. this.pageLastText, c, c > a) : e === p
  536. ? f = a
  537. : e === q ? f = c : e === r && (f = d), b
  538. .isArray(f) ? f.concat([" "]) : [f, " "]
  539. }, this))
  540. },
  541. _createPages : function() {
  542. var a = this._pagesCount(), b = this.pageButtonCount, c = this._firstDisplayingPage, d = [];
  543. c > 1
  544. && d.push(this._createPagerPageNavButton(
  545. this.pageNavigatorPrevText, this.showPrevPages));
  546. for (var e = 0, f = c; b > e && a >= f; e++, f++)
  547. d.push(f === this.pageIndex
  548. ? this._createPagerCurrentPage()
  549. : this._createPagerPage(f));
  550. return a > c + b - 1
  551. && d.push(this._createPagerPageNavButton(
  552. this.pageNavigatorNextText, this.showNextPages)), d
  553. },
  554. _createPagerNavButton : function(a, c, d) {
  555. return this
  556. ._createPagerButton(
  557. a,
  558. this.pagerNavButtonClass
  559. + (d ? "" : " "
  560. + this.pagerNavButtonInactiveClass),
  561. d ? function() {
  562. this.openPage(c)
  563. } : b.noop)
  564. },
  565. _createPagerPageNavButton : function(a, b) {
  566. return this._createPagerButton(a, this.pagerNavButtonClass, b)
  567. },
  568. _createPagerPage : function(a) {
  569. return this._createPagerButton(a, this.pageClass, function() {
  570. this.openPage(a)
  571. })
  572. },
  573. _createPagerButton : function(a, c, d) {
  574. var e = b("<a>").attr("href", s).html(a).on("click",
  575. b.proxy(d, this));
  576. return b("<span>").addClass(c).append(e)
  577. },
  578. _createPagerCurrentPage : function() {
  579. return b("<span>").addClass(this.pageClass)
  580. .addClass(this.currentPageClass).text(this.pageIndex)
  581. },
  582. _refreshSize : function() {
  583. this._refreshHeight(), this._refreshWidth()
  584. },
  585. _refreshWidth : function() {
  586. var a = this._headerGrid, b = this._bodyGrid, c = this.width;
  587. "auto" === c && (a.width("auto"), c = a.outerWidth()), a.width(""), b
  588. .width(""), this._container.width(c), c = a.outerWidth(), b
  589. .width(c)
  590. },
  591. _scrollBarWidth : function() {
  592. var a;
  593. return function() {
  594. if (a === c) {
  595. var d = b("<div style='width:50px;height:50px;overflow:hidden;position:absolute;top:-10000px;left:-10000px;'></div>"), e = b("<div style='height:100px;'></div>");
  596. d.append(e).appendTo("body");
  597. var f = e.innerWidth();
  598. d.css("overflow-y", "auto");
  599. var g = e.innerWidth();
  600. d.remove(), a = f - g
  601. }
  602. return a
  603. }
  604. }(),
  605. _refreshHeight : function() {
  606. var a, b = this._container, c = this._pagerContainer, d = this.height;
  607. b.height(d), "auto" !== d
  608. && (d = b.height(), a = this._header.outerHeight(!0), c
  609. .parents(b).length
  610. && (a += c.outerHeight(!0)), this._body
  611. .outerHeight(d - a))
  612. },
  613. showPrevPages : function() {
  614. var a = this._firstDisplayingPage, b = this.pageButtonCount;
  615. this._firstDisplayingPage = a > b ? a - b : 1, this._refreshPager()
  616. },
  617. showNextPages : function() {
  618. var a = this._firstDisplayingPage, b = this.pageButtonCount, c = this
  619. ._pagesCount();
  620. this._firstDisplayingPage = a + 2 * b > c ? c - b + 1 : a + b, this
  621. ._refreshPager()
  622. },
  623. openPage : function(a) {
  624. 1 > a || a > this._pagesCount()
  625. || (this._setPage(a), this._loadStrategy.openPage(a))
  626. },
  627. _setPage : function(a) {
  628. var b = this._firstDisplayingPage, c = this.pageButtonCount;
  629. this.pageIndex = a, b > a && (this._firstDisplayingPage = a), a > b
  630. + c - 1
  631. && (this._firstDisplayingPage = a - c + 1)
  632. },
  633. _controllerCall : function(a, c, d, e) {
  634. if (d)
  635. return b.Deferred().reject().promise();
  636. this._showLoading();
  637. var f = this._controller;
  638. if (!f || !f[a])
  639. throw Error("controller has no method '" + a + "'");
  640. return b.when(f[a](c)).done(b.proxy(e, this)).fail(b.proxy(
  641. this._errorHandler, this)).always(b.proxy(
  642. this._hideLoading, this))
  643. },
  644. _errorHandler : function() {
  645. this._callEventHandler(this.onError, {
  646. args : b.makeArray(arguments)
  647. })
  648. },
  649. _showLoading : function() {
  650. this.loadIndication
  651. && (clearTimeout(this._loadingTimer), this._loadingTimer = setTimeout(
  652. b.proxy(function() {
  653. this._loadIndicator.show()
  654. }, this), this.loadIndicationDelay))
  655. },
  656. _hideLoading : function() {
  657. this.loadIndication
  658. && (clearTimeout(this._loadingTimer), this._loadIndicator
  659. .hide())
  660. },
  661. search : function(a) {
  662. return this._resetSorting(), this._resetPager(), this.loadData(a)
  663. },
  664. loadData : function(a) {
  665. a = a || (this.filtering ? this.getFilter() : {}), b.extend(a,
  666. this._loadStrategy.loadParams(), this._sortingParams());
  667. var c = this._callEventHandler(this.onDataLoading, {
  668. filter : a
  669. });
  670. return this._controllerCall("loadData", a, c.cancel, function(a) {
  671. a
  672. && (this._loadStrategy.finishLoad(a), this
  673. ._callEventHandler(this.onDataLoaded, {
  674. data : a
  675. }))
  676. })
  677. },
  678. getFilter : function() {
  679. var a = {};
  680. return this._eachField(function(b) {
  681. b.filtering
  682. && this._setItemFieldValue(a, b, b
  683. .filterValue())
  684. }), a
  685. },
  686. _sortingParams : function() {
  687. return this.sorting && this._sortField ? {
  688. sortField : this._sortField.name,
  689. sortOrder : this._sortOrder
  690. } : {}
  691. },
  692. getSorting : function() {
  693. var a = this._sortingParams();
  694. return {
  695. field : a.sortField,
  696. order : a.sortOrder
  697. }
  698. },
  699. clearFilter : function() {
  700. var a = this._createFilterRow();
  701. return this._filterRow.replaceWith(a), this._filterRow = a, this
  702. .search()
  703. },
  704. insertItem : function(a) {
  705. var c = a || this._getValidatedInsertItem();
  706. if (!c)
  707. return b.Deferred().reject().promise();
  708. var d = this._callEventHandler(this.onItemInserting, {
  709. item : c
  710. });
  711. return this._controllerCall("insertItem", c, d.cancel, function(a) {
  712. a = a || c, this._loadStrategy.finishInsert(a), this
  713. ._callEventHandler(this.onItemInserted, {
  714. item : a
  715. })
  716. })
  717. },
  718. _getValidatedInsertItem : function() {
  719. var a = this._getInsertItem();
  720. return this._validateItem(a, this._insertRow) ? a : null
  721. },
  722. _getInsertItem : function() {
  723. var a = {};
  724. return this._eachField(function(b) {
  725. b.inserting
  726. && this._setItemFieldValue(a, b, b
  727. .insertValue())
  728. }), a
  729. },
  730. _validateItem : function(a, c) {
  731. var d = [], e = {
  732. item : a,
  733. itemIndex : this._rowIndex(c),
  734. row : c
  735. };
  736. if (this._eachField(function(f, g) {
  737. if (f.validate) {
  738. var h = this._validation.validate(b.extend({
  739. value : this._getItemFieldValue(a, f),
  740. rules : f.validate
  741. }, e));
  742. this._setCellValidity(c.children().eq(g), h), h.length
  743. && d.push.apply(d, b.map(h, function(a) {
  744. return {
  745. field : f,
  746. message : a
  747. }
  748. }))
  749. }
  750. }), !d.length)
  751. return !0;
  752. var f = b.extend({
  753. errors : d
  754. }, e);
  755. return this._callEventHandler(this.onItemInvalid, f), this
  756. .invalidNotify(f), !1
  757. },
  758. _setCellValidity : function(a, b) {
  759. a.toggleClass(this.invalidClass, !!b.length).attr("title",
  760. b.join("\n"))
  761. },
  762. clearInsert : function() {
  763. var a = this._createInsertRow();
  764. this._insertRow.replaceWith(a), this._insertRow = a, this.refresh()
  765. },
  766. editItem : function(a) {
  767. var b = this.rowByItem(a);
  768. b.length && this._editRow(b)
  769. },
  770. rowByItem : function(a) {
  771. return a.jquery || a.nodeType ? b(a) : this._content.find("tr")
  772. .filter(function() {
  773. return b.data(this, g) === a
  774. })
  775. },
  776. _editRow : function(a) {
  777. if (this.editing) {
  778. var b = a.data(g), c = this._callEventHandler(
  779. this.onItemEditing, {
  780. row : a,
  781. item : b,
  782. itemIndex : this._itemIndex(b)
  783. });
  784. if (!c.cancel) {
  785. this._editingRow && this.cancelEdit();
  786. var d = this._createEditRow(b);
  787. this._editingRow = a, a.hide(), d.insertBefore(a), a.data(
  788. h, d)
  789. }
  790. }
  791. },
  792. _createEditRow : function(a) {
  793. if (b.isFunction(this.editRowRenderer))
  794. return b(this.editRowRenderer(a, this._itemIndex(a)));
  795. var c = b("<tr>").addClass(this.editRowClass);
  796. return this._eachField(function(b) {
  797. var d = this._getItemFieldValue(a, b);
  798. this._prepareCell("<td>", b, "editcss")
  799. .append(b.editTemplate
  800. ? b.editTemplate(d, a)
  801. : "").appendTo(c)
  802. }), c
  803. },
  804. updateItem : function(a, b) {
  805. 1 === arguments.length && (b = a);
  806. var c = a ? this.rowByItem(a) : this._editingRow;
  807. return (b = b || this._getValidatedEditedItem()) ? this._updateRow(
  808. c, b) : void 0
  809. },
  810. _getValidatedEditedItem : function() {
  811. var a = this._getEditedItem();
  812. return this._validateItem(a, this._getEditRow()) ? a : null
  813. },
  814. _updateRow : function(a, c) {
  815. var d = a.data(g), e = this._itemIndex(d), f = b.extend(!0, {}, d);
  816. b.extend(!0, d, c);
  817. var h = this._callEventHandler(this.onItemUpdating, {
  818. row : a,
  819. item : d,
  820. itemIndex : e,
  821. previousItem : f
  822. });
  823. return this._controllerCall("updateItem", d, h.cancel, function(b) {
  824. b = b || d;
  825. var c = this._finishUpdate(a, b, e);
  826. this._callEventHandler(this.onItemUpdated, {
  827. row : c,
  828. item : b,
  829. itemIndex : e,
  830. previousItem : f
  831. })
  832. })
  833. },
  834. _rowIndex : function(a) {
  835. return this._content.children().index(b(a))
  836. },
  837. _itemIndex : function(a) {
  838. return b.inArray(a, this.data)
  839. },
  840. _finishUpdate : function(a, b, c) {
  841. this.cancelEdit(), this.data[c] = b;
  842. var d = this._createRow(b, c);
  843. return a.replaceWith(d), d
  844. },
  845. _getEditedItem : function() {
  846. var a = {};
  847. return this._eachField(function(b) {
  848. b.editing
  849. && this._setItemFieldValue(a, b, b.editValue())
  850. }), a
  851. },
  852. cancelEdit : function() {
  853. this._editingRow
  854. && (this._getEditRow().remove(), this._editingRow.show(), this._editingRow = null)
  855. },
  856. _getEditRow : function() {
  857. return this._editingRow.data(h)
  858. },
  859. deleteItem : function(b) {
  860. var c = this.rowByItem(b);
  861. if (c.length
  862. && (!this.confirmDeleting || a.confirm(t(
  863. this.deleteConfirm, this, c.data(g)))))
  864. return this._deleteRow(c)
  865. },
  866. _deleteRow : function(a) {
  867. var b = a.data(g), c = this._itemIndex(b), d = this
  868. ._callEventHandler(this.onItemDeleting, {
  869. row : a,
  870. item : b,
  871. itemIndex : c
  872. });
  873. return this._controllerCall("deleteItem", b, d.cancel, function() {
  874. this._loadStrategy.finishDelete(b, c), this
  875. ._callEventHandler(this.onItemDeleted, {
  876. row : a,
  877. item : b,
  878. itemIndex : c
  879. })
  880. })
  881. }
  882. }, b.fn.jsGrid = function(a) {
  883. var e = b.makeArray(arguments), g = e.slice(1), h = this;
  884. return this.each(function() {
  885. var e, i = b(this), j = i.data(f);
  886. if (j)
  887. if ("string" == typeof a) {
  888. if (e = j[a].apply(j, g), e !== c && e !== j)
  889. return h = e, !1
  890. } else
  891. j._detachWindowResizeCallback(), j._init(a), j
  892. .render();
  893. else
  894. new d(i, a)
  895. }), h
  896. };
  897. var v = {}, w = function(a) {
  898. var c;
  899. b.isPlainObject(a)
  900. ? c = d.prototype
  901. : (c = v[a].prototype, a = arguments[1] || {}), b.extend(c, a)
  902. }, x = {}, y = function(a) {
  903. var c = b.isPlainObject(a) ? a : x[a];
  904. if (!c)
  905. throw Error("unknown locale " + a);
  906. z(jsGrid, c)
  907. }, z = function(a, c) {
  908. b.each(c, function(c, d) {
  909. return b.isPlainObject(d)
  910. ? void z(
  911. a[c] || a[c[0].toUpperCase() + c.slice(1)],
  912. d)
  913. : void(a.hasOwnProperty(c)
  914. ? a[c] = d
  915. : a.prototype[c] = d)
  916. })
  917. };
  918. a.jsGrid = {
  919. Grid : d,
  920. fields : v,
  921. setDefaults : w,
  922. locales : x,
  923. locale : y
  924. }
  925. }(window, jQuery), function(a, b) {
  926. function c(a) {
  927. this._init(a)
  928. }
  929. c.prototype = {
  930. container : "body",
  931. message : "Loading...",
  932. shading : !0,
  933. zIndex : 1e3,
  934. shaderClass : "jsgrid-load-shader",
  935. loadPanelClass : "jsgrid-load-panel",
  936. _init : function(a) {
  937. b.extend(!0, this, a), this._initContainer(), this._initShader(), this
  938. ._initLoadPanel()
  939. },
  940. _initContainer : function() {
  941. this._container = b(this.container)
  942. },
  943. _initShader : function() {
  944. this.shading
  945. && (this._shader = b("<div>").addClass(this.shaderClass)
  946. .hide().css({
  947. position : "absolute",
  948. top : 0,
  949. right : 0,
  950. bottom : 0,
  951. left : 0,
  952. zIndex : this.zIndex
  953. }).appendTo(this._container))
  954. },
  955. _initLoadPanel : function() {
  956. this._loadPanel = b("<div>").addClass(this.loadPanelClass)
  957. .text(this.message).hide().css({
  958. position : "absolute",
  959. top : "50%",
  960. left : "50%",
  961. zIndex : this.zIndex
  962. }).appendTo(this._container)
  963. },
  964. show : function() {
  965. var a = this._loadPanel.show(), b = a.outerWidth(), c = a
  966. .outerHeight();
  967. a.css({
  968. marginTop : -c / 2,
  969. marginLeft : -b / 2
  970. }), this._shader.show()
  971. },
  972. hide : function() {
  973. this._loadPanel.hide(), this._shader.hide()
  974. }
  975. }, a.LoadIndicator = c
  976. }(jsGrid, jQuery), function(a, b) {
  977. function c(a) {
  978. this._grid = a
  979. }
  980. function d(a) {
  981. this._grid = a, this._itemsCount = 0
  982. }
  983. c.prototype = {
  984. firstDisplayIndex : function() {
  985. var a = this._grid;
  986. return a.option("paging") ? (a.option("pageIndex") - 1)
  987. * a.option("pageSize") : 0
  988. },
  989. lastDisplayIndex : function() {
  990. var a = this._grid, b = a.option("data").length;
  991. return a.option("paging") ? Math.min(a.option("pageIndex")
  992. * a.option("pageSize"), b) : b
  993. },
  994. itemsCount : function() {
  995. return this._grid.option("data").length
  996. },
  997. openPage : function() {
  998. this._grid.refresh()
  999. },
  1000. loadParams : function() {
  1001. return {}
  1002. },
  1003. sort : function() {
  1004. return this._grid._sortData(), this._grid.refresh(), b.Deferred()
  1005. .resolve().promise()
  1006. },
  1007. finishLoad : function(a) {
  1008. this._grid.option("data", a)
  1009. },
  1010. finishInsert : function(a) {
  1011. var b = this._grid;
  1012. b.option("data").push(a), b.refresh()
  1013. },
  1014. finishDelete : function(a, b) {
  1015. var c = this._grid;
  1016. c.option("data").splice(b, 1), c.reset()
  1017. }
  1018. }, d.prototype = {
  1019. firstDisplayIndex : function() {
  1020. return 0
  1021. },
  1022. lastDisplayIndex : function() {
  1023. return this._grid.option("data").length
  1024. },
  1025. itemsCount : function() {
  1026. return this._itemsCount
  1027. },
  1028. openPage : function() {
  1029. this._grid.loadData()
  1030. },
  1031. loadParams : function() {
  1032. var a = this._grid;
  1033. return {
  1034. pageIndex : a.option("pageIndex"),
  1035. pageSize : a.option("pageSize")
  1036. }
  1037. },
  1038. sort : function() {
  1039. return this._grid.loadData()
  1040. },
  1041. finishLoad : function(a) {
  1042. this._itemsCount = a.itemsCount, this._grid.option("data", a.data)
  1043. },
  1044. finishInsert : function() {
  1045. this._grid.search()
  1046. },
  1047. finishDelete : function() {
  1048. this._grid.search()
  1049. }
  1050. }, a.loadStrategies = {
  1051. DirectLoadingStrategy : c,
  1052. PageLoadingStrategy : d
  1053. }
  1054. }(jsGrid, jQuery), function(a) {
  1055. var b = function(a) {
  1056. return "undefined" != typeof a && null !== a
  1057. }, c = {
  1058. string : function(a, c) {
  1059. return b(a) || b(c) ? b(a) ? b(c)
  1060. ? ("" + a).localeCompare("" + c)
  1061. : 1 : -1 : 0
  1062. },
  1063. number : function(a, b) {
  1064. return a - b
  1065. },
  1066. date : function(a, b) {
  1067. return a - b
  1068. },
  1069. numberAsString : function(a, b) {
  1070. return parseFloat(a) - parseFloat(b)
  1071. }
  1072. };
  1073. a.sortStrategies = c
  1074. }(jsGrid, jQuery), function(a, b, c) {
  1075. function d(a) {
  1076. this._init(a)
  1077. }
  1078. d.prototype = {
  1079. _init : function(a) {
  1080. b.extend(!0, this, a)
  1081. },
  1082. validate : function(a) {
  1083. var c = [];
  1084. return b.each(this._normalizeRules(a.rules), function(d, e) {
  1085. if (!e.validator(a.value, a.item, e.param)) {
  1086. var f = b.isFunction(e.message) ? e.message(
  1087. a.value, a.item) : e.message;
  1088. c.push(f)
  1089. }
  1090. }), c
  1091. },
  1092. _normalizeRules : function(a) {
  1093. return b.isArray(a) || (a = [a]), b.map(a, b.proxy(function(a) {
  1094. return this._normalizeRule(a)
  1095. }, this))
  1096. },
  1097. _normalizeRule : function(a) {
  1098. if ("string" == typeof a && (a = {
  1099. validator : a
  1100. }), b.isFunction(a) && (a = {
  1101. validator : a
  1102. }), !b.isPlainObject(a))
  1103. throw Error("wrong validation config specified");
  1104. return a = b.extend({}, a), b.isFunction(a.validator) ? a : this
  1105. ._applyNamedValidator(a, a.validator)
  1106. },
  1107. _applyNamedValidator : function(a, c) {
  1108. delete a.validator;
  1109. var d = e[c];
  1110. if (!d)
  1111. throw Error('unknown validator "' + c + '"');
  1112. return b.isFunction(d) && (d = {
  1113. validator : d
  1114. }), b.extend({}, d, a)
  1115. }
  1116. }, a.Validation = d;
  1117. var e = {
  1118. required : {
  1119. message : "Field is required",
  1120. validator : function(a) {
  1121. return a !== c && null !== a && "" !== a
  1122. }
  1123. },
  1124. rangeLength : {
  1125. message : "Field value length is out of the defined range",
  1126. validator : function(a, b, c) {
  1127. return a.length >= c[0] && a.length <= c[1]
  1128. }
  1129. },
  1130. minLength : {
  1131. message : "Field value is too long",
  1132. validator : function(a, b, c) {
  1133. return a.length >= c
  1134. }
  1135. },
  1136. maxLength : {
  1137. message : "Field value is too short",
  1138. validator : function(a, b, c) {
  1139. return a.length <= c
  1140. }
  1141. },
  1142. pattern : {
  1143. message : "Field value is not matching the defined pattern",
  1144. validator : function(a, b, c) {
  1145. return "string" == typeof c
  1146. && (c = new RegExp("^(?:" + c + ")$")), c.test(a)
  1147. }
  1148. },
  1149. range : {
  1150. message : "Field value is out of the defined range",
  1151. validator : function(a, b, c) {
  1152. return a >= c[0] && a <= c[1]
  1153. }
  1154. },
  1155. min : {
  1156. message : "Field value is too large",
  1157. validator : function(a, b, c) {
  1158. return a >= c
  1159. }
  1160. },
  1161. max : {
  1162. message : "Field value is too small",
  1163. validator : function(a, b, c) {
  1164. return c >= a
  1165. }
  1166. }
  1167. };
  1168. a.validators = e
  1169. }(jsGrid, jQuery), function(a, b, c) {
  1170. function d(a) {
  1171. b.extend(!0, this, a), this.sortingFunc = this._getSortingFunc()
  1172. }
  1173. d.prototype = {
  1174. name : "",
  1175. title : null,
  1176. css : "",
  1177. align : "",
  1178. width : 100,
  1179. visible : !0,
  1180. filtering : !0,
  1181. inserting : !0,
  1182. editing : !0,
  1183. sorting : !0,
  1184. sorter : "string",
  1185. headerTemplate : function() {
  1186. return this.title === c || null === this.title
  1187. ? this.name
  1188. : this.title
  1189. },
  1190. itemTemplate : function(a) {
  1191. return a
  1192. },
  1193. filterTemplate : function() {
  1194. return ""
  1195. },
  1196. insertTemplate : function() {
  1197. return ""
  1198. },
  1199. editTemplate : function(a, b) {
  1200. return this._value = a, this.itemTemplate(a, b)
  1201. },
  1202. filterValue : function() {
  1203. return ""
  1204. },
  1205. insertValue : function() {
  1206. return ""
  1207. },
  1208. editValue : function() {
  1209. return this._value
  1210. },
  1211. _getSortingFunc : function() {
  1212. var c = this.sorter;
  1213. if (b.isFunction(c))
  1214. return c;
  1215. if ("string" == typeof c)
  1216. return a.sortStrategies[c];
  1217. throw Error('wrong sorter for the field "' + this.name + '"!')
  1218. }
  1219. }, a.Field = d
  1220. }(jsGrid, jQuery), function(a, b) {
  1221. function c(a) {
  1222. d.call(this, a)
  1223. }
  1224. var d = a.Field;
  1225. c.prototype = new d({
  1226. autosearch : !0,
  1227. readOnly : !1,
  1228. filterTemplate : function() {
  1229. if (!this.filtering)
  1230. return "";
  1231. var a = this._grid, b = this.filterControl = this
  1232. ._createTextBox();
  1233. return this.autosearch && b.on("keypress", function(b) {
  1234. 13 === b.which
  1235. && (a.search(), b.preventDefault())
  1236. }), b
  1237. },
  1238. insertTemplate : function() {
  1239. return this.inserting ? this.insertControl = this
  1240. ._createTextBox() : ""
  1241. },
  1242. editTemplate : function(a) {
  1243. if (!this.editing)
  1244. return this.itemTemplate(a);
  1245. var b = this.editControl = this._createTextBox();
  1246. return b.val(a), b
  1247. },
  1248. filterValue : function() {
  1249. return this.filterControl.val()
  1250. },
  1251. insertValue : function() {
  1252. return this.insertControl.val()
  1253. },
  1254. editValue : function() {
  1255. return this.editControl.val()
  1256. },
  1257. _createTextBox : function() {
  1258. return b("<input>").attr("type", "text").prop("readonly",
  1259. !!this.readOnly)
  1260. }
  1261. }), a.fields.text = a.TextField = c
  1262. }(jsGrid, jQuery), function(a, b) {
  1263. function c(a) {
  1264. d.call(this, a)
  1265. }
  1266. var d = a.TextField;
  1267. c.prototype = new d({
  1268. sorter : "number",
  1269. align : "right",
  1270. readOnly : !1,
  1271. filterValue : function() {
  1272. return parseInt(this.filterControl.val() || 0, 10)
  1273. },
  1274. insertValue : function() {
  1275. return parseInt(this.insertControl.val() || 0, 10)
  1276. },
  1277. editValue : function() {
  1278. return parseInt(this.editControl.val() || 0, 10)
  1279. },
  1280. _createTextBox : function() {
  1281. return b("<input>").attr("type", "number").prop("readonly",
  1282. !!this.readOnly)
  1283. }
  1284. }), a.fields.number = a.NumberField = c
  1285. }(jsGrid, jQuery), function(a, b) {
  1286. function c(a) {
  1287. d.call(this, a)
  1288. }
  1289. var d = a.TextField;
  1290. c.prototype = new d({
  1291. insertTemplate : function() {
  1292. return this.inserting ? this.insertControl = this
  1293. ._createTextArea() : ""
  1294. },
  1295. editTemplate : function(a) {
  1296. if (!this.editing)
  1297. return this.itemTemplate(a);
  1298. var b = this.editControl = this._createTextArea();
  1299. return b.val(a), b
  1300. },
  1301. _createTextArea : function() {
  1302. return b("<textarea>").prop("readonly", !!this.readOnly)
  1303. }
  1304. }), a.fields.textarea = a.TextAreaField = c
  1305. }(jsGrid, jQuery), function(a, b, c) {
  1306. function d(a) {
  1307. this.items = [], this.selectedIndex = -1, this.valueField = "", this.textField = "", a.valueField
  1308. && a.items.length
  1309. && (this.valueType = typeof a.items[0][a.valueField]), this.sorter = this.valueType, e
  1310. .call(this, a)
  1311. }
  1312. var e = a.NumberField;
  1313. d.prototype = new e({
  1314. align : "center",
  1315. valueType : "number",
  1316. itemTemplate : function(a) {
  1317. var d, e = this.items, f = this.valueField, g = this.textField;
  1318. d = f ? b.grep(e, function(b) {
  1319. return b[f] === a
  1320. })[0] || {} : e[a];
  1321. var h = g ? d[g] : d;
  1322. return h === c || null === h ? "" : h
  1323. },
  1324. filterTemplate : function() {
  1325. if (!this.filtering)
  1326. return "";
  1327. var a = this._grid, b = this.filterControl = this._createSelect();
  1328. return this.autosearch && b.on("change", function() {
  1329. a.search()
  1330. }), b
  1331. },
  1332. insertTemplate : function() {
  1333. return this.inserting
  1334. ? this.insertControl = this._createSelect()
  1335. : ""
  1336. },
  1337. editTemplate : function(a) {
  1338. if (!this.editing)
  1339. return this.itemTemplate(a);
  1340. var b = this.editControl = this._createSelect();
  1341. return a !== c && b.val(a), b
  1342. },
  1343. filterValue : function() {
  1344. var a = this.filterControl.val();
  1345. return "number" === this.valueType ? parseInt(a || 0, 10) : a
  1346. },
  1347. insertValue : function() {
  1348. var a = this.insertControl.val();
  1349. return "number" === this.valueType ? parseInt(a || 0, 10) : a
  1350. },
  1351. editValue : function() {
  1352. var a = this.editControl.val();
  1353. return "number" === this.valueType ? parseInt(a || 0, 10) : a
  1354. },
  1355. _createSelect : function() {
  1356. var a = b("<select>"), c = this.valueField, d = this.textField, e = this.selectedIndex;
  1357. return b.each(this.items, function(f, g) {
  1358. var h = c ? g[c] : f, i = d ? g[d] : g, j = b("<option>")
  1359. .attr("value", h).text(i).appendTo(a);
  1360. j.prop("selected", e === f)
  1361. }), a.prop("disabled", !!this.readOnly), a
  1362. }
  1363. }), a.fields.select = a.SelectField = d
  1364. }(jsGrid, jQuery), function(a, b, c) {
  1365. function d(a) {
  1366. e.call(this, a)
  1367. }
  1368. var e = a.Field;
  1369. d.prototype = new e({
  1370. sorter : "number",
  1371. align : "center",
  1372. autosearch : !0,
  1373. itemTemplate : function(a) {
  1374. return this._createCheckbox().prop({
  1375. checked : a,
  1376. disabled : !0
  1377. })
  1378. },
  1379. filterTemplate : function() {
  1380. if (!this.filtering)
  1381. return "";
  1382. var a = this._grid, c = this.filterControl = this._createCheckbox();
  1383. return c.prop({
  1384. readOnly : !0,
  1385. indeterminate : !0
  1386. }), c.on("click", function() {
  1387. var a = b(this);
  1388. a.prop("readOnly") ? a.prop({
  1389. checked : !1,
  1390. readOnly : !1
  1391. }) : a.prop("checked") || a.prop({
  1392. readOnly : !0,
  1393. indeterminate : !0
  1394. })
  1395. }), this.autosearch && c.on("click", function() {
  1396. a.search()
  1397. }), c
  1398. },
  1399. insertTemplate : function() {
  1400. return this.inserting
  1401. ? this.insertControl = this._createCheckbox()
  1402. : ""
  1403. },
  1404. editTemplate : function(a) {
  1405. if (!this.editing)
  1406. return this.itemTemplate(a);
  1407. var b = this.editControl = this._createCheckbox();
  1408. return b.prop("checked", a), b
  1409. },
  1410. filterValue : function() {
  1411. return this.filterControl.get(0).indeterminate
  1412. ? c
  1413. : this.filterControl.is(":checked")
  1414. },
  1415. insertValue : function() {
  1416. return this.insertControl.is(":checked")
  1417. },
  1418. editValue : function() {
  1419. return this.editControl.is(":checked")
  1420. },
  1421. _createCheckbox : function() {
  1422. return b("<input>").attr("type", "checkbox")
  1423. }
  1424. }), a.fields.checkbox = a.CheckboxField = d
  1425. }(jsGrid, jQuery), function(a, b) {
  1426. function c(a) {
  1427. d.call(this, a), this._configInitialized = !1
  1428. }
  1429. var d = a.Field;
  1430. c.prototype = new d({
  1431. css : "jsgrid-control-field",
  1432. align : "center",
  1433. width : 50,
  1434. filtering : !1,
  1435. inserting : !1,
  1436. editing : !1,
  1437. sorting : !1,
  1438. buttonClass : "jsgrid-button",
  1439. modeButtonClass : "jsgrid-mode-button",
  1440. modeOnButtonClass : "jsgrid-mode-on-button",
  1441. searchModeButtonClass : "jsgrid-search-mode-button",
  1442. insertModeButtonClass : "jsgrid-insert-mode-button",
  1443. editButtonClass : "jsgrid-edit-button",
  1444. deleteButtonClass : "jsgrid-delete-button",
  1445. searchButtonClass : "jsgrid-search-button",
  1446. clearFilterButtonClass : "jsgrid-clear-filter-button",
  1447. insertButtonClass : "jsgrid-insert-button",
  1448. updateButtonClass : "jsgrid-update-button",
  1449. cancelEditButtonClass : "jsgrid-cancel-edit-button",
  1450. searchModeButtonTooltip : "Switch to searching",
  1451. insertModeButtonTooltip : "Switch to inserting",
  1452. editButtonTooltip : "Edit",
  1453. deleteButtonTooltip : "Delete",
  1454. searchButtonTooltip : "Search",
  1455. clearFilterButtonTooltip : "Clear filter",
  1456. insertButtonTooltip : "Insert",
  1457. updateButtonTooltip : "Update",
  1458. cancelEditButtonTooltip : "Cancel edit",
  1459. editButton : !0,
  1460. deleteButton : !0,
  1461. clearFilterButton : !0,
  1462. modeSwitchButton : !0,
  1463. _initConfig : function() {
  1464. this._hasFiltering = this._grid.filtering, this._hasInserting = this._grid.inserting, this._hasInserting
  1465. && this.modeSwitchButton && (this._grid.inserting = !1), this._configInitialized = !0
  1466. },
  1467. headerTemplate : function() {
  1468. this._configInitialized || this._initConfig();
  1469. var a = this._hasFiltering, b = this._hasInserting;
  1470. return this.modeSwitchButton && (a || b) ? a && !b ? this
  1471. ._createFilterSwitchButton() : b && !a ? this
  1472. ._createInsertSwitchButton() : this
  1473. ._createModeSwitchButton() : ""
  1474. },
  1475. itemTemplate : function(a, c) {
  1476. var d = b([]);
  1477. return this.editButton && (d = d.add(this._createEditButton(c))), this.deleteButton
  1478. && (d = d.add(this._createDeleteButton(c))), d
  1479. },
  1480. filterTemplate : function() {
  1481. var a = this._createSearchButton();
  1482. return this.clearFilterButton ? a.add(this
  1483. ._createClearFilterButton()) : a
  1484. },
  1485. insertTemplate : function() {
  1486. return this._createInsertButton()
  1487. },
  1488. editTemplate : function() {
  1489. return this._createUpdateButton().add(this
  1490. ._createCancelEditButton())
  1491. },
  1492. _createFilterSwitchButton : function() {
  1493. return this._createOnOffSwitchButton("filtering",
  1494. this.searchModeButtonClass, !0)
  1495. },
  1496. _createInsertSwitchButton : function() {
  1497. return this._createOnOffSwitchButton("inserting",
  1498. this.insertModeButtonClass, !1)
  1499. },
  1500. _createOnOffSwitchButton : function(a, c, d) {
  1501. var e = d, f = b.proxy(function() {
  1502. g.toggleClass(this.modeOnButtonClass, e)
  1503. }, this), g = this._createGridButton(this.modeButtonClass
  1504. + " " + c, "", function(b) {
  1505. e = !e, b.option(a, e), f()
  1506. });
  1507. return f(), g
  1508. },
  1509. _createModeSwitchButton : function() {
  1510. var a = !1, c = b.proxy(function() {
  1511. d.attr(
  1512. "title",
  1513. a
  1514. ? this.searchModeButtonTooltip
  1515. : this.insertModeButtonTooltip)
  1516. .toggleClass(this.insertModeButtonClass, !a)
  1517. .toggleClass(this.searchModeButtonClass, a)
  1518. }, this), d = this._createGridButton(this.modeButtonClass,
  1519. "", function(b) {
  1520. a = !a, b.option("inserting", a), b.option("filtering",
  1521. !a), c()
  1522. });
  1523. return c(), d
  1524. },
  1525. _createEditButton : function(a) {
  1526. return this._createGridButton(this.editButtonClass,
  1527. this.editButtonTooltip, function(b, c) {
  1528. b.editItem(a), c.stopPropagation()
  1529. })
  1530. },
  1531. _createDeleteButton : function(a) {
  1532. return this._createGridButton(this.deleteButtonClass,
  1533. this.deleteButtonTooltip, function(b, c) {
  1534. b.deleteItem(a), c.stopPropagation()
  1535. })
  1536. },
  1537. _createSearchButton : function() {
  1538. return this._createGridButton(this.searchButtonClass,
  1539. this.searchButtonTooltip, function(a) {
  1540. a.search()
  1541. })
  1542. },
  1543. _createClearFilterButton : function() {
  1544. return this._createGridButton(this.clearFilterButtonClass,
  1545. this.clearFilterButtonTooltip, function(a) {
  1546. a.clearFilter()
  1547. })
  1548. },
  1549. _createInsertButton : function() {
  1550. return this._createGridButton(this.insertButtonClass,
  1551. this.insertButtonTooltip, function(a) {
  1552. a.insertItem().done(function() {
  1553. a.clearInsert()
  1554. })
  1555. })
  1556. },
  1557. _createUpdateButton : function() {
  1558. return this._createGridButton(this.updateButtonClass,
  1559. this.updateButtonTooltip, function(a, b) {
  1560. a.updateItem(), b.stopPropagation()
  1561. })
  1562. },
  1563. _createCancelEditButton : function() {
  1564. return this._createGridButton(this.cancelEditButtonClass,
  1565. this.cancelEditButtonTooltip, function(a, b) {
  1566. a.cancelEdit(), b.stopPropagation()
  1567. })
  1568. },
  1569. _createGridButton : function(a, c, d) {
  1570. var e = this._grid;
  1571. return b("<input>").addClass(this.buttonClass).addClass(a).attr({
  1572. type : "button",
  1573. title : c
  1574. }).on("click", function(a) {
  1575. d(e, a)
  1576. })
  1577. },
  1578. editValue : function() {
  1579. return ""
  1580. }
  1581. }), a.fields.control = a.ControlField = c
  1582. }(jsGrid, jQuery);