grid.js 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547
  1. /**
  2. * Copyright © Magento, Inc. All rights reserved.
  3. * See COPYING.txt for license details.
  4. */
  5. // also depends on a mage/adminhtml/tools.js for Base64 encoding
  6. /* global varienGrid, setLocation, varienGlobalEvents, FORM_KEY,
  7. BASE_URL, Base64, varienGridMassaction, varienStringArray, serializerController
  8. */
  9. /* eslint-disable strict */
  10. define([
  11. 'jquery',
  12. 'mage/template',
  13. 'Magento_Ui/js/modal/alert',
  14. 'Magento_Ui/js/modal/confirm',
  15. 'mage/mage',
  16. 'prototype',
  17. 'mage/adminhtml/form',
  18. 'mage/adminhtml/events'
  19. ], function (jQuery, mageTemplate, alert, confirm) {
  20. /**
  21. * @param {*} grid
  22. * @param {*} event
  23. */
  24. function openGridRow(grid, event) {
  25. var element = Event.findElement(event, 'tr');
  26. if (['a', 'input', 'select', 'option'].indexOf(Event.element(event).tagName.toLowerCase()) !== -1) {
  27. return;
  28. }
  29. if (element.title) {
  30. setLocation(element.title);
  31. }
  32. }
  33. window.openGridRow = openGridRow;
  34. window.varienGrid = new Class.create();
  35. varienGrid.prototype = {
  36. /**
  37. * @param {String} containerId
  38. * @param {String} url
  39. * @param {*} pageVar
  40. * @param {*} sortVar
  41. * @param {*} dirVar
  42. * @param {*} filterVar
  43. */
  44. initialize: function (containerId, url, pageVar, sortVar, dirVar, filterVar) {
  45. this.containerId = containerId;
  46. jQuery('#' + containerId).data('gridObject', this);
  47. this.url = url;
  48. this.pageVar = pageVar || false;
  49. this.sortVar = sortVar || false;
  50. this.dirVar = dirVar || false;
  51. this.filterVar = filterVar || false;
  52. this.tableSufix = '_table';
  53. this.useAjax = false;
  54. this.rowClickCallback = false;
  55. this.checkboxCheckCallback = false;
  56. this.preInitCallback = false;
  57. this.initCallback = false;
  58. this.initRowCallback = false;
  59. this.doFilterCallback = false;
  60. this.sortableUpdateCallback = false;
  61. this.reloadParams = false;
  62. this.trOnMouseOver = this.rowMouseOver.bindAsEventListener(this);
  63. this.trOnMouseOut = this.rowMouseOut.bindAsEventListener(this);
  64. this.trOnClick = this.rowMouseClick.bindAsEventListener(this);
  65. this.trOnDblClick = this.rowMouseDblClick.bindAsEventListener(this);
  66. this.trOnKeyPress = this.keyPress.bindAsEventListener(this);
  67. this.thLinkOnClick = this.doSort.bindAsEventListener(this);
  68. this.initGrid();
  69. },
  70. /**
  71. * Init grid.
  72. */
  73. initGrid: function () {
  74. var row, columns, col;
  75. if (this.preInitCallback) {
  76. this.preInitCallback(this);
  77. }
  78. if ($(this.containerId + this.tableSufix)) {
  79. this.rows = $$('#' + this.containerId + this.tableSufix + ' tbody tr');
  80. for (row = 0; row < this.rows.length; row++) {
  81. if (row % 2 == 0) { //eslint-disable-line eqeqeq, max-depth
  82. Element.addClassName(this.rows[row], 'even');
  83. }
  84. Event.observe(this.rows[row], 'mouseover', this.trOnMouseOver);
  85. Event.observe(this.rows[row], 'mouseout', this.trOnMouseOut);
  86. Event.observe(this.rows[row], 'click', this.trOnClick);
  87. Event.observe(this.rows[row], 'dblclick', this.trOnDblClick);
  88. }
  89. }
  90. if (this.sortVar && this.dirVar) {
  91. columns = $$('#' + this.containerId + this.tableSufix + ' thead [data-sort]');
  92. for (col = 0; col < columns.length; col++) {
  93. Event.observe(columns[col], 'click', this.thLinkOnClick);
  94. }
  95. }
  96. this.bindFilterFields();
  97. this.bindFieldsChange();
  98. if (this.initCallback) {
  99. try {
  100. this.initCallback(this);
  101. }
  102. catch (e) {
  103. if (window.console) { //eslint-disable-line max-depth
  104. console.log(e);
  105. }
  106. }
  107. }
  108. jQuery('#' + this.containerId).trigger('gridinit', this);
  109. },
  110. /**
  111. * Init grid ajax.
  112. */
  113. initGridAjax: function () {
  114. this.initGrid();
  115. this.initGridRows();
  116. },
  117. /**
  118. * Init grid rows.
  119. */
  120. initGridRows: function () {
  121. var row;
  122. if (this.initRowCallback) {
  123. for (row = 0; row < this.rows.length; row++) {
  124. try { //eslint-disable-line max-depth
  125. this.initRowCallback(this, this.rows[row]);
  126. } catch (e) {
  127. if (window.console) { //eslint-disable-line max-depth
  128. console.log(e);
  129. }
  130. }
  131. }
  132. }
  133. },
  134. /**
  135. * @param {*} event
  136. */
  137. rowMouseOver: function (event) {
  138. var element = Event.findElement(event, 'tr');
  139. if (!element.title) {
  140. return;
  141. }
  142. Element.addClassName(element, 'on-mouse');
  143. if (!Element.hasClassName('_clickable') && (this.rowClickCallback !== openGridRow || element.title)) {
  144. if (element.title) {
  145. Element.addClassName(element, '_clickable');
  146. }
  147. }
  148. },
  149. /**
  150. * @param {*} event
  151. */
  152. rowMouseOut: function (event) {
  153. var element = Event.findElement(event, 'tr');
  154. Element.removeClassName(element, 'on-mouse');
  155. },
  156. /**
  157. * @param {*} event
  158. */
  159. rowMouseClick: function (event) {
  160. if (this.rowClickCallback) {
  161. try {
  162. this.rowClickCallback(this, event);
  163. }
  164. catch (e) {
  165. }
  166. }
  167. varienGlobalEvents.fireEvent('gridRowClick', event);
  168. },
  169. /**
  170. * @param {*} event
  171. */
  172. rowMouseDblClick: function (event) {
  173. varienGlobalEvents.fireEvent('gridRowDblClick', event);
  174. },
  175. /**
  176. * Key press.
  177. */
  178. keyPress: function () {},
  179. /**
  180. * @param {*} event
  181. * @return {Boolean}
  182. */
  183. doSort: function (event) {
  184. var element = Event.findElement(event, 'th');
  185. if (element.readAttribute('data-sort') && element.readAttribute('data-direction')) {
  186. this.addVarToUrl(this.sortVar, element.readAttribute('data-sort'));
  187. this.addVarToUrl(this.dirVar, element.readAttribute('data-direction'));
  188. this.reload(this.url);
  189. }
  190. Event.stop(event);
  191. return false;
  192. },
  193. /**
  194. * @param {Object} element
  195. */
  196. loadByElement: function (element) {
  197. if (element && element.name) {
  198. this.reload(this.addVarToUrl(element.name, element.value));
  199. }
  200. },
  201. /**
  202. * @param {*} data
  203. * @param {*} textStatus
  204. * @param {*} transport
  205. * @private
  206. */
  207. _onAjaxSeccess: function (data, textStatus, transport) {
  208. var responseText, response, divId;
  209. /* eslint-disable max-depth */
  210. try {
  211. responseText = transport.responseText;
  212. if (transport.responseText.isJSON()) {
  213. response = transport.responseText.evalJSON();
  214. if (response.error) {
  215. alert({
  216. content: response.message
  217. });
  218. }
  219. if (response.ajaxExpired && response.ajaxRedirect) {
  220. setLocation(response.ajaxRedirect);
  221. }
  222. } else {
  223. /*eslint-disable max-len*/
  224. /**
  225. * For IE <= 7.
  226. * If there are two elements, and first has name, that equals id of second.
  227. * In this case, IE will choose one that is above
  228. *
  229. * @see https://prototype.lighthouseapp.com/projects/8886/tickets/994-id-selector-finds-elements-by-name-attribute-in-ie7
  230. */
  231. /*eslint-enable max-len*/
  232. divId = $(this.containerId);
  233. if (divId.id == this.containerId) { //eslint-disable-line eqeqeq
  234. divId.update(responseText);
  235. } else {
  236. $$('div[id="' + this.containerId + '"]')[0].update(responseText);
  237. }
  238. }
  239. } catch (e) {
  240. divId = $(this.containerId);
  241. if (divId.id == this.containerId) { //eslint-disable-line eqeqeq
  242. divId.update(responseText);
  243. } else {
  244. $$('div[id="' + this.containerId + '"]')[0].update(responseText);
  245. }
  246. }
  247. /* eslint-enable max-depth */
  248. jQuery('#' + this.containerId).trigger('contentUpdated');
  249. },
  250. /**
  251. * @param {*} url
  252. * @param {Function} onSuccessCallback
  253. * @return {*}
  254. */
  255. reload: function (url, onSuccessCallback) {
  256. var ajaxSettings, ajaxRequest;
  257. this.reloadParams = this.reloadParams || {};
  258. this.reloadParams['form_key'] = FORM_KEY;
  259. url = url || this.url;
  260. if (this.useAjax) {
  261. ajaxSettings = {
  262. url: url + (url.match(new RegExp('\\?')) ? '&ajax=true' : '?ajax=true'),
  263. showLoader: true,
  264. method: 'post',
  265. context: jQuery('#' + this.containerId),
  266. data: this.reloadParams,
  267. error: this._processFailure.bind(this),
  268. complete: this.initGridAjax.bind(this),
  269. dataType: 'html',
  270. /**
  271. * Success callback.
  272. */
  273. success: function (data, textStatus, transport) {
  274. this._onAjaxSeccess(data, textStatus, transport);
  275. if (onSuccessCallback && typeof onSuccessCallback === 'function') {
  276. // execute the callback, passing parameters as necessary
  277. onSuccessCallback();
  278. }
  279. }.bind(this)
  280. };
  281. jQuery('#' + this.containerId).trigger('gridajaxsettings', ajaxSettings);
  282. ajaxRequest = jQuery.ajax(ajaxSettings);
  283. jQuery('#' + this.containerId).trigger('gridajax', ajaxRequest);
  284. return ajaxRequest;
  285. }
  286. if (this.reloadParams) {
  287. $H(this.reloadParams).each(function (pair) {
  288. url = this.addVarToUrl(pair.key, pair.value);
  289. }.bind(this));
  290. }
  291. location.href = url;
  292. },
  293. /**
  294. * @private
  295. */
  296. _processFailure: function () {
  297. location.href = BASE_URL;
  298. },
  299. /**
  300. * @param {*} url
  301. * @param {*} varName
  302. * @param {*} varValue
  303. * @return {String|*}
  304. * @private
  305. */
  306. _addVarToUrl: function (url, varName, varValue) {
  307. var re = new RegExp('\/(' + varName + '\/.*?\/)'),
  308. parts = url.split(new RegExp('\\?'));
  309. url = parts[0].replace(re, '/');
  310. url += varName + '/' + varValue + '/';
  311. if (parts.size() > 1) {
  312. url += '?' + parts[1];
  313. }
  314. return url;
  315. },
  316. /**
  317. * @param {*} varName
  318. * @param {*} varValue
  319. * @return {*|String}
  320. */
  321. addVarToUrl: function (varName, varValue) {
  322. this.url = this._addVarToUrl(this.url, varName, varValue);
  323. return this.url;
  324. },
  325. /**
  326. * Do export.
  327. */
  328. doExport: function () {
  329. var exportUrl;
  330. if ($(this.containerId + '_export')) {
  331. exportUrl = $(this.containerId + '_export').value;
  332. if (this.massaction && this.massaction.checkedString) {
  333. exportUrl = this._addVarToUrl(
  334. exportUrl,
  335. this.massaction.formFieldNameInternal,
  336. this.massaction.checkedString
  337. );
  338. }
  339. location.href = exportUrl;
  340. }
  341. },
  342. /**
  343. * Bind filter fields.
  344. */
  345. bindFilterFields: function () {
  346. var filters = $$(
  347. '#' + this.containerId + ' [data-role="filter-form"] input',
  348. '#' + this.containerId + ' [data-role="filter-form"] select'
  349. ),
  350. i;
  351. for (i = 0; i < filters.length; i++) {
  352. Event.observe(filters[i], 'keypress', this.filterKeyPress.bind(this));
  353. }
  354. },
  355. /**
  356. * Bind field change.
  357. */
  358. bindFieldsChange: function () {
  359. var dataElements, i;
  360. if (!$(this.containerId)) {
  361. return;
  362. }
  363. //var dataElements = $(this.containerId+this.tableSufix).down('.data tbody').select('input', 'select');
  364. dataElements = $(this.containerId + this.tableSufix).down('tbody').select('input', 'select');
  365. for (i = 0; i < dataElements.length; i++) {
  366. Event.observe(dataElements[i], 'change', dataElements[i].setHasChanges.bind(dataElements[i]));
  367. }
  368. },
  369. /**
  370. * Bind sortable.
  371. */
  372. bindSortable: function () {
  373. if (jQuery('#' + this.containerId).find('.draggable-handle').length) {
  374. jQuery('#' + this.containerId).find('tbody').sortable({
  375. axis: 'y',
  376. handle: '.draggable-handle',
  377. /**
  378. * @param {*} event
  379. * @param {*} ui
  380. * @return {*}
  381. */
  382. helper: function (event, ui) {
  383. ui.children().each(function () {
  384. jQuery(this).width(jQuery(this).width());
  385. });
  386. return ui;
  387. },
  388. update: this.sortableUpdateCallback ? this.sortableUpdateCallback : function () {},
  389. tolerance: 'pointer'
  390. });
  391. }
  392. },
  393. /**
  394. * @param {Object} event
  395. */
  396. filterKeyPress: function (event) {
  397. if (event.keyCode == Event.KEY_RETURN) { //eslint-disable-line eqeqeq
  398. this.doFilter();
  399. }
  400. },
  401. /**
  402. * @param {Function} callback
  403. */
  404. doFilter: function (callback) {
  405. var filters = $$(
  406. '#' + this.containerId + ' [data-role="filter-form"] input',
  407. '#' + this.containerId + ' [data-role="filter-form"] select'
  408. ),
  409. elements = [],
  410. i;
  411. for (i in filters) {
  412. if (filters[i].value && filters[i].value.length) {
  413. elements.push(filters[i]);
  414. }
  415. }
  416. if (!this.doFilterCallback || this.doFilterCallback && this.doFilterCallback()) {
  417. this.reload(
  418. this.addVarToUrl(this.filterVar, Base64.encode(Form.serializeElements(elements))),
  419. callback
  420. );
  421. }
  422. },
  423. /**
  424. * @param {Function} callback
  425. */
  426. resetFilter: function (callback) {
  427. this.reload(this.addVarToUrl(this.filterVar, ''), callback);
  428. },
  429. /**
  430. * @param {Object} element
  431. */
  432. checkCheckboxes: function (element) {
  433. var elements = Element.select($(this.containerId), 'input[name="' + element.name + '"]'),
  434. i;
  435. for (i = 0; i < elements.length; i++) {
  436. this.setCheckboxChecked(elements[i], element.checked);
  437. }
  438. /*eslint-enable no-undef*/
  439. },
  440. /**
  441. *
  442. * @param {HTMLElement} element
  443. * @param {*} checked
  444. */
  445. setCheckboxChecked: function (element, checked) {
  446. element.checked = checked;
  447. jQuery(element).trigger('change');
  448. element.setHasChanges({});
  449. if (this.checkboxCheckCallback) {
  450. this.checkboxCheckCallback(this, element, checked);
  451. }
  452. },
  453. /**
  454. * @param {Object} event
  455. */
  456. inputPage: function (event) {
  457. var element = Event.element(event),
  458. keyCode = event.keyCode || event.which;
  459. if (keyCode == Event.KEY_RETURN) { //eslint-disable-line eqeqeq
  460. this.setPage(element.value);
  461. }
  462. /*if(keyCode>47 && keyCode<58){
  463. }
  464. else{
  465. Event.stop(event);
  466. }*/
  467. },
  468. /**
  469. * @param {*} pageNumber
  470. */
  471. setPage: function (pageNumber) {
  472. this.reload(this.addVarToUrl(this.pageVar, pageNumber));
  473. }
  474. };
  475. window.varienGridMassaction = Class.create();
  476. varienGridMassaction.prototype = {
  477. /* Predefined vars */
  478. checkedValues: $H({}),
  479. checkedString: '',
  480. oldCallbacks: {},
  481. errorText: '',
  482. items: {},
  483. gridIds: [],
  484. useSelectAll: false,
  485. currentItem: false,
  486. lastChecked: {
  487. left: false,
  488. top: false,
  489. checkbox: false
  490. },
  491. fieldTemplate: mageTemplate('<input type="hidden" name="<%- name %>" value="<%- value %>" />'),
  492. /**
  493. * @param {*} containerId
  494. * @param {*} grid
  495. * @param {*} checkedValues
  496. * @param {*} formFieldNameInternal
  497. * @param {*} formFieldName
  498. */
  499. initialize: function (containerId, grid, checkedValues, formFieldNameInternal, formFieldName) {
  500. this.setOldCallback('row_click', grid.rowClickCallback);
  501. this.setOldCallback('init', grid.initCallback);
  502. this.setOldCallback('init_row', grid.initRowCallback);
  503. this.setOldCallback('pre_init', grid.preInitCallback);
  504. this.useAjax = false;
  505. this.grid = grid;
  506. this.grid.massaction = this;
  507. this.containerId = containerId;
  508. this.initMassactionElements();
  509. this.checkedString = checkedValues;
  510. this.formFieldName = formFieldName;
  511. this.formFieldNameInternal = formFieldNameInternal;
  512. this.grid.initCallback = this.onGridInit.bind(this);
  513. this.grid.preInitCallback = this.onGridPreInit.bind(this);
  514. this.grid.initRowCallback = this.onGridRowInit.bind(this);
  515. this.grid.rowClickCallback = this.onGridRowClick.bind(this);
  516. this.initCheckboxes();
  517. this.checkCheckboxes();
  518. },
  519. /**
  520. * @param {*} flag
  521. */
  522. setUseAjax: function (flag) {
  523. this.useAjax = flag;
  524. },
  525. /**
  526. * @param {*} flag
  527. */
  528. setUseSelectAll: function (flag) {
  529. this.useSelectAll = flag;
  530. },
  531. /**
  532. * Init massaction elements.
  533. */
  534. initMassactionElements: function () {
  535. this.container = $(this.containerId);
  536. this.multiselect = $(this.containerId + '-mass-select');
  537. this.count = $(this.containerId + '-count');
  538. this.formHiddens = $(this.containerId + '-form-hiddens');
  539. this.formAdditional = $(this.containerId + '-form-additional');
  540. this.select = $(this.containerId + '-select');
  541. this.form = this.prepareForm();
  542. jQuery(this.form).mage('validation');
  543. this.select.observe('change', this.onSelectChange.bindAsEventListener(this));
  544. this.lastChecked = {
  545. left: false,
  546. top: false,
  547. checkbox: false
  548. };
  549. this.select.addClassName(this.select.value ? '_selected' : '');
  550. this.initMassSelect();
  551. },
  552. /**
  553. * @return {jQuery|*|HTMLElement}
  554. */
  555. prepareForm: function () {
  556. var form = $(this.containerId + '-form'),
  557. formPlace = null,
  558. formElement = this.formHiddens || this.formAdditional;
  559. if (!formElement) {
  560. formElement = this.container.getElementsByTagName('button')[0];
  561. formElement && formElement.parentNode;
  562. }
  563. if (!form && formElement) {
  564. /* fix problem with rendering form in FF through innerHTML property */
  565. form = document.createElement('form');
  566. form.setAttribute('method', 'post');
  567. form.setAttribute('action', '');
  568. form.id = this.containerId + '-form';
  569. formPlace = formElement.parentNode;
  570. formPlace.parentNode.appendChild(form);
  571. form.appendChild(formPlace);
  572. }
  573. return form;
  574. },
  575. /**
  576. * @param {Array} gridIds
  577. */
  578. setGridIds: function (gridIds) {
  579. this.gridIds = gridIds;
  580. this.updateCount();
  581. },
  582. /**
  583. * @return {Array}
  584. */
  585. getGridIds: function () {
  586. return this.gridIds;
  587. },
  588. /**
  589. * @param {*} items
  590. */
  591. setItems: function (items) {
  592. this.items = items;
  593. this.updateCount();
  594. },
  595. /**
  596. * @return {Object}
  597. */
  598. getItems: function () {
  599. return this.items;
  600. },
  601. /**
  602. * @param {*} itemId
  603. * @return {*}
  604. */
  605. getItem: function (itemId) {
  606. if (this.items[itemId]) {
  607. return this.items[itemId];
  608. }
  609. return false;
  610. },
  611. /**
  612. * @param {String} callbackName
  613. * @return {Function}
  614. */
  615. getOldCallback: function (callbackName) {
  616. return this.oldCallbacks[callbackName] ? this.oldCallbacks[callbackName] : Prototype.emptyFunction;
  617. },
  618. /**
  619. * @param {String} callbackName
  620. * @param {Function} callback
  621. */
  622. setOldCallback: function (callbackName, callback) {
  623. this.oldCallbacks[callbackName] = callback;
  624. },
  625. /**
  626. * @param {*} grid
  627. */
  628. onGridPreInit: function (grid) {
  629. this.initMassactionElements();
  630. this.getOldCallback('pre_init')(grid);
  631. },
  632. /**
  633. * @param {*} grid
  634. */
  635. onGridInit: function (grid) {
  636. this.initCheckboxes();
  637. this.checkCheckboxes();
  638. this.updateCount();
  639. this.getOldCallback('init')(grid);
  640. },
  641. /**
  642. * @param {*} grid
  643. * @param {*} row
  644. */
  645. onGridRowInit: function (grid, row) {
  646. this.getOldCallback('init_row')(grid, row);
  647. },
  648. /**
  649. * @param {Object} evt
  650. */
  651. isDisabled: function (evt) {
  652. var target = jQuery(evt.target),
  653. tr,
  654. checkbox;
  655. tr = target.is('tr') ? target : target.closest('tr');
  656. checkbox = tr.find('input[type="checkbox"]');
  657. return checkbox.is(':disabled');
  658. },
  659. /**
  660. * @param {*} grid
  661. * @param {*} evt
  662. * @return {*}
  663. */
  664. onGridRowClick: function (grid, evt) {
  665. var tdElement = Event.findElement(evt, 'td'),
  666. trElement = Event.findElement(evt, 'tr'),
  667. checkbox, isInput, checked;
  668. if (this.isDisabled(evt)) {
  669. return false;
  670. }
  671. if (!$(tdElement).down('input')) {
  672. if ($(tdElement).down('a') || $(tdElement).down('select')) {
  673. return; //eslint-disable-line
  674. }
  675. if (trElement.title && trElement.title.strip() != '#') { //eslint-disable-line eqeqeq
  676. this.getOldCallback('row_click')(grid, evt);
  677. } else {
  678. checkbox = Element.select(trElement, 'input');
  679. isInput = Event.element(evt).tagName == 'input'; //eslint-disable-line eqeqeq
  680. checked = isInput ? checkbox[0].checked : !checkbox[0].checked;
  681. if (checked) { //eslint-disable-line max-depth
  682. this.checkedString = varienStringArray.add(checkbox[0].value, this.checkedString);
  683. } else {
  684. this.checkedString = varienStringArray.remove(checkbox[0].value, this.checkedString);
  685. }
  686. this.grid.setCheckboxChecked(checkbox[0], checked);
  687. this.updateCount();
  688. }
  689. return; //eslint-disable-line
  690. }
  691. if (Event.element(evt).isMassactionCheckbox) {
  692. this.setCheckbox(Event.element(evt));
  693. } else if (checkbox = this.findCheckbox(evt)) { //eslint-disable-line no-cond-assign
  694. checkbox.checked = !checkbox.checked;
  695. jQuery(checkbox).trigger('change');
  696. this.setCheckbox(checkbox);
  697. }
  698. },
  699. /**
  700. * @param {Object} evt
  701. */
  702. onSelectChange: function (evt) {
  703. var item = this.getSelectedItem();
  704. if (item) {
  705. this.formAdditional.update($(this.containerId + '-item-' + item.id + '-block').innerHTML);
  706. evt.target.addClassName('_selected');
  707. } else {
  708. this.formAdditional.update('');
  709. evt.target.removeClassName('_selected');
  710. }
  711. jQuery(this.form).data('validator').resetForm();
  712. },
  713. /**
  714. * @param {Object} evt
  715. * @return {*}
  716. */
  717. findCheckbox: function (evt) {
  718. if (['a', 'input', 'select'].indexOf(Event.element(evt).tagName.toLowerCase()) !== -1) {
  719. return false;
  720. }
  721. checkbox = false; //eslint-disable-line no-undef
  722. Event.findElement(evt, 'tr').select('[data-role="select-row"]').each(function (element) { //eslint-disable-line
  723. if (element.isMassactionCheckbox) {
  724. checkbox = element; //eslint-disable-line no-undef
  725. }
  726. });
  727. return checkbox; //eslint-disable-line no-undef
  728. },
  729. /**
  730. * Init checkobox.
  731. */
  732. initCheckboxes: function () {
  733. this.getCheckboxes().each(function (checkbox) { //eslint-disable-line no-extra-bind
  734. checkbox.isMassactionCheckbox = true; //eslint-disable-line no-undef
  735. });
  736. },
  737. /**
  738. * Check checkbox.
  739. */
  740. checkCheckboxes: function () {
  741. this.getCheckboxes().each(function (checkbox) {
  742. checkbox.checked = varienStringArray.has(checkbox.value, this.checkedString);
  743. jQuery(checkbox).trigger('change');
  744. }.bind(this));
  745. },
  746. /**
  747. * @return {Boolean}
  748. */
  749. selectAll: function () {
  750. this.setCheckedValues(this.useSelectAll ? this.getGridIds() : this.getCheckboxesValuesAsString());
  751. this.checkCheckboxes();
  752. this.updateCount();
  753. this.clearLastChecked();
  754. return false;
  755. },
  756. /**
  757. * @return {Boolean}
  758. */
  759. unselectAll: function () {
  760. this.setCheckedValues('');
  761. this.checkCheckboxes();
  762. this.updateCount();
  763. this.clearLastChecked();
  764. return false;
  765. },
  766. /**
  767. * @return {Boolean}
  768. */
  769. selectVisible: function () {
  770. this.setCheckedValues(this.getCheckboxesValuesAsString());
  771. this.checkCheckboxes();
  772. this.updateCount();
  773. this.clearLastChecked();
  774. return false;
  775. },
  776. /**
  777. * @return {Boolean}
  778. */
  779. unselectVisible: function () {
  780. this.getCheckboxesValues().each(function (key) {
  781. this.checkedString = varienStringArray.remove(key, this.checkedString);
  782. }.bind(this));
  783. this.checkCheckboxes();
  784. this.updateCount();
  785. this.clearLastChecked();
  786. return false;
  787. },
  788. /**
  789. * @param {*} values
  790. */
  791. setCheckedValues: function (values) {
  792. this.checkedString = values;
  793. },
  794. /**
  795. * @return {String}
  796. */
  797. getCheckedValues: function () {
  798. return this.checkedString;
  799. },
  800. /**
  801. * @return {Array}
  802. */
  803. getCheckboxes: function () {
  804. var result = [];
  805. this.grid.rows.each(function (row) {
  806. var checkboxes = row.select('[data-role="select-row"]');
  807. checkboxes.each(function (checkbox) {
  808. result.push(checkbox);
  809. });
  810. });
  811. return result;
  812. },
  813. /**
  814. * @return {Array}
  815. */
  816. getCheckboxesValues: function () {
  817. var result = [];
  818. this.getCheckboxes().each(function (checkbox) { //eslint-disable-line no-extra-bind
  819. result.push(checkbox.value);
  820. });
  821. return result;
  822. },
  823. /**
  824. * @return {String}
  825. */
  826. getCheckboxesValuesAsString: function () {
  827. return this.getCheckboxesValues().join(',');
  828. },
  829. /**
  830. * @param {Object} checkbox
  831. */
  832. setCheckbox: function (checkbox) {
  833. if (checkbox.checked) {
  834. this.checkedString = varienStringArray.add(checkbox.value, this.checkedString);
  835. } else {
  836. this.checkedString = varienStringArray.remove(checkbox.value, this.checkedString);
  837. }
  838. this.updateCount();
  839. },
  840. /**
  841. * Update count.
  842. */
  843. updateCount: function () {
  844. var checkboxesTotal = varienStringArray.count(
  845. this.useSelectAll ? this.getGridIds() : this.getCheckboxesValuesAsString()
  846. ),
  847. checkboxesChecked = varienStringArray.count(this.checkedString);
  848. jQuery('[data-role="counter"]', this.count).html(checkboxesChecked);
  849. if (!checkboxesTotal) {
  850. this.multiselect.addClassName('_disabled');
  851. } else {
  852. this.multiselect.removeClassName('_disabled');
  853. }
  854. if (checkboxesChecked == checkboxesTotal && checkboxesTotal != 0) { //eslint-disable-line eqeqeq
  855. this.count.removeClassName('_empty');
  856. this.multiselect.addClassName('_checked').removeClassName('_indeterminate');
  857. } else if (checkboxesChecked == 0) { //eslint-disable-line eqeqeq
  858. this.count.addClassName('_empty');
  859. this.multiselect.removeClassName('_checked').removeClassName('_indeterminate');
  860. } else {
  861. this.count.removeClassName('_empty');
  862. this.multiselect.addClassName('_checked').addClassName('_indeterminate');
  863. }
  864. if (!this.grid.reloadParams) {
  865. this.grid.reloadParams = {};
  866. }
  867. this.grid.reloadParams[this.formFieldNameInternal] = this.checkedString;
  868. },
  869. /**
  870. * @return {*}
  871. */
  872. getSelectedItem: function () {
  873. if (this.getItem(this.select.value)) {
  874. return this.getItem(this.select.value);
  875. }
  876. return false;
  877. },
  878. /**
  879. * Apply.
  880. */
  881. apply: function () {
  882. var item, fieldName;
  883. if (varienStringArray.count(this.checkedString) == 0) { //eslint-disable-line eqeqeq
  884. alert({
  885. content: this.errorText
  886. });
  887. return;
  888. }
  889. item = this.getSelectedItem();
  890. if (!item) {
  891. jQuery(this.form).valid();
  892. return;
  893. }
  894. this.currentItem = item;
  895. fieldName = item.field ? item.field : this.formFieldName;
  896. if (this.currentItem.confirm) {
  897. confirm({
  898. content: this.currentItem.confirm,
  899. actions: {
  900. confirm: this.onConfirm.bind(this, fieldName, item)
  901. }
  902. });
  903. } else {
  904. this.onConfirm(fieldName, item);
  905. }
  906. },
  907. /**
  908. * @param {*} fieldName
  909. * @param {*} item
  910. */
  911. onConfirm: function (fieldName, item) {
  912. this.formHiddens.update('');
  913. new Insertion.Bottom(this.formHiddens, this.fieldTemplate({
  914. name: fieldName,
  915. value: this.checkedString
  916. }));
  917. new Insertion.Bottom(this.formHiddens, this.fieldTemplate({
  918. name: 'massaction_prepare_key',
  919. value: fieldName
  920. }));
  921. if (!jQuery(this.form).valid()) {
  922. return;
  923. }
  924. if (this.useAjax && item.url) {
  925. new Ajax.Request(item.url, {
  926. 'method': 'post',
  927. 'parameters': this.form.serialize(true),
  928. 'onComplete': this.onMassactionComplete.bind(this)
  929. });
  930. } else if (item.url) {
  931. this.form.action = item.url;
  932. this.form.submit();
  933. }
  934. },
  935. /**
  936. * @param {*} transport
  937. */
  938. onMassactionComplete: function (transport) {
  939. var listener;
  940. if (this.currentItem.complete) {
  941. try {
  942. listener = this.getListener(this.currentItem.complete) || Prototype.emptyFunction;
  943. listener(this.grid, this, transport);
  944. } catch (e) {}
  945. }
  946. },
  947. /**
  948. * @param {*} strValue
  949. * @return {Object}
  950. */
  951. getListener: function (strValue) {
  952. return eval(strValue); //eslint-disable-line no-eval
  953. },
  954. /**
  955. * Init mass select.
  956. */
  957. initMassSelect: function () {
  958. $$('input[data-role="select-row"]').each(function (element) {
  959. element.observe('click', this.massSelect.bind(this));
  960. }.bind(this));
  961. },
  962. /**
  963. * Clear last checked.
  964. */
  965. clearLastChecked: function () {
  966. this.lastChecked = {
  967. left: false,
  968. top: false,
  969. checkbox: false
  970. };
  971. },
  972. /**
  973. * @param {Object} evt
  974. */
  975. massSelect: function (evt) {
  976. var currentCheckbox, lastCheckbox, start, finish;
  977. if (this.lastChecked.left !== false &&
  978. this.lastChecked.top !== false &&
  979. evt.button === 0 &&
  980. evt.shiftKey === true
  981. ) {
  982. currentCheckbox = Event.element(evt);
  983. lastCheckbox = this.lastChecked.checkbox;
  984. if (lastCheckbox != currentCheckbox) { //eslint-disable-line eqeqeq
  985. start = this.getCheckboxOrder(lastCheckbox);
  986. finish = this.getCheckboxOrder(currentCheckbox);
  987. if (start !== false && finish !== false) { //eslint-disable-line max-depth
  988. this.selectCheckboxRange(
  989. Math.min(start, finish),
  990. Math.max(start, finish),
  991. currentCheckbox.checked
  992. );
  993. }
  994. }
  995. }
  996. this.lastChecked = {
  997. left: Event.element(evt).viewportOffset().left,
  998. top: Event.element(evt).viewportOffset().top,
  999. checkbox: Event.element(evt) // "boundary" checkbox
  1000. };
  1001. },
  1002. /**
  1003. * @param {*} curCheckbox
  1004. * @return {Boolean}
  1005. */
  1006. getCheckboxOrder: function (curCheckbox) {
  1007. var order = false;
  1008. this.getCheckboxes().each(function (checkbox, key) {
  1009. if (curCheckbox == checkbox) { //eslint-disable-line eqeqeq
  1010. order = key;
  1011. }
  1012. });
  1013. return order;
  1014. },
  1015. /**
  1016. * @param {*} start
  1017. * @param {*} finish
  1018. * @param {*} isChecked
  1019. */
  1020. selectCheckboxRange: function (start, finish, isChecked) {
  1021. this.getCheckboxes().each(function (checkbox, key) {
  1022. if (key >= start && key <= finish) {
  1023. checkbox.checked = isChecked;
  1024. this.setCheckbox(checkbox);
  1025. }
  1026. }.bind(this));
  1027. }
  1028. };
  1029. window.varienGridAction = {
  1030. /**
  1031. * @param {Object} select
  1032. */
  1033. execute: function (select) {
  1034. var config, win;
  1035. if (!select.value || !select.value.isJSON()) {
  1036. return;
  1037. }
  1038. config = select.value.evalJSON();
  1039. if (config.confirm && !window.confirm(config.confirm)) { //eslint-disable-line no-alert
  1040. select.options[0].selected = true;
  1041. return;
  1042. }
  1043. if (config.popup) {
  1044. win = window.open(config.href, 'action_window', 'width=500,height=600,resizable=1,scrollbars=1');
  1045. win.focus();
  1046. select.options[0].selected = true;
  1047. } else {
  1048. setLocation(config.href);
  1049. }
  1050. }
  1051. };
  1052. window.varienStringArray = {
  1053. /**
  1054. * @param {*} str
  1055. * @param {*} haystack
  1056. * @return {*}
  1057. */
  1058. remove: function (str, haystack) {
  1059. haystack = ',' + haystack + ',';
  1060. haystack = haystack.replace(new RegExp(',' + str + ',', 'g'), ',');
  1061. return this.trimComma(haystack);
  1062. },
  1063. /**
  1064. * @param {*} str
  1065. * @param {*} haystack
  1066. * @return {*}
  1067. */
  1068. add: function (str, haystack) {
  1069. haystack = ',' + haystack + ',';
  1070. if (haystack.search(new RegExp(',' + str + ',', 'g'), haystack) === -1) {
  1071. haystack += str + ',';
  1072. }
  1073. return this.trimComma(haystack);
  1074. },
  1075. /**
  1076. * @param {*} str
  1077. * @param {*} haystack
  1078. * @return {Boolean}
  1079. */
  1080. has: function (str, haystack) {
  1081. haystack = ',' + haystack + ',';
  1082. if (haystack.search(new RegExp(',' + str + ',', 'g'), haystack) === -1) {
  1083. return false;
  1084. }
  1085. return true;
  1086. },
  1087. /**
  1088. * @param {*} haystack
  1089. * @return {*}
  1090. */
  1091. count: function (haystack) {
  1092. var match;
  1093. if (typeof haystack != 'string') {
  1094. return 0;
  1095. }
  1096. /* eslint-disable no-undef, no-cond-assign, eqeqeq */
  1097. if (match = haystack.match(new RegExp(',', 'g'))) {
  1098. return match.length + 1;
  1099. } else if (haystack.length != 0) {
  1100. return 1;
  1101. }
  1102. /* eslint-enable no-undef, no-cond-assign, eqeqeq */
  1103. return 0;
  1104. },
  1105. /**
  1106. * @param {*} haystack
  1107. * @param {*} fnc
  1108. */
  1109. each: function (haystack, fnc) {
  1110. var i;
  1111. haystack = haystack.split(',');
  1112. for (i = 0; i < haystack.length; i++) {
  1113. fnc(haystack[i]);
  1114. }
  1115. },
  1116. /**
  1117. * @param {String} string
  1118. * @return {String}
  1119. */
  1120. trimComma: function (string) {
  1121. string = string.replace(new RegExp('^(,+)','i'), '');
  1122. string = string.replace(new RegExp('(,+)$','i'), '');
  1123. return string;
  1124. }
  1125. };
  1126. window.serializerController = Class.create();
  1127. serializerController.prototype = {
  1128. oldCallbacks: {},
  1129. /**
  1130. * @param {*} hiddenDataHolder
  1131. * @param {*} predefinedData
  1132. * @param {*} inputsToManage
  1133. * @param {*} grid
  1134. * @param {*} reloadParamName
  1135. */
  1136. initialize: function (hiddenDataHolder, predefinedData, inputsToManage, grid, reloadParamName) {
  1137. //Grid inputs
  1138. this.tabIndex = 1000;
  1139. this.inputsToManage = inputsToManage;
  1140. this.multidimensionalMode = inputsToManage.length > 0;
  1141. //Hash with grid data
  1142. this.gridData = this.getGridDataHash(predefinedData);
  1143. //Hidden input data holder
  1144. this.hiddenDataHolder = $(hiddenDataHolder);
  1145. this.hiddenDataHolder.value = this.serializeObject();
  1146. this.grid = grid;
  1147. // Set old callbacks
  1148. this.setOldCallback('row_click', this.grid.rowClickCallback);
  1149. this.setOldCallback('init_row', this.grid.initRowCallback);
  1150. this.setOldCallback('checkbox_check', this.grid.checkboxCheckCallback);
  1151. //Grid
  1152. this.reloadParamName = reloadParamName;
  1153. this.grid.reloadParams = {};
  1154. this.grid.reloadParams[this.reloadParamName + '[]'] = this.getDataForReloadParam();
  1155. this.grid.rowClickCallback = this.rowClick.bind(this);
  1156. this.grid.initRowCallback = this.rowInit.bind(this);
  1157. this.grid.checkboxCheckCallback = this.registerData.bind(this);
  1158. this.grid.rows.each(this.eachRow.bind(this));
  1159. },
  1160. /**
  1161. * @param {String} callbackName
  1162. * @param {Function} callback
  1163. */
  1164. setOldCallback: function (callbackName, callback) {
  1165. this.oldCallbacks[callbackName] = callback;
  1166. },
  1167. /**
  1168. * @param {String} callbackName
  1169. * @return {Prototype.emptyFunction}
  1170. */
  1171. getOldCallback: function (callbackName) {
  1172. return this.oldCallbacks[callbackName] ? this.oldCallbacks[callbackName] : Prototype.emptyFunction;
  1173. },
  1174. /**
  1175. * @param {*} grid
  1176. * @param {*} element
  1177. * @param {*} checked
  1178. */
  1179. registerData: function (grid, element, checked) {
  1180. var i;
  1181. if (this.multidimensionalMode) {
  1182. if (checked) {
  1183. /*eslint-disable max-depth*/
  1184. if (element.inputElements) {
  1185. this.gridData.set(element.value, {});
  1186. for (i = 0; i < element.inputElements.length; i++) {
  1187. element.inputElements[i].disabled = false;
  1188. this.gridData.get(element.value)[element.inputElements[i].name] =
  1189. element.inputElements[i].value;
  1190. }
  1191. }
  1192. } else {
  1193. if (element.inputElements) {
  1194. for (i = 0; i < element.inputElements.length; i++) {
  1195. element.inputElements[i].disabled = true;
  1196. }
  1197. }
  1198. this.gridData.unset(element.value);
  1199. }
  1200. } else {
  1201. if (checked) { //eslint-disable-line no-lonely-if
  1202. this.gridData.set(element.value, element.value);
  1203. } else {
  1204. this.gridData.unset(element.value);
  1205. }
  1206. }
  1207. this.hiddenDataHolder.value = this.serializeObject();
  1208. this.grid.reloadParams = {};
  1209. this.grid.reloadParams[this.reloadParamName + '[]'] = this.getDataForReloadParam();
  1210. this.getOldCallback('checkbox_check')(grid, element, checked);
  1211. /*eslint-enable max-depth*/
  1212. },
  1213. /**
  1214. * @param {*} row
  1215. */
  1216. eachRow: function (row) {
  1217. this.rowInit(this.grid, row);
  1218. },
  1219. /**
  1220. * @param {*} grid
  1221. * @param {*} event
  1222. */
  1223. rowClick: function (grid, event) {
  1224. var trElement = Event.findElement(event, 'tr'),
  1225. isInput = Event.element(event).tagName == 'INPUT', //eslint-disable-line eqeqeq
  1226. checkbox, checked;
  1227. if (trElement) {
  1228. checkbox = Element.select(trElement, 'input');
  1229. if (checkbox[0] && !checkbox[0].disabled) {
  1230. checked = isInput ? checkbox[0].checked : !checkbox[0].checked;
  1231. this.grid.setCheckboxChecked(checkbox[0], checked);
  1232. }
  1233. }
  1234. this.getOldCallback('row_click')(grid, event);
  1235. },
  1236. /**
  1237. * @param {*} event
  1238. */
  1239. inputChange: function (event) {
  1240. var element = Event.element(event);
  1241. if (element && element.checkboxElement && element.checkboxElement.checked) {
  1242. this.gridData.get(element.checkboxElement.value)[element.name] = element.value;
  1243. this.hiddenDataHolder.value = this.serializeObject();
  1244. }
  1245. },
  1246. /**
  1247. * @param {*} grid
  1248. * @param {*} row
  1249. */
  1250. rowInit: function (grid, row) {
  1251. var checkbox, selectors, inputs, i;
  1252. if (this.multidimensionalMode) {
  1253. checkbox = $(row).select('.checkbox')[0];
  1254. selectors = this.inputsToManage.map(function (name) {
  1255. return ['input[name="' + name + '"]', 'select[name="' + name + '"]'];
  1256. });
  1257. inputs = $(row).select.apply($(row), selectors.flatten());
  1258. if (checkbox && inputs.length > 0) {
  1259. checkbox.inputElements = inputs;
  1260. /* eslint-disable max-depth */
  1261. for (i = 0; i < inputs.length; i++) {
  1262. inputs[i].checkboxElement = checkbox;
  1263. if (this.gridData.get(checkbox.value) && this.gridData.get(checkbox.value)[inputs[i].name]) {
  1264. inputs[i].value = this.gridData.get(checkbox.value)[inputs[i].name];
  1265. }
  1266. inputs[i].disabled = !checkbox.checked;
  1267. inputs[i].tabIndex = this.tabIndex++;
  1268. Event.observe(inputs[i], 'keyup', this.inputChange.bind(this));
  1269. Event.observe(inputs[i], 'change', this.inputChange.bind(this));
  1270. }
  1271. }
  1272. }
  1273. /* eslint-enable max-depth */
  1274. this.getOldCallback('init_row')(grid, row);
  1275. },
  1276. /**
  1277. * Stuff methods.
  1278. *
  1279. * @param {*} _object
  1280. * @return {*}
  1281. */
  1282. getGridDataHash: function (_object) {
  1283. return $H(this.multidimensionalMode ? _object : this.convertArrayToObject(_object));
  1284. },
  1285. /**
  1286. * @return {*}
  1287. */
  1288. getDataForReloadParam: function () {
  1289. return this.multidimensionalMode ? this.gridData.keys() : this.gridData.values();
  1290. },
  1291. /**
  1292. * @return {*}
  1293. */
  1294. serializeObject: function () {
  1295. var clone;
  1296. if (this.multidimensionalMode) {
  1297. clone = this.gridData.clone();
  1298. clone.each(function (pair) {
  1299. clone.set(pair.key, Base64.encode(Object.toQueryString(pair.value)));
  1300. });
  1301. return clone.toQueryString();
  1302. }
  1303. return this.gridData.values().join('&');
  1304. },
  1305. /**
  1306. * @param {Array} _array
  1307. * @return {Object}
  1308. */
  1309. convertArrayToObject: function (_array) {
  1310. var _object = {},
  1311. i, l;
  1312. for (i = 0, l = _array.length; i < l; i++) {
  1313. _object[_array[i]] = _array[i];
  1314. }
  1315. return _object;
  1316. }
  1317. };
  1318. });