BxBaseGrid.php 24 KB

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