BxBaseGrid.php 24 KB

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