BxBaseGrid.php 24 KB

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