BxBaseGrid.php 24 KB

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