1
0

BxBaseStudioFormsSearchFields.php 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup UnaView UNA Studio Representation classes
  7. * @ingroup UnaStudio
  8. * @{
  9. */
  10. class BxBaseStudioFormsSearchFields extends BxDolStudioFormsSearchFields
  11. {
  12. protected $sUrlPage;
  13. function __construct($aOptions, $oTemplate = false)
  14. {
  15. parent::__construct($aOptions, $oTemplate);
  16. $this->_aOptions['actions_single']['edit']['attr']['title'] = _t('_adm_form_btn_search_forms_fields_edit');
  17. $this->sUrlPage = BX_DOL_URL_STUDIO . 'builder_forms.php?page=search_fields';
  18. }
  19. public function performActionEdit()
  20. {
  21. $sAction = 'edit';
  22. $aIds = bx_get('ids');
  23. if(!$aIds || !is_array($aIds)) {
  24. $iId = (int)bx_get('id');
  25. if(!$iId) {
  26. echoJson(array());
  27. exit;
  28. }
  29. $aIds = array($iId);
  30. }
  31. $iId = $aIds[0];
  32. $aField = array();
  33. $this->oDb->getSearchFields(array('type' => 'by_id', 'id' => (int)$iId), $aField, false);
  34. if(empty($aField) || !is_array($aField)) {
  35. echoJson(array());
  36. exit;
  37. }
  38. bx_import('BxTemplStudioFormView');
  39. $aForm = array(
  40. 'form_attrs' => array(
  41. 'id' => 'adm-form-search-field-edit',
  42. 'action' => bx_append_url_params(BX_DOL_URL_ROOT . 'grid.php', array(
  43. 'o' => $this->_sObject,
  44. 'a' => $sAction,
  45. 'module' => $this->sModule,
  46. 'form' => $this->sForm
  47. )),
  48. 'method' => BX_DOL_STUDIO_METHOD_DEFAULT
  49. ),
  50. 'params' => array (
  51. 'db' => array(
  52. 'table' => 'sys_search_extended_fields',
  53. 'key' => 'id',
  54. 'uri' => '',
  55. 'uri_title' => '',
  56. 'submit_name' => 'do_submit'
  57. ),
  58. ),
  59. 'inputs' => array (
  60. 'id' => array(
  61. 'type' => 'hidden',
  62. 'name' => 'id',
  63. 'value' => $iId,
  64. 'db' => array (
  65. 'pass' => 'Int',
  66. ),
  67. ),
  68. 'search_type' => array(
  69. 'type' => 'select',
  70. 'name' => 'search_type',
  71. 'caption' => _t('_adm_form_txt_search_forms_fields_search_type'),
  72. 'info' => _t('_adm_form_dsc_search_forms_fields_search_type'),
  73. 'values' => array(),
  74. 'value' => $aField['search_type'],
  75. 'required' => '1',
  76. 'db' => array (
  77. 'pass' => 'Xss',
  78. ),
  79. 'checker' => array (
  80. 'func' => 'Avail',
  81. 'params' => array(),
  82. 'error' => _t('_adm_form_err_search_forms_essential'),
  83. ),
  84. ),
  85. 'controls' => array(
  86. 'name' => 'controls',
  87. 'type' => 'input_set',
  88. array(
  89. 'type' => 'submit',
  90. 'name' => 'do_submit',
  91. 'value' => _t('_adm_form_btn_search_forms_save'),
  92. ),
  93. array (
  94. 'type' => 'reset',
  95. 'name' => 'close',
  96. 'value' => _t('_adm_form_btn_search_forms_cancel'),
  97. 'attrs' => array(
  98. 'onclick' => "$('.bx-popup-applied:visible').dolPopupHide()",
  99. 'class' => 'bx-def-margin-sec-left',
  100. ),
  101. )
  102. )
  103. )
  104. );
  105. foreach(BxDolSearchExtended::$TYPE_TO_TYPE_SEARCH[$aField['type']] as $sType)
  106. $aForm['inputs']['search_type']['values'][] = array('key' => $sType, 'value' => _t('_adm_form_txt_field_type_' . $sType));
  107. $oForm = new BxTemplStudioFormView($aForm);
  108. $oForm->initChecker();
  109. if($oForm->isSubmittedAndValid()) {
  110. if($oForm->update($iId) !== false)
  111. $aRes = array('grid' => $this->getCode(false), 'blink' => $iId);
  112. else
  113. $aRes = array('msg' => _t('_adm_form_err_search_forms_fields_edit'));
  114. echoJson($aRes);
  115. }
  116. else {
  117. $sContent = BxTemplStudioFunctions::getInstance()->popupBox('adm-form-search-forms-fields-edit-popup', _t('_adm_form_txt_search_forms_fields_edit_popup', _t($aField['caption'])), $this->_oTemplate->parseHtmlByName('form_add_search_field.html', array(
  118. 'form_id' => $aForm['form_attrs']['id'],
  119. 'form' => $oForm->getCode(true),
  120. 'object' => $this->_sObject,
  121. 'action' => $sAction
  122. )));
  123. echoJson(array('popup' => array('html' => $sContent, 'options' => array('closeOnOuterClick' => false))));
  124. }
  125. }
  126. public function performActionReset()
  127. {
  128. $mixedResult = BxDolSearchExtended::getObjectInstance($this->sForm)->reset();
  129. if($mixedResult === false)
  130. return echoJson(array('msg' => _t('_adm_from_err_search_forms_fields_reset')));
  131. echoJson(array('grid' => $this->getCode(false)));
  132. }
  133. function getJsObject()
  134. {
  135. return 'oBxDolStudioFormsSearchFields';
  136. }
  137. function getFormsSelector($sModule = '')
  138. {
  139. $oForm = new BxTemplStudioFormView(array());
  140. $aInputForms = array(
  141. 'type' => 'select',
  142. 'name' => 'form',
  143. 'attrs' => array(
  144. 'id' => 'bx-grid-form-' . $this->_sObject,
  145. 'onChange' => 'javascript:' . $this->getJsObject() . '.onChangeForm()'
  146. ),
  147. 'value' => $this->sForm,
  148. 'values' => array(
  149. '' => _t('_adm_form_txt_search_forms_fields_select_object'),
  150. )
  151. );
  152. if(!empty($sModule)) {
  153. $aForms = array();
  154. $this->oDb->getSearchForms(array('type' => 'by_module', 'module' => $sModule), $aForms, false);
  155. foreach($aForms as $aForm)
  156. $aInputForms['values'][] = array(
  157. 'key' => $aForm['object'],
  158. 'value' => _t($aForm['title'])
  159. );
  160. }
  161. else
  162. $aInputForms['attrs']['disabled'] = 'disabled';
  163. return $oForm->genRow($aInputForms);
  164. }
  165. function getCode($isDisplayHeader = true)
  166. {
  167. return $this->_oTemplate->parseHtmlByName('forms_search_fields.html', array(
  168. 'content' => parent::getCode($isDisplayHeader),
  169. 'js_object' => $this->getJsObject(),
  170. 'page_url' => $this->sUrlPage,
  171. 'grid_object' => $this->_sObject,
  172. 'params_divider' => $this->sParamsDivider
  173. ));
  174. }
  175. protected function _addJsCss()
  176. {
  177. parent::_addJsCss();
  178. $this->_oTemplate->addCss(array('menu.css'));
  179. $this->_oTemplate->addJs(array('jquery.form.min.js', 'forms_search_fields.js'));
  180. $oForm = new BxTemplStudioFormView(array());
  181. $oForm->addCssJs();
  182. }
  183. protected function _getCellSwitcher ($mixedValue, $sKey, $aField, $aRow)
  184. {
  185. if(!$this->_isEditable($aRow))
  186. return parent::_getCellDefault('', $sKey, $aField, $aRow);
  187. return parent::_getCellSwitcher($mixedValue, $sKey, $aField, $aRow);
  188. }
  189. protected function _getCellType ($mixedValue, $sKey, $aField, $aRow)
  190. {
  191. $mixedValue = $this->_oTemplate->getIcon('ui-' . $aRow['type'] . '.png', array('alt' => _t('_adm_form_txt_field_type_' . $aRow['type'])));
  192. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  193. }
  194. protected function _getCellSearchType ($mixedValue, $sKey, $aField, $aRow)
  195. {
  196. $mixedValue = $this->_oTemplate->getIcon('ui-' . $aRow['search_type'] . '.png', array('alt' => _t('_adm_form_txt_field_type_' . $aRow['search_type'])));
  197. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  198. }
  199. protected function _getActionEdit ($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
  200. {
  201. if($sType == 'single' && !$this->_isEditable($aRow))
  202. return '';
  203. $aSearchTypes = BxDolSearchExtended::$TYPE_TO_TYPE_SEARCH[$aRow['type']];
  204. if(!is_array($aSearchTypes) || count($aSearchTypes) < 2)
  205. return '';
  206. return parent::_getActionDefault($sType, $sKey, $a, false, $isDisabled, $aRow);
  207. }
  208. protected function _getActionReset ($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
  209. {
  210. if(!$this->_isResetable($aRow))
  211. return '';
  212. if($this->sForm == '')
  213. $isDisabled = true;
  214. return parent::_getActionDefault($sType, $sKey, $a, false, $isDisabled, $aRow);
  215. }
  216. protected function _getFilterControls ()
  217. {
  218. parent::_getFilterControls();
  219. $sContent = $this->getModulesSelectOne('getSearchForms') . $this->getFormsSelector($this->sModule);
  220. $oForm = new BxTemplStudioFormView(array());
  221. $aInputSearch = array(
  222. 'type' => 'text',
  223. 'name' => 'keyword',
  224. 'attrs' => array(
  225. 'id' => 'bx-grid-search-' . $this->_sObject,
  226. ),
  227. 'tr_attrs' => array(
  228. 'style' => empty($this->sModule) || empty($this->sForm) ? 'display:none;' : ''
  229. )
  230. );
  231. $sContent .= $oForm->genRow($aInputSearch);
  232. return $sContent;
  233. }
  234. protected function _isEditable(&$aRow)
  235. {
  236. return true;
  237. }
  238. protected function _isResetable(&$aRow)
  239. {
  240. return true;
  241. }
  242. }
  243. /** @} */