BxBaseStudioFormsSearchForms.php 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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 BxBaseStudioFormsSearchForms extends BxDolStudioFormsSearchForms
  11. {
  12. protected $_sFilter;
  13. protected $sUrlViewFields;
  14. protected $sUrlViewSortableFields;
  15. public function __construct($aOptions, $oTemplate = false)
  16. {
  17. parent::__construct($aOptions, $oTemplate);
  18. $this->_aOptions['actions_single']['edit']['attr']['title'] = _t('_adm_form_btn_search_forms_edit');
  19. $this->_sFilter = '';
  20. if(($sFilter = $this->_getFilterValue()))
  21. $this->_sFilter = $sFilter;
  22. $this->sUrlViewFields = BX_DOL_URL_STUDIO . 'builder_forms.php?page=search_fields&module=%s&form=%s';
  23. $this->sUrlViewSortableFields = BX_DOL_URL_STUDIO . 'builder_forms.php?page=search_sortable_fields&module=%s&form=%s';
  24. }
  25. public function performActionEdit()
  26. {
  27. $sAction = 'edit';
  28. $aIds = bx_get('ids');
  29. if(!$aIds || !is_array($aIds)) {
  30. $iId = (int)bx_get('id');
  31. if(!$iId) {
  32. echoJson(array());
  33. exit;
  34. }
  35. $aIds = array($iId);
  36. }
  37. $iId = $aIds[0];
  38. $aFormData = array();
  39. $iFormData = $this->oDb->getSearchForms(array('type' => 'by_id', 'id' => $iId), $aFormData);
  40. if($iFormData != 1 || empty($aFormData)){
  41. echoJson(array());
  42. exit;
  43. }
  44. bx_import('BxTemplStudioFormView');
  45. $aForm = array(
  46. 'form_attrs' => array(
  47. 'id' => 'adm-form-search-form-edit',
  48. 'action' => BX_DOL_URL_ROOT . bx_append_url_params('grid.php', [
  49. 'o' => $this->_sObject,
  50. 'a' => $sAction,
  51. $this->_aOptions['filter_get'] => $this->_sFilter
  52. ]),
  53. 'method' => BX_DOL_STUDIO_METHOD_DEFAULT
  54. ),
  55. 'params' => array (
  56. 'db' => array(
  57. 'table' => 'sys_objects_search_extended',
  58. 'key' => 'id',
  59. 'uri' => '',
  60. 'uri_title' => '',
  61. 'submit_name' => 'do_submit'
  62. ),
  63. ),
  64. 'inputs' => array (
  65. 'id' => array(
  66. 'type' => 'hidden',
  67. 'name' => 'id',
  68. 'value' => $iId,
  69. 'db' => array (
  70. 'pass' => 'Int',
  71. ),
  72. ),
  73. 'title' => array(
  74. 'type' => 'text_translatable',
  75. 'name' => 'title',
  76. 'caption' => _t('_adm_form_txt_search_forms_title'),
  77. 'info' => _t('_adm_form_dsc_search_forms_title'),
  78. 'value' => $aFormData['title'],
  79. 'required' => '1',
  80. 'db' => array (
  81. 'pass' => 'Xss',
  82. ),
  83. 'checker' => array (
  84. 'func' => 'LengthTranslatable',
  85. 'params' => array(3,100, 'title'),
  86. 'error' => _t('_adm_form_err_search_forms_title'),
  87. ),
  88. ),
  89. 'controls' => array(
  90. 'name' => 'controls',
  91. 'type' => 'input_set',
  92. array(
  93. 'type' => 'submit',
  94. 'name' => 'do_submit',
  95. 'value' => _t('_adm_form_btn_search_forms_save'),
  96. ),
  97. array (
  98. 'type' => 'reset',
  99. 'name' => 'close',
  100. 'value' => _t('_adm_form_btn_search_forms_cancel'),
  101. 'attrs' => array(
  102. 'onclick' => "$('.bx-popup-applied:visible').dolPopupHide()",
  103. 'class' => 'bx-def-margin-sec-left',
  104. ),
  105. )
  106. )
  107. )
  108. );
  109. $oForm = new BxTemplStudioFormView($aForm);
  110. $oForm->initChecker();
  111. if($oForm->isSubmittedAndValid()) {
  112. if($oForm->update($iId) !== false)
  113. $aRes = array('grid' => $this->getCode(false), 'blink' => $iId);
  114. else
  115. $aRes = array('msg' => _t('_adm_form_err_search_forms_edit'));
  116. echoJson($aRes);
  117. }
  118. else {
  119. $sContent = BxTemplStudioFunctions::getInstance()->popupBox('adm-form-search-forms-edit-popup', _t('_adm_form_txt_search_forms_edit_popup', _t($aFormData['title'])), $this->_oTemplate->parseHtmlByName('form_add_search_form.html', array(
  120. 'form_id' => $aForm['form_attrs']['id'],
  121. 'form' => $oForm->getCode(true),
  122. 'object' => $this->_sObject,
  123. 'action' => $sAction
  124. )));
  125. echoJson(array('popup' => array('html' => $sContent, 'options' => array('closeOnOuterClick' => false))));
  126. }
  127. }
  128. function getJsObject()
  129. {
  130. return 'oBxDolStudioFormsSearchForms';
  131. }
  132. function getCode($isDisplayHeader = true)
  133. {
  134. return $this->_oTemplate->parseHtmlByName('forms_search_forms.html', array(
  135. 'content' => parent::getCode($isDisplayHeader),
  136. 'js_object' => $this->getJsObject(),
  137. 'grid_object' => $this->_sObject,
  138. 'params_divider' => $this->sParamsDivider
  139. ));
  140. }
  141. protected function _addJsCss()
  142. {
  143. parent::_addJsCss();
  144. $this->_oTemplate->addJs(array('jquery.form.min.js', 'forms_search_forms.js'));
  145. $oForm = new BxTemplStudioFormView(array());
  146. $oForm->addCssJs();
  147. }
  148. protected function _getCellModule($mixedValue, $sKey, $aField, $aRow)
  149. {
  150. $mixedValue = $this->_limitMaxLength($this->getModuleTitle($aRow['module']), $sKey, $aField, $aRow, $this->_isDisplayPopupOnTextOverflow);
  151. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  152. }
  153. protected function _getCellFields ($mixedValue, $sKey, $aField, $aRow)
  154. {
  155. $aFields = array();
  156. $this->oDb->getSearchFields(array('type' => 'by_object', 'object' => $aRow['object']), $aFields, false);
  157. $sLink = sprintf($this->sUrlViewFields, $aRow['module'], $aRow['object']);
  158. $mixedValue = $this->_oTemplate->parseLink($sLink, _t('_adm_form_txt_search_forms_n_fields', count($aFields)), array(
  159. 'title' => _t('_adm_form_txt_search_forms_manage_fields')
  160. ));
  161. return parent::_getCellDefault ($mixedValue, $sKey, $aField, $aRow);
  162. }
  163. protected function _getCellSortableFields ($mixedValue, $sKey, $aField, $aRow)
  164. {
  165. $aFields = array();
  166. $this->oDb->getSortableFields(array('type' => 'by_object', 'object' => $aRow['object']), $aFields, false);
  167. $sLink = sprintf($this->sUrlViewSortableFields, $aRow['module'], $aRow['object']);
  168. $mixedValue = $this->_oTemplate->parseLink($sLink, _t('_adm_form_txt_search_forms_n_fields', count($aFields)), array(
  169. 'title' => _t('_adm_form_txt_search_forms_manage_fields')
  170. ));
  171. return parent::_getCellDefault ($mixedValue, $sKey, $aField, $aRow);
  172. }
  173. protected function _getFilterControls ()
  174. {
  175. parent::_getFilterControls();
  176. $sContent = "";
  177. $sJsObject = $this->getJsObject();
  178. $oForm = new BxTemplStudioFormView(array());
  179. $aInputModules = array(
  180. 'type' => 'select',
  181. 'name' => 'module',
  182. 'attrs' => array(
  183. 'id' => 'bx-grid-module-' . $this->_sObject,
  184. 'aria-label' => _t('_adm_grid_lbl_module'),
  185. 'onChange' => 'javascript:' . $this->getJsObject() . '.onChangeFilter()'
  186. ),
  187. 'value' => '',
  188. 'values' => $this->getModules(false)
  189. );
  190. $aCounter = array();
  191. $this->oDb->getSearchForms(array('type' => 'counter_by_modules'), $aCounter, false);
  192. foreach($aInputModules['values'] as $sKey => $sValue){
  193. if (isset($aCounter[$sKey]) && $aCounter[$sKey] > 0)
  194. $aInputModules['values'][$sKey] = $aInputModules['values'][$sKey] . " (" . (isset($aCounter[$sKey]) ? $aCounter[$sKey] : "0") . ")";
  195. else
  196. unset($aInputModules['values'][$sKey]);
  197. }
  198. $aInputModules['values'] = array_merge(array('' => _t('_adm_form_txt_all_modules')), $aInputModules['values']);
  199. $sContent .= $oForm->genRow($aInputModules);
  200. $aInputSearch = array(
  201. 'type' => 'text',
  202. 'name' => 'keyword',
  203. 'attrs' => array(
  204. 'id' => 'bx-grid-search-' . $this->_sObject,
  205. 'aria-label' => _t('_adm_grid_lbl_search'),
  206. 'onKeyup' => 'javascript:$(this).off(\'keyup focusout\'); ' . $sJsObject . '.onChangeFilter()',
  207. 'onBlur' => 'javascript:' . $sJsObject . '.onChangeFilter()',
  208. )
  209. );
  210. $sContent .= $oForm->genRow($aInputSearch);
  211. return $sContent;
  212. }
  213. }
  214. /** @} */