1
0

BxBaseStudioFormsSearchFields.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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 BxBaseStudioFormsSearchFormFields
  11. {
  12. public function __construct($aOptions, $oTemplate = false)
  13. {
  14. parent::__construct($aOptions, $oTemplate);
  15. $this->_aOptions['actions_single']['edit']['attr']['title'] = _t('_adm_form_btn_search_forms_fields_edit');
  16. $this->sUrlPage .= 'search_fields';
  17. }
  18. public function performActionEdit()
  19. {
  20. $sAction = 'edit';
  21. $aIds = bx_get('ids');
  22. if(!$aIds || !is_array($aIds)) {
  23. $iId = (int)bx_get('id');
  24. if(!$iId) {
  25. echoJson(array());
  26. exit;
  27. }
  28. $aIds = array($iId);
  29. }
  30. $iId = $aIds[0];
  31. $aField = array();
  32. $this->oDb->getSearchFields(array('type' => 'by_id', 'id' => (int)$iId), $aField, false);
  33. if(empty($aField) || !is_array($aField)) {
  34. echoJson(array());
  35. exit;
  36. }
  37. bx_import('BxTemplStudioFormView');
  38. $aForm = array(
  39. 'form_attrs' => array(
  40. 'id' => 'adm-form-search-field-edit',
  41. 'action' => bx_append_url_params(BX_DOL_URL_ROOT . 'grid.php', array(
  42. 'o' => $this->_sObject,
  43. 'a' => $sAction,
  44. 'module' => $this->sModule,
  45. 'form' => $this->sForm
  46. )),
  47. 'method' => BX_DOL_STUDIO_METHOD_DEFAULT
  48. ),
  49. 'params' => array (
  50. 'db' => array(
  51. 'table' => 'sys_search_extended_fields',
  52. 'key' => 'id',
  53. 'uri' => '',
  54. 'uri_title' => '',
  55. 'submit_name' => 'do_submit'
  56. ),
  57. ),
  58. 'inputs' => array (
  59. 'id' => array(
  60. 'type' => 'hidden',
  61. 'name' => 'id',
  62. 'value' => $iId,
  63. 'db' => array (
  64. 'pass' => 'Int',
  65. ),
  66. ),
  67. 'caption' => array(
  68. 'type' => 'text_translatable',
  69. 'name' => 'caption',
  70. 'caption' => _t('_adm_form_txt_search_forms_fields_caption'),
  71. 'value' => $aField['caption'],
  72. 'required' => '0',
  73. 'db' => array (
  74. 'pass' => 'Xss',
  75. ),
  76. ),
  77. 'info' => array(
  78. 'type' => 'text_translatable',
  79. 'name' => 'info',
  80. 'caption' => _t('_adm_form_txt_search_forms_fields_info'),
  81. 'value' => $aField['info'],
  82. 'required' => '0',
  83. 'db' => array (
  84. 'pass' => 'Xss',
  85. ),
  86. ),
  87. 'controls' => array(
  88. 'name' => 'controls',
  89. 'type' => 'input_set',
  90. array(
  91. 'type' => 'submit',
  92. 'name' => 'do_submit',
  93. 'value' => _t('_adm_form_btn_search_forms_save'),
  94. ),
  95. array (
  96. 'type' => 'reset',
  97. 'name' => 'close',
  98. 'value' => _t('_adm_form_btn_search_forms_cancel'),
  99. 'attrs' => array(
  100. 'onclick' => "$('.bx-popup-applied:visible').dolPopupHide()",
  101. 'class' => 'bx-def-margin-sec-left',
  102. ),
  103. )
  104. )
  105. )
  106. );
  107. $aSearchTypes = BxDolSearchExtended::$TYPE_TO_TYPE_SEARCH[$aField['type']];
  108. if(is_array($aSearchTypes) && count($aSearchTypes) >= 2) {
  109. $aForm['inputs'] = bx_array_insert_before(array(
  110. 'search_type' => array(
  111. 'type' => 'select',
  112. 'name' => 'search_type',
  113. 'caption' => _t('_adm_form_txt_search_forms_fields_search_type'),
  114. 'info' => _t('_adm_form_dsc_search_forms_fields_search_type'),
  115. 'values' => array(),
  116. 'value' => $aField['search_type'],
  117. 'required' => '1',
  118. 'db' => array (
  119. 'pass' => 'Xss',
  120. ),
  121. 'checker' => array (
  122. 'func' => 'Avail',
  123. 'params' => array(),
  124. 'error' => _t('_adm_form_err_search_forms_essential'),
  125. ),
  126. )), $aForm['inputs'], 'controls');
  127. foreach($aSearchTypes as $sType)
  128. $aForm['inputs']['search_type']['values'][] = array('key' => $sType, 'value' => _t('_adm_form_txt_field_type_' . $sType));
  129. }
  130. $oForm = new BxTemplStudioFormView($aForm);
  131. $oForm->initChecker();
  132. if($oForm->isSubmittedAndValid()) {
  133. if($oForm->update($iId) !== false)
  134. $aRes = array('grid' => $this->getCode(false), 'blink' => $iId);
  135. else
  136. $aRes = array('msg' => _t('_adm_form_err_search_forms_fields_edit'));
  137. echoJson($aRes);
  138. }
  139. else {
  140. $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(
  141. 'form_id' => $aForm['form_attrs']['id'],
  142. 'form' => $oForm->getCode(true),
  143. 'object' => $this->_sObject,
  144. 'action' => $sAction
  145. )));
  146. echoJson(array('popup' => array('html' => $sContent, 'options' => array('closeOnOuterClick' => false))));
  147. }
  148. }
  149. public function performActionReset()
  150. {
  151. $mixedResult = BxDolSearchExtended::getObjectInstance($this->sForm)->resetFields();
  152. if($mixedResult === false)
  153. return echoJson(array('msg' => _t('_adm_from_err_search_forms_fields_reset')));
  154. echoJson(array('grid' => $this->getCode(false)));
  155. }
  156. protected function _addJsCss()
  157. {
  158. parent::_addJsCss();
  159. $this->_oTemplate->addJs(['forms_search_fields.js']);
  160. }
  161. protected function _getCellType ($mixedValue, $sKey, $aField, $aRow)
  162. {
  163. $mixedValue = $this->_oTemplate->getIcon('ui-' . $aRow['type'] . '.png', array('alt' => _t('_adm_form_txt_field_type_' . $aRow['type'])));
  164. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  165. }
  166. protected function _getCellSearchType ($mixedValue, $sKey, $aField, $aRow)
  167. {
  168. $mixedValue = $this->_oTemplate->getIcon('ui-' . $aRow['search_type'] . '.png', array('alt' => _t('_adm_form_txt_field_type_' . $aRow['search_type'])));
  169. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  170. }
  171. }
  172. /** @} */