BxBaseStudioFormsForms.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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 BxBaseStudioFormsForms extends BxDolStudioFormsForms
  11. {
  12. protected $_sFilter;
  13. protected $sUrlViewDisplays;
  14. function __construct($aOptions, $oTemplate = false)
  15. {
  16. parent::__construct($aOptions, $oTemplate);
  17. $this->_aOptions['actions_single']['edit']['attr']['title'] = _t('_adm_form_btn_forms_edit');
  18. $this->_sFilter = '';
  19. if(($sFilter = $this->_getFilterValue()))
  20. $this->_sFilter = $sFilter;
  21. $this->sUrlViewDisplays = BX_DOL_URL_STUDIO . 'builder_forms.php?page=displays&module=%s&object=%s';
  22. }
  23. public function performActionEdit()
  24. {
  25. $sAction = 'edit';
  26. $aIds = bx_get('ids');
  27. if(!$aIds || !is_array($aIds)) {
  28. $iId = (int)bx_get('id');
  29. if(!$iId) {
  30. echoJson(array());
  31. exit;
  32. }
  33. $aIds = array($iId);
  34. }
  35. $iId = $aIds[0];
  36. $aFormData = array();
  37. $iFormData = $this->oDb->getForms(array('type' => 'by_id', 'value' => $iId), $aFormData);
  38. if($iFormData != 1 || empty($aFormData)){
  39. echoJson(array());
  40. exit;
  41. }
  42. bx_import('BxTemplStudioFormView');
  43. $aForm = array(
  44. 'form_attrs' => array(
  45. 'id' => 'adm-form-form-edit',
  46. 'action' => BX_DOL_URL_ROOT . bx_append_url_params('grid.php', [
  47. 'o' => $this->_sObject,
  48. 'a' => $sAction,
  49. $this->_aOptions['filter_get'] => $this->_sFilter
  50. ]),
  51. 'method' => BX_DOL_STUDIO_METHOD_DEFAULT
  52. ),
  53. 'params' => array (
  54. 'db' => array(
  55. 'table' => 'sys_objects_form',
  56. 'key' => 'id',
  57. 'uri' => '',
  58. 'uri_title' => '',
  59. 'submit_name' => 'do_submit'
  60. ),
  61. ),
  62. 'inputs' => array (
  63. 'id' => array(
  64. 'type' => 'hidden',
  65. 'name' => 'id',
  66. 'value' => $iId,
  67. 'db' => array (
  68. 'pass' => 'Int',
  69. ),
  70. ),
  71. 'title' => array(
  72. 'type' => 'text_translatable',
  73. 'name' => 'title',
  74. 'caption' => _t('_adm_form_txt_forms_title'),
  75. 'info' => _t('_adm_form_dsc_forms_title'),
  76. 'value' => $aFormData['title'],
  77. 'required' => '1',
  78. 'db' => array (
  79. 'pass' => 'Xss',
  80. ),
  81. 'checker' => array (
  82. 'func' => 'LengthTranslatable',
  83. 'params' => array(3,100, 'title'),
  84. 'error' => _t('_adm_form_err_forms_title'),
  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_forms_save'),
  94. ),
  95. array (
  96. 'type' => 'reset',
  97. 'name' => 'close',
  98. 'value' => _t('_adm_form_btn_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. $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_forms_edit'));
  114. echoJson($aRes);
  115. }
  116. else {
  117. $sContent = BxTemplStudioFunctions::getInstance()->popupBox('adm-form-forms-edit-popup', _t('_adm_form_txt_forms_edit_popup', _t($aFormData['title'])), $this->_oTemplate->parseHtmlByName('form_add_form.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. function getJsObject()
  127. {
  128. return 'oBxDolStudioFormsForms';
  129. }
  130. function getCode($isDisplayHeader = true)
  131. {
  132. return $this->_oTemplate->parseHtmlByName('forms_forms.html', array(
  133. 'content' => parent::getCode($isDisplayHeader),
  134. 'js_object' => $this->getJsObject(),
  135. 'grid_object' => $this->_sObject,
  136. 'params_divider' => $this->sParamsDivider
  137. ));
  138. }
  139. protected function _addJsCss()
  140. {
  141. parent::_addJsCss();
  142. $this->_oTemplate->addJs(array('jquery.form.min.js', 'forms_forms.js'));
  143. $oForm = new BxTemplStudioFormView(array());
  144. $oForm->addCssJs();
  145. }
  146. protected function _getCellModule($mixedValue, $sKey, $aField, $aRow)
  147. {
  148. $mixedValue = $this->_limitMaxLength($this->getModuleTitle($aRow['module']), $sKey, $aField, $aRow, $this->_isDisplayPopupOnTextOverflow);
  149. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  150. }
  151. protected function _getCellDisplays ($mixedValue, $sKey, $aField, $aRow)
  152. {
  153. $aDisplayes = array();
  154. $this->oDb->getDisplays(array('type' => 'by_object', 'value' => $aRow['object']), $aDisplayes, false);
  155. $sLink = sprintf($this->sUrlViewDisplays, $aRow['module'], $aRow['object']);
  156. $mixedValue = $this->_oTemplate->parseLink($sLink, _t('_adm_form_txt_forms_n_displays', count($aDisplayes)), array(
  157. 'title' => _t('_adm_form_txt_forms_manage_displays')
  158. ));
  159. return parent::_getCellDefault ($mixedValue, $sKey, $aField, $aRow);
  160. }
  161. protected function _getFilterControls ()
  162. {
  163. parent::_getFilterControls();
  164. $aCounter = [];
  165. $this->oDb->getForms(['type' => 'counter_by_modules'], $aCounter, false);
  166. $aModules = $this->getModules(false);
  167. foreach($aModules as $sKey => $sValue)
  168. $aModules[$sKey] = $aModules[$sKey] . " (" . ($aCounter[$sKey] ?? 0) . ")";
  169. return parent::_getFilterSelectOne('module', '', $aModules, '_adm_form_txt_all_modules') . $this->getSearchInput();
  170. }
  171. }
  172. /** @} */