BxBaseGrid.php 24 KB

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