BxDolGrid.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605
  1. /**
  2. * Copyright (c) UNA, Inc - https://una.io
  3. * MIT License - https://opensource.org/licenses/MIT
  4. *
  5. * @defgroup UnaCore UNA Core
  6. * @{
  7. */
  8. function BxDolGrid (sObject, oOptions) {
  9. this._iSearchTimeoutId = false;
  10. this._sObject = sObject;
  11. this._sIdWrapper = 'bx-grid-wrap-' + sObject;
  12. this._sIdContainer = 'bx-grid-cont-' + sObject;
  13. this._sIdTable = 'bx-grid-table-' + sObject;
  14. this._oOptions = oOptions;
  15. this._sCsrfToken = oOptions.csrf_token;
  16. this._sOrderField = undefined == oOptions.order_field ? '' : oOptions.order_field;
  17. this._sOrderDir = undefined == oOptions.order_dir ? 'ASC' : oOptions.order_dir;
  18. this._sSearchInputText = undefined == oOptions.text_search_input ? '' : oOptions.text_search_input;
  19. this._oPopupOptions = $.extend({
  20. onBeforeShow: function(oElement) {
  21. jQuery(oElement).bxProcessHtml();
  22. }
  23. }, oOptions.popup_options);
  24. this._oQueryAppend = oOptions.query_append;
  25. this._oConfirmMessages = oOptions.confirm_messages;
  26. this.onReload = null;
  27. this.init(oOptions);
  28. }
  29. BxDolGrid.prototype.init = function (oOptions) {
  30. this._sFilter = undefined == oOptions.filter ? '' : oOptions.filter;
  31. if (this._sFilter.length)
  32. this._sSearchInputText = this._sFilter;
  33. $('#bx-grid-search-' + this._sObject).val(this._sSearchInputText);
  34. this._oQueryAppend = oOptions.query_append;
  35. this._onDataReloaded();
  36. if (this._sOrderField.length)
  37. this.setSorting (this._sOrderField, this._sOrderDir, true);
  38. };
  39. BxDolGrid.prototype.resetSorting = function (sField, sDir) {
  40. this._sOrderField = '';
  41. this._sOrderDir = 'ASC';
  42. this.reload(0);
  43. };
  44. BxDolGrid.prototype.setSorting = function (sField, sDir, isDisableReload) {
  45. if (typeof(sField) == "undefined" || 0 == sField.length)
  46. return;
  47. if (typeof(sDir) != "undefined")
  48. this._sOrderDir = 'DESC' == sDir ? 'DESC' : 'ASC'; // explicit order
  49. else
  50. this._sOrderDir = 'ASC'; // of sorting new field, always order in asceding order
  51. this._sOrderField = sField;
  52. var sHtmlIndi = 'ASC' == this._sOrderDir ? ' ↓' : ' ↑';
  53. jQuery('#' + this._sIdTable + ' *[bx_grid_sort_head] .bx-grid-sort-indi').hide();
  54. jQuery('#' + this._sIdTable + ' *[bx_grid_sort_head=' + sField + '] .bx-grid-sort-indi').html(sHtmlIndi).show();
  55. if (typeof(isDisableReload) == "undefined" || !isDisableReload)
  56. this.reload(0);
  57. };
  58. BxDolGrid.prototype.setFilter = function (sFilter, isReload) {
  59. if (this._sFilter == sFilter)
  60. return;
  61. this._sFilter = sFilter;
  62. if (isReload) {
  63. if (sFilter.length > 0)
  64. this.reload(0);
  65. else
  66. this.reload();
  67. }
  68. };
  69. BxDolGrid.prototype.orderable = function () {
  70. var $this = this;
  71. jQuery('#' + this._sIdTable + ' *[bx_grid_sort_head] .bx-grid-sort-handle').bind('click', function () {
  72. var sField = $(this).parents('*[bx_grid_sort_head]').attr('bx_grid_sort_head');
  73. if (sField) {
  74. $this.setSorting(sField, sField == $this._sOrderField ? ('ASC' == $this._sOrderDir ? 'DESC' : 'ASC') : undefined);
  75. }
  76. });
  77. if (this._sOrderField)
  78. this.setSorting (this._sOrderField, this._sOrderDir, true);
  79. };
  80. BxDolGrid.prototype.sortable = function () {
  81. var $this = this;
  82. jQuery('#' + this._sIdTable + ' tbody .bx-grid-drag-handle').show();
  83. jQuery('#' + this._sIdTable + ' tbody').sortable({
  84. handle: '.bx-grid-drag-handle',
  85. placeholder: 'bx-grid-drag-placeholder',
  86. items:'tr',
  87. forcePlaceholderSize: true,
  88. start: function(oEvent, oUi) {
  89. jQuery('#' + $this._sIdTable + ' tbody tr').removeClass('bx-def-color-bg-hl bx-grid-table-row-trans'); // remove rows highlighting and transitions
  90. oUi.placeholder.html('<td colspan="' + $this._oOptions.columns + '">&rarr;</td>'); // add placeholder with arrow
  91. oUi.item.addClass('bx-grid-gragging-row bx-def-color-bg-active'); // apply classes for dragged row
  92. },
  93. stop: function(oEvent, oUi) {
  94. oUi.item.removeClass('bx-grid-gragging-row'); // remove classes from dragged row
  95. jQuery('#' + $this._sIdTable + ' tbody tr:odd').addClass('bx-def-color-bg-hl'); // highlight odd rows
  96. $this.blink(oUi.item.attr('id')); // make dropped row to blink, so we clearly see where dropped row is places
  97. // searialize current rows order and send result to the server for saving
  98. var s = jQuery('#' + $this._sIdTable + ' tbody').sortable('serialize');
  99. $this.action('reorder', {}, s, true);
  100. }
  101. });
  102. };
  103. BxDolGrid.prototype.blink = function (sId) {
  104. var e = jQuery('#' + sId);
  105. e.removeClass('bx-grid-table-row-trans');
  106. e.addClass('bx-def-color-bg-active');
  107. setTimeout('glGrids.' + this._sObject + '._blinkCallback("' + sId + '")', 200);
  108. };
  109. BxDolGrid.prototype.enable = function (sId, isEnable) {
  110. var e = jQuery('#' + sId);
  111. var eSwitch = e.find('.bx-switcher-cont:has([bx_grid_action_single = "enable"])');
  112. var eActions = e.find('.bx-grid-cell-single-actions-wrapper *[bx_grid_action_single]').not('*[bx_grid_permanent_state]');
  113. if (isEnable) {
  114. e.removeClass('bx-grid-table-row-disabled bx-def-font-grayed');
  115. eSwitch.removeClass('off').addClass('on');
  116. eActions.removeClass('bx-btn-disabled');
  117. if (eActions.length)
  118. this._bindActionsSingle(e);
  119. } else {
  120. eActions.addClass('bx-btn-disabled');
  121. eSwitch.removeClass('on').addClass('off');
  122. e.addClass('bx-grid-table-row-disabled bx-def-font-grayed');
  123. if (eActions.length)
  124. this._unbindActionsSingle(e);
  125. }
  126. };
  127. BxDolGrid.prototype._blinkCallback = function (sId) {
  128. var e = jQuery('#' + sId);
  129. e.addClass('bx-grid-table-row-trans');
  130. e.removeClass('bx-def-color-bg-active');
  131. };
  132. BxDolGrid.prototype.actionSingle = function (sAction, sId, oExtra) {
  133. oExtra = oExtra || {};
  134. var isConfirm = typeof(oExtra.confirm) != 'undefined' ? oExtra.confirm : 0;
  135. var iActionResetPaginate = typeof(oExtra.reset_paginate) != 'undefined' ? parseInt(oExtra.reset_paginate) : (String(sAction).indexOf('delete') === -1 ? 0 : 1);
  136. var oData = iActionResetPaginate ? {} : this._getActionDataForReload();
  137. if (typeof(oExtra.data) == 'object')
  138. oData = $.extend({}, oData, oExtra.data);
  139. this.actionWithId(sId, sAction, oData, typeof(oExtra.post_data) != 'undefined' ? oExtra.post_data : '', false, isConfirm);
  140. };
  141. BxDolGrid.prototype.setOnReload = function (fCallback) {
  142. this.onReload = typeof(fCallback) == 'function' ? fCallback : null;
  143. };
  144. BxDolGrid.prototype.actionWithId = function (sId, sAction, oData, sData, isDisableLoading, isConfirm) {
  145. var sDataAdd = 'ids[]=' + sId;
  146. if (typeof(sData) == "undefined" || !sData.length) {
  147. sData = sDataAdd;
  148. } else {
  149. if ('&' != sData[sData.length-1])
  150. sData += '&';
  151. sData += sDataAdd;
  152. }
  153. this.action(sAction, oData, sData, isDisableLoading, isConfirm);
  154. };
  155. BxDolGrid.prototype.actionWithSelected = function (sActionData, sAction, oData, sData, isDisableLoading, isConfirm) {
  156. var sDataAdd = '';
  157. jQuery("#" + this._sIdTable + " input[name=" + this._sObject + "_check]:checked").each(function () {
  158. if (sDataAdd.length)
  159. sDataAdd += "&";
  160. sDataAdd += 'ids[]=' + $(this).val();
  161. });
  162. if (!sDataAdd.length)
  163. return;
  164. if (typeof(sData) == "undefined" || !sData.length) {
  165. sData = sDataAdd;
  166. } else {
  167. if ('&' != sData[sData.length-1])
  168. sData += '&';
  169. sData += sDataAdd;
  170. }
  171. this.action(sAction, oData, sData, isDisableLoading, isConfirm);
  172. };
  173. BxDolGrid.prototype.action = function (sAction, oData, sData, isDisableLoading, isConfirm) {
  174. var $this = this;
  175. var fPerform = function() {
  176. var i;
  177. var sUrl = sUrlRoot + "grid.php?o=" + $this._sObject + "&a=" + sAction;
  178. if (typeof($this._oQueryAppend) == 'object')
  179. oData = $.extend({}, $this._oQueryAppend, oData);
  180. for (i in oData)
  181. sUrl += "&" + i + "=" + encodeURIComponent(oData[i]);
  182. if (typeof(sData) != 'undefined')
  183. sUrl += '&' + sData;
  184. if ($this._sFilter.length)
  185. sUrl += '&' + $this._oOptions.filter_get + '=' + encodeURIComponent ($this._sFilter);
  186. if ($this._sOrderField.length)
  187. sUrl += '&' + $this._oOptions.order_get_field + '=' + encodeURIComponent ($this._sOrderField);
  188. if ($this._sOrderDir.length)
  189. sUrl += '&' + $this._oOptions.order_get_dir + '=' + encodeURIComponent ($this._sOrderDir);
  190. if ($this._sCsrfToken.length)
  191. sUrl += '&csrf_token=' + encodeURIComponent ($this._sCsrfToken);
  192. sUrl += '&_r=' + Math.random();
  193. if (typeof(isDisableLoading) == 'undefined' || !isDisableLoading)
  194. $this.loading(true);
  195. if(sUrl.length < 2048)
  196. $.getJSON(sUrl, function(oResult) {
  197. $this.processJson(oResult, sAction, isDisableLoading);
  198. });
  199. else {
  200. var oUri = new URI(sUrl);
  201. oData = oUri.query(true);
  202. sUrl = oUri.query("").toString();
  203. $.post(sUrl, oData, function(oResult) {
  204. $this.processJson(oResult, sAction, isDisableLoading);
  205. }, 'json');
  206. }
  207. };
  208. if(typeof(isConfirm) != 'undefined' && parseInt(isConfirm) == 1)
  209. bx_confirm(typeof(this._oConfirmMessages[sAction]) == 'undefined' ? _t('_sys_grid_confirmation') : this._oConfirmMessages[sAction], function() {
  210. fPerform();
  211. });
  212. else
  213. fPerform();
  214. };
  215. BxDolGrid.prototype.processJson = function (oData, sAction, isDisableLoading) {
  216. var $this = this;
  217. var fContinue = function() {
  218. if (oData && undefined != oData.grid) {
  219. if (typeof($this.onReload) == 'function') {
  220. $this.onReload(oData);
  221. } else {
  222. $('#' + $this._sIdWrapper).find('.bx-grid-header-controls-counter-value').html(oData.total_count_f);
  223. switch(sAction) {
  224. case 'load_more':
  225. var sClassData = 'bx-grid-table-data';
  226. $('#' + $this._sIdContainer).find('.' + sClassData).append($(oData.grid).find('#' + $this._sIdContainer + ' .' + sClassData).html());
  227. break;
  228. default:
  229. $('#' + $this._sIdContainer).html($(oData.grid).find('#' + $this._sIdContainer).html());
  230. break;
  231. }
  232. var oFooter = $(oData.grid).find('.bx-grid-footer');
  233. $('#' + $this._sIdWrapper).find('.bx-grid-footer').html(oFooter.size() ? oFooter.html() : '');
  234. $this._onDataReloaded(true);
  235. }
  236. }
  237. if (oData && undefined != oData.blink) {
  238. if ('object' == typeof(oData.blink)) {
  239. for(var i in oData.blink)
  240. $this.blink($this._sObject + '_row_' + oData.blink[i]);
  241. } else {
  242. $this.blink($this._sObject + '_row_' + oData.blink);
  243. }
  244. }
  245. if (oData && undefined != oData.disable) {
  246. if ('object' == typeof(oData.disable)) {
  247. for(var i in oData.disable)
  248. $this.enable($this._sObject + '_row_' + oData.disable[i], false);
  249. } else {
  250. $this.enable($this._sObject + '_row_' + oData.disable, false);
  251. }
  252. }
  253. if (oData && undefined != oData.enable) {
  254. if ('object' == typeof(oData.enable)) {
  255. for(var i in oData.enable)
  256. $this.enable($this._sObject + '_row_' + oData.enable[i], true);
  257. } else {
  258. $this.enable($this._sObject + '_row_' + oData.enable, true);
  259. }
  260. }
  261. if (oData && undefined != oData.popup) {
  262. var sId = 'grid-popup-' + $this._sObject + '-' + sAction;
  263. $('#' + sId).remove();
  264. if ('object' == typeof(oData.popup)) {
  265. var o = $.extend({}, $this._oPopupOptions, oData.popup.options);
  266. $('<div id="' + sId + '" style="display: none;"></div>').prependTo('body').html(oData.popup.html);
  267. $('#' + sId).dolPopup(o);
  268. } else {
  269. $('<div id="' + sId + '" style="display: none;"></div>').prependTo('body').html(oData.popup);
  270. $('#' + sId).dolPopup($this._oPopupOptions);
  271. }
  272. }
  273. if (oData && oData.reload != undefined && parseInt(oData.reload) == 1) {
  274. document.location = document.location;
  275. }
  276. if (oData && oData.redirect != undefined && oData.redirect.length != 0) {
  277. document.location = oData.redirect;
  278. }
  279. if (oData && oData.open_url != undefined && oData.open_url.length != 0) {
  280. window.open(oData.open_url, '_blank');
  281. }
  282. if (oData && undefined != oData.eval) {
  283. eval(oData.eval);
  284. }
  285. if (oData && undefined != oData.secret) {
  286. $this.setSecretValue(oData.secret.id, oData.secret.field, oData.secret.value);
  287. }
  288. };
  289. if (typeof(isDisableLoading) == 'undefined' || !isDisableLoading)
  290. this.loading(false);
  291. if (oData && undefined != oData.msg) {
  292. bx_alert(oData.msg, function() {
  293. fContinue();
  294. });
  295. }
  296. else if (oData && undefined != oData.toast) {
  297. bx_toast(oData.toast);
  298. fContinue();
  299. }
  300. else
  301. fContinue();
  302. };
  303. BxDolGrid.prototype.loading = function (bShow) {
  304. if (!$('#' + this._sIdContainer).length)
  305. return;
  306. bx_loading(this._sIdContainer, bShow);
  307. };
  308. BxDolGrid.prototype.reload = function (iStart, iPerPage) {
  309. var oData = this._getActionDataForReload(iStart, iPerPage);
  310. this.action('display', oData);
  311. };
  312. BxDolGrid.prototype.loadMore = function (iStart, iPerPage) {
  313. var oData = this._getActionDataForReload(iStart, iPerPage);
  314. this.action('load_more', oData);
  315. };
  316. BxDolGrid.prototype._getActionDataForReload = function (iStart, iPerPage) {
  317. var oData = {};
  318. if (typeof(iStart) != 'undefined') {
  319. oData[this._oOptions.paginate_get_start] = iStart;
  320. this._oOptions.start = iStart;
  321. }
  322. else {
  323. oData[this._oOptions.paginate_get_start] = this._oOptions.start;
  324. }
  325. if (this._oOptions.paginate_get_per_page.length) {
  326. if (typeof(iPerPage) != 'undefined') {
  327. oData[this._oOptions.paginate_get_per_page] = iPerPage;
  328. this._oOptions.per_page = iPerPage;
  329. }
  330. else {
  331. oData[this._oOptions.paginate_get_per_page] = this._oOptions.per_page;
  332. }
  333. }
  334. return oData;
  335. };
  336. BxDolGrid.prototype._unbindActionsSingle = function (eElement) {
  337. var elements;
  338. if ('undefined' == typeof(eElement))
  339. elements = jQuery('#' + this._sIdWrapper + ' *[bx_grid_action_single]');
  340. else
  341. elements = eElement.find('*[bx_grid_action_single]');
  342. elements.unbind('click');
  343. };
  344. BxDolGrid.prototype._bindActionsSingle = function (eElement) {
  345. var $this = this;
  346. var elements;
  347. if ('undefined' == typeof(eElement))
  348. elements = jQuery('#' + this._sIdWrapper + ' *[bx_grid_action_single]');
  349. else
  350. elements = eElement.find('*[bx_grid_action_single]');
  351. elements.not('.bx-btn-disabled').bind('click', function () {
  352. if ($(this).hasClass('bx-btn-disabled'))
  353. return;
  354. var sAction = $(this).attr('bx_grid_action_single');
  355. var sActionConfirm = $(this).attr('bx_grid_action_confirm');
  356. var sActionData = $(this).attr('bx_grid_action_data');
  357. var iActionResetPaginate = parseInt($(this).attr('bx_grid_action_reset_paginate'));
  358. $this.actionSingle(sAction, sActionData, {
  359. confirm: sActionConfirm,
  360. reset_paginate: iActionResetPaginate,
  361. data: $this._checkAppend(this, {})
  362. });
  363. });
  364. };
  365. BxDolGrid.prototype._bindActions = function (isSkipSearchInput) {
  366. var $this = this;
  367. jQuery('#' + this._sIdContainer).bind('scroll', function () {
  368. if (-$(this).find('.bx-grid-table').position().left >= ($(this).find('.bx-grid-table').width() - $(this).width()))
  369. $(this).parents('.bx-grid-table-wrapper2').addClass('bx-grid-table-hide-shadow-after');
  370. else
  371. $(this).parents('.bx-grid-table-wrapper2').removeClass('bx-grid-table-hide-shadow-after');
  372. if ($(this).find('.bx-grid-table').position().left >= 0)
  373. $(this).parents('.bx-grid-table-wrapper2').addClass('bx-grid-table-hide-shadow-before');
  374. else
  375. $(this).parents('.bx-grid-table-wrapper2').removeClass('bx-grid-table-hide-shadow-before');
  376. });
  377. jQuery('#' + this._sIdWrapper + ' *[bx_grid_action_bulk]').bind('click', function () {
  378. if ($(this).hasClass('bx-btn-disabled'))
  379. return;
  380. var sAction = $(this).attr('bx_grid_action_bulk');
  381. var sActionConfirm = $(this).attr('bx_grid_action_confirm');
  382. var sActionData = $(this).attr('bx_grid_action_data');
  383. var iActionResetPaginate = parseInt($(this).attr('bx_grid_action_reset_paginate'));
  384. var oData = iActionResetPaginate ? {} : $this._getActionDataForReload();
  385. oData = $this._checkAppend(this, oData);
  386. $this.actionWithSelected (sActionData, sAction, oData, '', false, sActionConfirm);
  387. });
  388. this._bindActionsSingle ();
  389. jQuery('#' + this._sIdWrapper + ' .bx-grid-secret-toggle').bind('click', function () {
  390. var eWrap = $(this).closest('.bx-grid-secret');
  391. if (eWrap.hasClass('bx-grid-secret-shown')) {
  392. $this.hideSecret(eWrap);
  393. return;
  394. }
  395. $this.revealSecret($(this).attr('bx_grid_secret_id'), $(this).attr('bx_grid_secret_field'));
  396. });
  397. if (jQuery('#' + this._sIdWrapper + ' .bx-switcher-cont input').length)
  398. jQuery('#' + this._sIdWrapper).addWebForms();
  399. jQuery('#' + this._sIdWrapper + ' .bx-switcher-cont input').bind('change', function () {
  400. var sAction = $(this).attr('bx_grid_action_single');
  401. var sActionConfirm = $(this).attr('bx_grid_action_confirm');
  402. var sActionData = $(this).attr('bx_grid_action_data');
  403. var iActionResetPaginate = parseInt($(this).attr('bx_grid_action_reset_paginate'));
  404. var oData = iActionResetPaginate ? {} : $this._getActionDataForReload();
  405. $this.actionWithId (sActionData, sAction, $.extend({}, oData, {checked:this.checked ? 1 : 0}), '', false, sActionConfirm);
  406. });
  407. if (typeof(isSkipSearchInput) == 'undefined' || false == isSkipSearchInput) {
  408. jQuery('#' + this._sIdWrapper + ' *[bx_grid_action_independent]').bind('click', function () {
  409. if ($(this).hasClass('bx-btn-disabled'))
  410. return;
  411. var sAction = $(this).attr('bx_grid_action_independent');
  412. var sActionConfirm = $(this).attr('bx_grid_action_confirm');
  413. var iActionResetPaginate = parseInt($(this).attr('bx_grid_action_reset_paginate'));
  414. var oData = iActionResetPaginate ? {} : $this._getActionDataForReload();
  415. oData = $this._checkAppend(this, oData);
  416. $this.action (sAction, oData, '', false, sActionConfirm);
  417. });
  418. var callbackSearch = function (sTerm) {
  419. clearTimeout($this._iSearchTimeoutId);
  420. $this._iSearchTimeoutId = setTimeout(function () {
  421. if(glGrids[$this._sObject])
  422. glGrids[$this._sObject].setFilter(sTerm, true);
  423. }, 500);
  424. };
  425. jQuery('#bx-grid-search-' + this._sObject).bind({
  426. keyup: function (e) {
  427. callbackSearch(this.value);
  428. },
  429. focusout: function (e) {
  430. if (0 == this.value.length)
  431. this.value = $this._sSearchInputText;
  432. callbackSearch(this.value == $this._sSearchInputText ? '' : this.value);
  433. },
  434. focusin: function (e) {
  435. if (this.value == $this._sSearchInputText)
  436. this.value = '';
  437. }
  438. });
  439. }
  440. };
  441. BxDolGrid.prototype._onDataReloaded = function (isSkipSearchInput) {
  442. jQuery('#' + this._sIdTable + ' tbody tr:odd').addClass('bx-def-color-bg-hl');
  443. jQuery('#' + this._sIdTable).bxProcessHtml();
  444. if (this._oOptions.sorting)
  445. this.orderable();
  446. if (this._oOptions.sortable && 0 == this._sFilter.length && 0 == this._sOrderField.length)
  447. this.sortable();
  448. this._bindActions(isSkipSearchInput);
  449. this.onDataReloaded(isSkipSearchInput);
  450. };
  451. BxDolGrid.prototype.onDataReloaded = function (isSkipSearchInput) {};
  452. BxDolGrid.prototype._checkAppend = function (oInput, oData) {
  453. var oAppend = $(oInput).attr('bx_grid_action_append') ? $.parseJSON($(oInput).attr('bx_grid_action_append')) : false;
  454. if(typeof(oAppend) == 'object')
  455. oData = $.extend({}, oData, oAppend);
  456. return oData;
  457. };
  458. BxDolGrid.prototype.revealSecret = function (sId, sField) {
  459. var $this = this;
  460. var oInput = $('#bx-popup-prompt-value');
  461. $(document).dolPopupPrompt({
  462. message: _t('_sys_grid_secret_password_prompt'),
  463. value: '',
  464. onClickOk: function (oPopup) {
  465. var oData = {
  466. o: $this._sObject,
  467. a: 'reveal_secret',
  468. 'ids[]': sId,
  469. field: sField,
  470. password: oPopup.getValue(),
  471. csrf_token: $this._sCsrfToken,
  472. _r: Math.random()
  473. };
  474. if (typeof($this._oQueryAppend) == 'object')
  475. oData = $.extend({}, $this._oQueryAppend, oData);
  476. $this.loading(true);
  477. $.post(sUrlRoot + 'grid.php', oData, function (oResult) {
  478. $this.processJson(oResult, 'reveal_secret', false);
  479. }, 'json');
  480. },
  481. onShow: function () {
  482. oInput.attr('type', 'password').attr('autocomplete', 'current-password').val('').focus();
  483. },
  484. onHide: function () {
  485. oInput.attr('type', 'text').removeAttr('autocomplete').val('');
  486. }
  487. });
  488. };
  489. BxDolGrid.prototype.hideSecret = function (eWrap) {
  490. var sMasked = eWrap.find('.bx-grid-secret-value').attr('data-masked') || '';
  491. eWrap.removeClass('bx-grid-secret-shown');
  492. eWrap.find('.bx-grid-secret-value').text(sMasked);
  493. eWrap.find('.bx-grid-secret-toggle').attr('title', _t('_sys_grid_secret_reveal'));
  494. eWrap.find('.bx-grid-secret-toggle .sys-icon').removeClass('eye-slash').addClass('eye');
  495. };
  496. BxDolGrid.prototype.setSecretValue = function (sId, sField, sValue) {
  497. var eToggle = jQuery('#' + this._sIdWrapper + ' .bx-grid-secret-toggle').filter(function () {
  498. return $(this).attr('bx_grid_secret_id') == sId && $(this).attr('bx_grid_secret_field') == sField;
  499. });
  500. var eWrap = eToggle.closest('.bx-grid-secret');
  501. eWrap.addClass('bx-grid-secret-shown');
  502. eWrap.find('.bx-grid-secret-value').text(sValue);
  503. eToggle.attr('title', _t('_sys_grid_secret_hide'));
  504. eToggle.find('.sys-icon').removeClass('eye').addClass('eye-slash');
  505. };
  506. /** @} */