1
0

BxBaseStudioFormsSearchForms.php 8.7 KB

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