1
0

BxBaseStudioFormsSearchFields.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  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. 'caption' => array(
  69. 'type' => 'text_translatable',
  70. 'name' => 'caption',
  71. 'caption' => _t('_adm_form_txt_search_forms_fields_caption'),
  72. 'value' => $aField['caption'],
  73. 'required' => '0',
  74. 'db' => array (
  75. 'pass' => 'Xss',
  76. ),
  77. ),
  78. 'info' => array(
  79. 'type' => 'text_translatable',
  80. 'name' => 'info',
  81. 'caption' => _t('_adm_form_txt_search_forms_fields_info'),
  82. 'value' => $aField['info'],
  83. 'required' => '0',
  84. 'db' => array (
  85. 'pass' => 'Xss',
  86. ),
  87. ),
  88. 'controls' => array(
  89. 'name' => 'controls',
  90. 'type' => 'input_set',
  91. array(
  92. 'type' => 'submit',
  93. 'name' => 'do_submit',
  94. 'value' => _t('_adm_form_btn_search_forms_save'),
  95. ),
  96. array (
  97. 'type' => 'reset',
  98. 'name' => 'close',
  99. 'value' => _t('_adm_form_btn_search_forms_cancel'),
  100. 'attrs' => array(
  101. 'onclick' => "$('.bx-popup-applied:visible').dolPopupHide()",
  102. 'class' => 'bx-def-margin-sec-left',
  103. ),
  104. )
  105. )
  106. )
  107. );
  108. $aSearchTypes = BxDolSearchExtended::$TYPE_TO_TYPE_SEARCH[$aField['type']];
  109. if(is_array($aSearchTypes) && count($aSearchTypes) >= 2) {
  110. $aForm['inputs'] = bx_array_insert_before(array(
  111. 'search_type' => array(
  112. 'type' => 'select',
  113. 'name' => 'search_type',
  114. 'caption' => _t('_adm_form_txt_search_forms_fields_search_type'),
  115. 'info' => _t('_adm_form_dsc_search_forms_fields_search_type'),
  116. 'values' => array(),
  117. 'value' => $aField['search_type'],
  118. 'required' => '1',
  119. 'db' => array (
  120. 'pass' => 'Xss',
  121. ),
  122. 'checker' => array (
  123. 'func' => 'Avail',
  124. 'params' => array(),
  125. 'error' => _t('_adm_form_err_search_forms_essential'),
  126. ),
  127. )), $aForm['inputs'], 'controls');
  128. foreach($aSearchTypes as $sType)
  129. $aForm['inputs']['search_type']['values'][] = array('key' => $sType, 'value' => _t('_adm_form_txt_field_type_' . $sType));
  130. }
  131. $oForm = new BxTemplStudioFormView($aForm);
  132. $oForm->initChecker();
  133. if($oForm->isSubmittedAndValid()) {
  134. if($oForm->update($iId) !== false)
  135. $aRes = array('grid' => $this->getCode(false), 'blink' => $iId);
  136. else
  137. $aRes = array('msg' => _t('_adm_form_err_search_forms_fields_edit'));
  138. echoJson($aRes);
  139. }
  140. else {
  141. $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(
  142. 'form_id' => $aForm['form_attrs']['id'],
  143. 'form' => $oForm->getCode(true),
  144. 'object' => $this->_sObject,
  145. 'action' => $sAction
  146. )));
  147. echoJson(array('popup' => array('html' => $sContent, 'options' => array('closeOnOuterClick' => false))));
  148. }
  149. }
  150. public function performActionReset()
  151. {
  152. $mixedResult = BxDolSearchExtended::getObjectInstance($this->sForm)->resetFields();
  153. if($mixedResult === false)
  154. return echoJson(array('msg' => _t('_adm_from_err_search_forms_fields_reset')));
  155. echoJson(array('grid' => $this->getCode(false)));
  156. }
  157. function getJsObject()
  158. {
  159. return 'oBxDolStudioFormsSearchFields';
  160. }
  161. function getFormsSelector($sModule = '')
  162. {
  163. $oForm = new BxTemplStudioFormView(array());
  164. $aInputForms = array(
  165. 'type' => 'select',
  166. 'name' => 'form',
  167. 'attrs' => array(
  168. 'id' => 'bx-grid-form-' . $this->_sObject,
  169. 'onChange' => 'javascript:' . $this->getJsObject() . '.onChangeForm()'
  170. ),
  171. 'value' => $this->sForm,
  172. 'values' => array(
  173. '' => _t('_adm_form_txt_search_forms_fields_select_object'),
  174. )
  175. );
  176. if(!empty($sModule)) {
  177. $aForms = array();
  178. $this->oDb->getSearchForms(array('type' => 'by_module', 'module' => $sModule), $aForms, false);
  179. foreach($aForms as $aForm)
  180. $aInputForms['values'][] = array(
  181. 'key' => $aForm['object'],
  182. 'value' => _t($aForm['title'])
  183. );
  184. }
  185. else
  186. $aInputForms['attrs']['disabled'] = 'disabled';
  187. return $oForm->genRow($aInputForms);
  188. }
  189. function getCode($isDisplayHeader = true)
  190. {
  191. return $this->_oTemplate->parseHtmlByName('forms_search_fields.html', array(
  192. 'content' => parent::getCode($isDisplayHeader),
  193. 'js_object' => $this->getJsObject(),
  194. 'page_url' => $this->sUrlPage,
  195. 'grid_object' => $this->_sObject,
  196. 'params_divider' => $this->sParamsDivider
  197. ));
  198. }
  199. protected function _addJsCss()
  200. {
  201. parent::_addJsCss();
  202. $this->_oTemplate->addCss(array('menu.css'));
  203. $this->_oTemplate->addJs(array('jquery.form.min.js', 'forms_search_fields.js'));
  204. $oForm = new BxTemplStudioFormView(array());
  205. $oForm->addCssJs();
  206. }
  207. protected function _getCellSwitcher ($mixedValue, $sKey, $aField, $aRow)
  208. {
  209. if(!$this->_isEditable($aRow))
  210. return parent::_getCellDefault('', $sKey, $aField, $aRow);
  211. return parent::_getCellSwitcher($mixedValue, $sKey, $aField, $aRow);
  212. }
  213. protected function _getCellType ($mixedValue, $sKey, $aField, $aRow)
  214. {
  215. $mixedValue = $this->_oTemplate->getIcon('ui-' . $aRow['type'] . '.png', array('alt' => _t('_adm_form_txt_field_type_' . $aRow['type'])));
  216. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  217. }
  218. protected function _getCellSearchType ($mixedValue, $sKey, $aField, $aRow)
  219. {
  220. $mixedValue = $this->_oTemplate->getIcon('ui-' . $aRow['search_type'] . '.png', array('alt' => _t('_adm_form_txt_field_type_' . $aRow['search_type'])));
  221. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  222. }
  223. protected function _getActionReset ($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
  224. {
  225. if(!$this->_isResetable($aRow))
  226. return '';
  227. if($this->sForm == '')
  228. $isDisabled = true;
  229. return parent::_getActionDefault($sType, $sKey, $a, false, $isDisabled, $aRow);
  230. }
  231. protected function _getFilterControls ()
  232. {
  233. parent::_getFilterControls();
  234. $sContent = $this->getModulesSelectOne('getSearchForms') . $this->getFormsSelector($this->sModule);
  235. $oForm = new BxTemplStudioFormView(array());
  236. $aInputSearch = array(
  237. 'type' => 'text',
  238. 'name' => 'keyword',
  239. 'attrs' => array(
  240. 'id' => 'bx-grid-search-' . $this->_sObject,
  241. ),
  242. 'tr_attrs' => array(
  243. 'style' => empty($this->sModule) || empty($this->sForm) ? 'display:none;' : ''
  244. )
  245. );
  246. $sContent .= $oForm->genRow($aInputSearch);
  247. return $sContent;
  248. }
  249. protected function _isEditable(&$aRow)
  250. {
  251. return true;
  252. }
  253. protected function _isResetable(&$aRow)
  254. {
  255. return true;
  256. }
  257. }
  258. /** @} */