BxBaseGrid.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
  4. * CC-BY License - http://creativecommons.org/licenses/by/3.0/
  5. *
  6. * @defgroup TridentCore Trident Core
  7. * @{
  8. */
  9. /**
  10. * Grid representation.
  11. * @see BxDolGrid
  12. */
  13. class BxBaseGrid extends BxDolGrid
  14. {
  15. protected $_oTemplate;
  16. protected $_aPopupOptions = false;
  17. protected $_aQueryAppend = false;
  18. protected $_aConfirmMessages = false;
  19. protected $_bSelectAll = false;
  20. protected $_isDisplayPopupOnTextOverflow = true;
  21. public function __construct ($aOptions, $oTemplate)
  22. {
  23. parent::__construct ($aOptions);
  24. if ($oTemplate)
  25. $this->_oTemplate = $oTemplate;
  26. else
  27. $this->_oTemplate = BxDolTemplate::getInstance();
  28. }
  29. public function performActionDisplay()
  30. {
  31. require_once(BX_DIRECTORY_PATH_INC . "design.inc.php");
  32. echoJson(array('grid' => $this->getCode(false)));
  33. }
  34. public function performActionReorder()
  35. {
  36. $this->_replaceMarkers ();
  37. $aOrder = bx_get($this->_sObject . '_row');
  38. $iOrder = 0;
  39. foreach ($aOrder as $mixedId)
  40. $this->_updateOrder($mixedId, ++$iOrder);
  41. echoJson(array());
  42. }
  43. public function performActionDelete()
  44. {
  45. $this->_replaceMarkers ();
  46. $iAffected = 0;
  47. $aIds = bx_get('ids');
  48. if (!$aIds || !is_array($aIds)) {
  49. echoJson(array());
  50. exit;
  51. }
  52. foreach ($aIds as $mixedId)
  53. $iAffected += $this->_delete($mixedId) ? 1 : 0;
  54. echo echoJson(array_merge(
  55. array(
  56. 'grid' => $this->getCode(false),
  57. ),
  58. $iAffected ? array() : array('msg' => _t("_sys_grid_delete_failed"))
  59. ));
  60. }
  61. public function performActionEnable()
  62. {
  63. $this->_replaceMarkers ();
  64. $aIds = bx_get('ids');
  65. if (!$aIds || !is_array($aIds)) {
  66. echoJson(array());
  67. exit;
  68. }
  69. $aAffectedIds = array ();
  70. foreach ($aIds as $mixedId)
  71. if ($this->_enable($mixedId, (int)bx_get('checked')))
  72. $aAffectedIds[] = $mixedId;
  73. $sAction = (int)bx_get('checked') ? 'enable' : 'disable';
  74. echo echoJson(array($sAction => $aAffectedIds));
  75. }
  76. public function getCode ($isDisplayHeader = true)
  77. {
  78. $this->_replaceMarkers ();
  79. if ($isDisplayHeader && empty($this->_aOptions['paginate_url'])) {
  80. // reset page query params if grid is just initialized and it uses AJAX paginate
  81. $this->resetQueryParams();
  82. }
  83. $sPaginate = '';
  84. $aData = array();
  85. $sIdWrapper = 'bx-grid-wrap-' . $this->_sObject;
  86. $sIdContainer = 'bx-grid-cont-' . $this->_sObject;
  87. $sIdTable = 'bx-grid-table-' . $this->_sObject;
  88. $sFilter = bx_unicode_urldecode(bx_process_input(bx_get('filter')));
  89. $sOrderField = bx_unicode_urldecode(bx_process_input(bx_get('order_field')));
  90. $sOrderDir = 0 === strcasecmp('desc', bx_get('order_dir')) ? 'DESC' : 'ASC';
  91. if ($this->_aOptions['paginate_get_start'])
  92. $iStart = (int)bx_get($this->_aOptions['paginate_get_start']);
  93. else
  94. $iStart = 0;
  95. if ($this->_aOptions['paginate_get_per_page'] && (int)bx_get($this->_aOptions['paginate_get_per_page']) > 0)
  96. $iPerPage = (int)bx_get($this->_aOptions['paginate_get_per_page']);
  97. elseif ($this->_aOptions['paginate_per_page'])
  98. $iPerPage = (int)$this->_aOptions['paginate_per_page'];
  99. else
  100. $iPerPage = 10;
  101. if ($this->_aOptions['paginate_get_start']) {
  102. $aData = $this->_getData ($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage + 1);
  103. $sPageUrl = false;
  104. if (!empty($this->_aOptions['paginate_url'])) {
  105. $sPageUrl = $this->_aOptions['paginate_url'];
  106. $aParamsAppend = array();
  107. if ($sFilter) {
  108. $aParamsAppend['filter'] = bx_process_input(bx_get('filter'));
  109. }
  110. if ($sOrderField) {
  111. $aParamsAppend['order_field'] = bx_process_input(bx_get('order_field'));
  112. $aParamsAppend['order_dir'] = bx_process_input(bx_get('order_dir'));
  113. }
  114. if ($aParamsAppend)
  115. $sPageUrl = bx_append_url_params($sPageUrl, $aParamsAppend);
  116. }
  117. $aPaginateParams = array(
  118. 'start' => $iStart,
  119. 'per_page' => $iPerPage,
  120. 'page_url' => $sPageUrl ? $sPageUrl : "javascript:glGrids." . $this->_sObject . ".reload('{start}'); void(0);",
  121. );
  122. $oPaginate = new BxTemplPaginate($aPaginateParams, $this->_oTemplate);
  123. $oPaginate->setNumFromDataArray($aData);
  124. if (isset($this->_aOptions['paginate_simple']) && false !== $this->_aOptions['paginate_simple'])
  125. $sPaginate = $oPaginate->getSimplePaginate($this->_aOptions['paginate_simple']);
  126. else
  127. $sPaginate = $oPaginate->getPaginate();
  128. } else {
  129. $aData = $this->_getData ($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage);
  130. }
  131. $sPopupOptions = '{}';
  132. if (!empty($this->_aPopupOptions) && is_array($this->_aPopupOptions))
  133. $sPopupOptions = json_encode($this->_aPopupOptions);
  134. $aQueryAppend = array_merge(is_array($this->_aQueryAppend) ? $this->_aQueryAppend : array(), is_array($this->_aMarkers) ? $this->_aMarkers : array());
  135. $sQueryAppend = '{}';
  136. if (!empty($aQueryAppend) && is_array($aQueryAppend))
  137. $sQueryAppend = json_encode($aQueryAppend);
  138. $sConfirmMessages = '{}';
  139. if (!empty($this->_aConfirmMessages) && is_array($this->_aConfirmMessages))
  140. $sConfirmMessages = json_encode($this->_aConfirmMessages);
  141. $iColumns = count($this->_aOptions['fields']);
  142. $aVarsHead = $this->_getRowHead();
  143. $aVars = array (
  144. 'object' => $this->_sObject,
  145. 'id_table' => $sIdTable,
  146. 'id_cont' => $sIdContainer,
  147. 'id_wrap' => $sIdWrapper,
  148. 'sortable' => empty($this->_aOptions['field_order']) ? 0 : 1,
  149. 'sorting' => empty($this->_aOptions['sorting_fields']) ? 0 : 1,
  150. 'sorting_field' => $sOrderField,
  151. 'sorting_dir' => $sOrderDir,
  152. 'bx_if:display_head' => array(
  153. 'condition' => !empty($aVarsHead),
  154. 'content' => array(
  155. 'bx_repeat:row_header' => $aVarsHead,
  156. 'columns' => $iColumns,
  157. )
  158. ),
  159. 'bx_repeat:rows_data' => $this->_getRowsDataDesign ($aData),
  160. 'paginate_get_start' => $this->_aOptions['paginate_get_start'],
  161. 'paginate_get_per_page' => $this->_aOptions['paginate_get_per_page'],
  162. 'start' => $iStart,
  163. 'per_page' => $iPerPage,
  164. 'filter' => bx_js_string($sFilter, BX_ESCAPE_STR_APOS),
  165. 'order_field' => bx_js_string($sOrderField, BX_ESCAPE_STR_APOS),
  166. 'order_dir' => bx_js_string($sOrderDir, BX_ESCAPE_STR_APOS),
  167. 'popup_options' => $sPopupOptions,
  168. 'query_append' => $sQueryAppend,
  169. 'confirm_messages' => $sConfirmMessages,
  170. 'columns' => $iColumns,
  171. 'bx_if:display_footer' => array(
  172. 'condition' => !empty($this->_aOptions['actions_bulk']) || !empty($sPaginate),
  173. 'content' => array(
  174. 'bx_if:actions_bulk' => array (
  175. 'condition' => !empty($this->_aOptions['actions_bulk']),
  176. 'content' => array(
  177. 'actions_bulk' => $this->_getActions ('bulk'),
  178. ),
  179. ),
  180. 'paginate' => $sPaginate,
  181. )
  182. ),
  183. 'bx_if:display_header' => array (
  184. 'condition' => $isDisplayHeader,
  185. 'content' => array (
  186. 'bx_if:actions_independent' => array (
  187. 'condition' => !empty($this->_aOptions['actions_independent']),
  188. 'content' => array(
  189. 'actions_independent' => $this->_getActions ('independent'),
  190. ),
  191. ),
  192. 'bx_if:filter' => array (
  193. 'condition' => !empty($this->_aOptions['filter_fields']) || !empty($this->_aOptions['filter_fields_translatable']),
  194. 'content' => array(
  195. 'controls' => $this->_getFilterControls(),
  196. ),
  197. ),
  198. ),
  199. ),
  200. );
  201. $this->_addJsCss();
  202. return $this->_oTemplate->parseHtmlByName('grid.html', $aVars);
  203. }
  204. /**
  205. * Reset query params, like filter and page number
  206. */
  207. public function resetQueryParams()
  208. {
  209. $aKeys = array('filter', 'order_field', 'order_dir', $this->_aOptions['paginate_get_start'], $this->_aOptions['paginate_get_per_page']);
  210. foreach ($aKeys as $sKey) {
  211. unset($_GET[$sKey]);
  212. unset($_POST[$sKey]);
  213. }
  214. }
  215. protected function _getRowHead ()
  216. {
  217. $aRet = array();
  218. foreach ($this->_aOptions['fields'] as $sKey => $a) {
  219. $sMethod = '_getCellHeaderDefault';
  220. $sCustomMethod = '_getCellHeader' . $this->_genMethodName($sKey);
  221. if (method_exists($this, $sCustomMethod))
  222. $sMethod = $sCustomMethod;
  223. $aRet[] = array('header_cell' => $this->$sMethod($sKey, $a));
  224. }
  225. return $aRet;
  226. }
  227. protected function _getCellHeaderDefault ($sKey, $aField)
  228. {
  229. $sHeader = bx_process_output($aField['title']);
  230. if (!empty($this->_aOptions['sorting_fields']) && is_array($this->_aOptions['sorting_fields']) && in_array($sKey, $this->_aOptions['sorting_fields'])) {
  231. $sHeader = '<a href="javascript:void(0);" class="bx-grid-sort-handle">' . $sHeader . '</a><span class="bx-grid-sort-indi"></span>';
  232. $aField['attr_head']['bx_grid_sort_head'] = $sKey;
  233. }
  234. $sAttr = $this->_convertAttrs(
  235. $aField, 'attr_head',
  236. 'bx-def-padding-sec-bottom bx-def-padding-sec-top bx-grid-header-' . $sKey, // add default classes
  237. isset($aField['width']) ? 'width:' . $aField['width'] : false // add default styles
  238. );
  239. return $this->_getCellHeaderWrapper ($sKey, $aField, $sHeader, $sAttr);
  240. }
  241. protected function _getCellHeaderCheckbox ($sKey, $aField)
  242. {
  243. $aAttr = array(
  244. 'type' => 'checkbox',
  245. 'id' => $this->_sObject . '_check_all',
  246. 'name' => $this->_sObject . '_check_all',
  247. 'onclick' => "$('input[name=" . $this->_sObject . "_check]:not([disabled])').attr('checked', this.checked)"
  248. );
  249. if($this->_bSelectAll)
  250. $aAttr['checked'] = 'checked';
  251. $aField['attr'] = isset($aField['attr']) && is_array($aField['attr']) ? array_merge($aAttr, $aField['attr']) : $aAttr;
  252. $sAttrHead = $this->_convertAttrs(
  253. $aField, 'attr_head',
  254. 'bx-def-padding-sec-bottom bx-def-padding-sec-top bx-grid-header-' . $sKey, // add default classes
  255. isset($aField['width']) ? 'width:' . $aField['width'] : false // add default styles
  256. );
  257. return $this->_getCellHeaderWrapper ($sKey, $aField, ' <input ' . $this->_convertAttrs($aField, 'attr') . ' /> ', $sAttrHead);
  258. }
  259. protected function _getCellHeaderWrapper ($sKey, $aField, $sHeader, $sAttr)
  260. {
  261. return '<th ' . $sAttr . '>' . $sHeader . '</th>';
  262. }
  263. /**
  264. * Check if the whole row is disabled.
  265. * When row is disabled - checkbox is not selectable, actions aren't clickable and text is grayed out.
  266. * By default all rows aren't disabled.
  267. * @param $aRow row array
  268. * @return boolean
  269. */
  270. protected function _isRowDisabled($aRow)
  271. {
  272. if (isset($aRow[$this->_aOptions['field_active']]) && !$this->_switcherState2Checked($aRow[$this->_aOptions['field_active']]))
  273. return true;
  274. return false;
  275. }
  276. /**
  277. * Determine how actions are disabled when whole row is disabled.
  278. * @param $aRow row array
  279. * @return null - disable/enable actions when row is disabled/enabled, true - actions are always disabled, false - actions are always enabled
  280. */
  281. protected function _getActionsDisabledBehavior($aRow)
  282. {
  283. return null;
  284. }
  285. /**
  286. * Check if the checkbox is disabled.
  287. * @param $aRow row array
  288. * @return boolean
  289. */
  290. protected function _isCheckboxDisabled($aRow)
  291. {
  292. return $this->_isRowDisabled($aRow);
  293. }
  294. /**
  295. * Is checkbox checked by default ?
  296. * By default no one checkbox is selected.
  297. * @return boolean
  298. */
  299. protected function _isCheckboxSelected($mixedValue, $sKey, $aField, $aRow)
  300. {
  301. return $this->_bSelectAll;
  302. }
  303. /**
  304. * Is switcher on by default ?
  305. * By default no one switcher is on.
  306. * @return boolean
  307. */
  308. protected function _isSwitcherOn($mixedValue, $sKey, $aField, $aRow)
  309. {
  310. return $this->_switcherState2Checked($mixedValue);
  311. }
  312. /**
  313. * Convert switcher checked status to the actual value ?
  314. * @return boolean
  315. */
  316. protected function _switcherChecked2State($isChecked)
  317. {
  318. return $isChecked ? 1 : 0;
  319. }
  320. /**
  321. * Convert switcher value to checked(boolean) value ?
  322. * @return boolean
  323. */
  324. protected function _switcherState2Checked($mixedState)
  325. {
  326. return $mixedState ? true : false;
  327. }
  328. protected function _getRowsDataDesign (&$aData)
  329. {
  330. $aGrid = array();
  331. if (empty($aData)) {
  332. $aGrid[] = array(
  333. 'row' => '<td class="bx-def-padding-sec-bottom bx-def-padding-sec-top" colspan="' . count($this->_aOptions['fields']) . '">' . _t('_Empty') . '</td>',
  334. 'id_row' => 0,
  335. 'row_class' => 'bx-grid-table-row-empty',
  336. );
  337. } else {
  338. foreach ($aData as $aRow) {
  339. $sRow = '';
  340. foreach ($this->_aOptions['fields'] as $sKey => $aField)
  341. $sRow .= $this->_getCellDesign($sKey, $aField, $aRow);
  342. $aGrid[] = array(
  343. 'row' => $sRow,
  344. 'id_row' => $this->_sObject . '_row_' . $aRow[$this->_aOptions['field_id']],
  345. 'row_class' => $this->_isRowDisabled($aRow) ? 'bx-grid-table-row-disabled bx-def-font-grayed' : '',
  346. );
  347. }
  348. }
  349. return $aGrid;
  350. }
  351. protected function _getCellDesign($sKey, $aField, $aRow)
  352. {
  353. $sMethod = '_getCellDefault';
  354. if ($this->_aOptions['field_order'] == $sKey)
  355. $sMethod = '_getCellOrder';
  356. $sCustomMethod = '_getCell' . $this->_genMethodName($sKey);
  357. if (method_exists($this, $sCustomMethod))
  358. $sMethod = $sCustomMethod;
  359. $mixedValue = $this->_getCellData($sKey, $aField, $aRow);
  360. if ($aField['translatable'])
  361. $mixedValue = _t($mixedValue);
  362. $mixedValue = $this->_limitMaxLength($mixedValue, $sKey, $aField, $aRow, $this->_isDisplayPopupOnTextOverflow);
  363. return $this->$sMethod($mixedValue, $sKey, $aField, $aRow);
  364. }
  365. protected function _getCellCheckbox ($mixedValue, $sKey, $aField, $aRow)
  366. {
  367. $sAttr = $this->_convertAttrs(
  368. $aField, 'attr_cell',
  369. 'bx-def-padding-sec-bottom bx-def-padding-sec-top', // add default classes
  370. isset($aField['width']) ? 'width:' . $aField['width'] : false // add default styles
  371. );
  372. $sDisabled = ($this->_isCheckboxDisabled($aRow) ? 'disabled="disabled"' : '');
  373. $sSelected = ($this->_isCheckboxSelected($mixedValue, $sKey, $aField, $aRow) ? 'checked="checked"' : '');
  374. $sVal = $aRow[$this->_aOptions['field_id']];
  375. return '<td ' . $sAttr . '><input type="checkbox" name="'. $this->_sObject . '_check" value="' . $sVal . '" ' . $sDisabled . ' ' . $sSelected . '/></td>';
  376. }
  377. protected function _getCellSwitcher ($mixedValue, $sKey, $aField, $aRow)
  378. {
  379. $sAttr = $this->_convertAttrs(
  380. $aField, 'attr_cell',
  381. 'bx-def-padding-sec-bottom bx-def-padding-sec-top', // add default classes
  382. isset($aField['width']) ? 'width:' . $aField['width'] : false // add default styles
  383. );
  384. $oForm = new BxTemplFormView(array(), $this->_oTemplate);
  385. $oForm->addCssJs();
  386. $aInput = array(
  387. 'type' => 'switcher',
  388. 'name' => $this->_sObject . '_switch_' . $aRow[$this->_aOptions['field_id']],
  389. 'caption' => '',
  390. 'attrs' => array (
  391. 'bx_grid_action_single' => 'enable',
  392. 'bx_grid_action_confirm' => '',
  393. 'bx_grid_action_data' => $aRow[$this->_aOptions['field_id']],
  394. ),
  395. 'value' => $aRow[$this->_aOptions['field_id']],
  396. 'checked' => $this->_isSwitcherOn(isset($aRow[$this->_aOptions['field_active']]) ? $aRow[$this->_aOptions['field_active']] : false, $sKey, $aField, $aRow),
  397. );
  398. $sSwitcher = $oForm->genInput($aInput);
  399. return '<td ' . $sAttr . '>' . $sSwitcher . '</td>';
  400. }
  401. protected function _getCellOrder ($mixedValue, $sKey, $aField, $aRow)
  402. {
  403. $sAttr = $this->_convertAttrs(
  404. $aField, 'attr_cell',
  405. 'bx-def-padding-sec-bottom bx-def-padding-sec-top', // add default classes
  406. isset($aField['width']) ? 'width:' . $aField['width'] : false // add default styles
  407. );
  408. return '<td ' . $sAttr . '><div id="' . $this->_sObject . '_cell_' . $aRow[$this->_aOptions['field_id']] . '" class="bx-grid-drag-handle"><i class="sys-icon align-justify"></i></div></td>';
  409. }
  410. protected function _getCellActions ($mixedValue, $sKey, $aField, $aRow)
  411. {
  412. $sAttr = $this->_convertAttrs(
  413. $aField, 'attr_cell',
  414. 'bx-def-padding-sec-bottom bx-def-padding-sec-top', // add default classes
  415. isset($aField['width']) ? 'width:' . $aField['width'] : false // add default styles
  416. );
  417. $mixedDisabledBehavior = $this->_getActionsDisabledBehavior($aRow);
  418. $sActions = $this->_getActions('single', $aRow[$this->_aOptions['field_id']], false, null === $mixedDisabledBehavior ? $this->_isRowDisabled($aRow) : $mixedDisabledBehavior, null !== $mixedDisabledBehavior, $aRow);
  419. return '<td ' . $sAttr . '><div class="bx-grid-cell-single-actions-wrapper bx-def-margin-thd-neg">' . $sActions . '</div></td>';
  420. }
  421. protected function _getCellDefault ($mixedValue, $sKey, $aField, $aRow)
  422. {
  423. $sAttr = $this->_convertAttrs(
  424. $aField, 'attr_cell',
  425. 'bx-def-padding-sec-bottom bx-def-padding-sec-top', // add default classes
  426. isset($aField['width']) ? 'width:' . $aField['width'] : false // add default styles
  427. );
  428. return '<td ' . $sAttr . '>' . $mixedValue . '</td>';
  429. }
  430. protected function _getActions ($sType, $sActionData = false, $isSmall = false, $isDisabled = false, $isPermanentState = false, $aRow = array())
  431. {
  432. $sActionsType = 'actions_' . $sType;
  433. if (empty($this->_aOptions[$sActionsType]) || !is_array($this->_aOptions[$sActionsType]))
  434. return '';
  435. $sRet = '';
  436. foreach ($this->_aOptions[$sActionsType] as $sKey => $a) {
  437. $sFunc = '_getAction' . $this->_genMethodName($sKey);
  438. if (!method_exists($this, $sFunc))
  439. $sFunc = empty($a) ? '_getActionDivider' : '_getActionDefault';
  440. if (!isset($a['attr']['bx_grid_action'])) {
  441. $a['attr']['bx_grid_action_' . $sType] = $sKey;
  442. if (!empty($sActionData))
  443. $a['attr']['bx_grid_action_data'] = $sActionData;
  444. if (isset($a['confirm']))
  445. $a['attr']['bx_grid_action_confirm'] = $a['confirm'] ? 1 : 0;
  446. $a['attr']['bx_grid_action_reset_paginate'] = false === strpos($sKey, 'delete') ? 0 : 1; // reset paginate after deleting row
  447. }
  448. if ($isPermanentState && !isset($a['attr']['bx_grid_permanent_state']))
  449. $a['attr']['bx_grid_permanent_state'] = 1;
  450. $sRet .= $this->$sFunc($sType, $sKey, $a, $isSmall, $isDisabled, $aRow);
  451. }
  452. return $sRet;
  453. }
  454. protected function _getActionDefault ($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
  455. {
  456. if ($a['icon_only'] && empty($a['attr']['title']) && !empty($a['title']))
  457. $a['attr']['title'] = $a['title'];
  458. $sAttr = $this->_convertAttrs(
  459. $a, 'attr',
  460. 'bx-btn bx-def-margin-thd' . ($isSmall ? ' bx-btn-small' : '') . ($isDisabled ? ' bx-btn-disabled' : '') // add default classes
  461. );
  462. $sIcon = '';
  463. $sImage = '';
  464. if (!empty($a['icon'])) {
  465. if (false === strpos($a['icon'], '.'))
  466. $sIcon = '<i class="sys-icon ' . $a['icon'] . '"></i>';
  467. elseif ($sIconUrl = $this->_oTemplate->getIconUrl($a['icon']))
  468. $sImage = '<i style="background-image:url(' . $sIconUrl . ');"></i>';
  469. }
  470. return '<button ' . $sAttr . '>' . $sIcon . $sImage . ($a['icon_only'] ? '' : $a['title']) . '</button>';
  471. }
  472. protected function _getActionDivider ($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
  473. {
  474. return '<div class="bx-grid-actions-divider bx-def-margin-sec-left"> | </div>';
  475. }
  476. protected function _getFilterControls ()
  477. {
  478. $oForm = new BxTemplStudioFormView(array());
  479. $aInput = array(
  480. 'type' => 'text',
  481. 'name' => 'keyword',
  482. 'attrs' => array(
  483. 'id' => 'bx-grid-search-' . $this->_sObject
  484. )
  485. );
  486. $this->_oTemplate->addCss('forms.css');
  487. return $oForm->genRow($aInput);
  488. }
  489. protected function _limitMaxLength ($mixedValue, $sKey, $aField, $aRow, $isDisplayPopupOnTextOverflow, $bReturnString = true)
  490. {
  491. if ($aField['chars_limit'] > 0)
  492. $mixedValue = BxTemplFunctions::getInstance()->getStringWithLimitedLength($mixedValue, $aField['chars_limit'], $isDisplayPopupOnTextOverflow, $bReturnString);
  493. return $mixedValue;
  494. }
  495. protected function _convertAttrs ($aField, $sAttrName, $sClasses = false, $sStyles = false)
  496. {
  497. return bx_convert_array2attrs(
  498. isset($aField[$sAttrName]) && is_array($aField[$sAttrName]) ? $aField[$sAttrName] : array(),
  499. $sClasses,
  500. $sStyles
  501. );
  502. }
  503. protected function _updateOrder($mixedId, $iOrder)
  504. {
  505. $oDb = BxDolDb::getInstance();
  506. $sTable = $this->_aOptions['table'];
  507. $sFieldId = $this->_aOptions['field_id'];
  508. $sFieldOrder = $this->_aOptions['field_order'];
  509. $sQuery = $oDb->prepare("UPDATE `{$sTable}` SET `{$sFieldOrder}` = ? WHERE `{$sFieldId}` = ?", $iOrder, $mixedId);
  510. return $oDb->query($sQuery);
  511. }
  512. protected function _delete ($mixedId)
  513. {
  514. $oDb = BxDolDb::getInstance();
  515. $sTable = $this->_aOptions['table'];
  516. $sFieldId = $this->_aOptions['field_id'];
  517. $sQuery = $oDb->prepare("DELETE FROM `{$sTable}` WHERE `{$sFieldId}` = ?", $mixedId);
  518. return $oDb->query($sQuery);
  519. }
  520. protected function _enable ($mixedId, $isChecked)
  521. {
  522. $oDb = BxDolDb::getInstance();
  523. $sTable = $this->_aOptions['table'];
  524. $sFieldId = $this->_aOptions['field_id'];
  525. $sFieldActive = $this->_aOptions['field_active'];
  526. $sQuery = $oDb->prepare("UPDATE `{$sTable}` SET `$sFieldActive` = ? WHERE `{$sFieldId}` = ?", $this->_switcherChecked2State($isChecked), $mixedId);
  527. return $oDb->query($sQuery);
  528. }
  529. protected function _addJsCss()
  530. {
  531. if ($this->_aOptions['field_order']) {
  532. $this->_oTemplate->addJs(array(
  533. 'jquery-ui/jquery.ui.core.min.js',
  534. 'jquery-ui/jquery.ui.widget.min.js',
  535. 'jquery-ui/jquery.ui.mouse.min.js',
  536. 'jquery-ui/jquery.ui.sortable.min.js',
  537. ));
  538. }
  539. $this->_oTemplate->addJs('BxDolGrid.js');
  540. $this->_oTemplate->addCss('grid.css');
  541. $this->_oTemplate->addJsTranslation('_sys_grid_confirmation');
  542. }
  543. }
  544. /** @} */