BxBaseGrid.php 23 KB

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