BxBaseStudioFormsForms.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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 $sUrlViewDisplays;
  13. function __construct($aOptions, $oTemplate = false)
  14. {
  15. parent::__construct($aOptions, $oTemplate);
  16. $this->_aOptions['actions_single']['edit']['attr']['title'] = _t('_adm_form_btn_forms_edit');
  17. $this->sUrlViewDisplays = BX_DOL_URL_STUDIO . 'builder_forms.php?page=displays&module=%s&object=%s';
  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. $aFormData = array();
  33. $iFormData = $this->oDb->getForms(array('type' => 'by_id', 'value' => $iId), $aFormData);
  34. if($iFormData != 1 || empty($aFormData)){
  35. echoJson(array());
  36. exit;
  37. }
  38. bx_import('BxTemplStudioFormView');
  39. $aForm = array(
  40. 'form_attrs' => array(
  41. 'id' => 'adm-form-form-edit',
  42. 'action' => BX_DOL_URL_ROOT . 'grid.php?o=' . $this->_sObject . '&a=' . $sAction,
  43. 'method' => BX_DOL_STUDIO_METHOD_DEFAULT
  44. ),
  45. 'params' => array (
  46. 'db' => array(
  47. 'table' => 'sys_objects_form',
  48. 'key' => 'id',
  49. 'uri' => '',
  50. 'uri_title' => '',
  51. 'submit_name' => 'do_submit'
  52. ),
  53. ),
  54. 'inputs' => array (
  55. 'id' => array(
  56. 'type' => 'hidden',
  57. 'name' => 'id',
  58. 'value' => $iId,
  59. 'db' => array (
  60. 'pass' => 'Int',
  61. ),
  62. ),
  63. 'title' => array(
  64. 'type' => 'text_translatable',
  65. 'name' => 'title',
  66. 'caption' => _t('_adm_form_txt_forms_title'),
  67. 'info' => _t('_adm_form_dsc_forms_title'),
  68. 'value' => $aFormData['title'],
  69. 'required' => '1',
  70. 'db' => array (
  71. 'pass' => 'Xss',
  72. ),
  73. 'checker' => array (
  74. 'func' => 'LengthTranslatable',
  75. 'params' => array(3,100, 'title'),
  76. 'error' => _t('_adm_form_err_forms_title'),
  77. ),
  78. ),
  79. 'controls' => array(
  80. 'name' => 'controls',
  81. 'type' => 'input_set',
  82. array(
  83. 'type' => 'submit',
  84. 'name' => 'do_submit',
  85. 'value' => _t('_adm_form_btn_forms_save'),
  86. ),
  87. array (
  88. 'type' => 'reset',
  89. 'name' => 'close',
  90. 'value' => _t('_adm_form_btn_forms_cancel'),
  91. 'attrs' => array(
  92. 'onclick' => "$('.bx-popup-applied:visible').dolPopupHide()",
  93. 'class' => 'bx-def-margin-sec-left',
  94. ),
  95. )
  96. )
  97. )
  98. );
  99. $oForm = new BxTemplStudioFormView($aForm);
  100. $oForm->initChecker();
  101. if($oForm->isSubmittedAndValid()) {
  102. if($oForm->update($iId) !== false)
  103. $aRes = array('grid' => $this->getCode(false), 'blink' => $iId);
  104. else
  105. $aRes = array('msg' => _t('_adm_form_err_forms_edit'));
  106. echoJson($aRes);
  107. }
  108. else {
  109. $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(
  110. 'form_id' => $aForm['form_attrs']['id'],
  111. 'form' => $oForm->getCode(true),
  112. 'object' => $this->_sObject,
  113. 'action' => $sAction
  114. )));
  115. echoJson(array('popup' => array('html' => $sContent, 'options' => array('closeOnOuterClick' => false))));
  116. }
  117. }
  118. function getJsObject()
  119. {
  120. return 'oBxDolStudioFormsForms';
  121. }
  122. function getCode($isDisplayHeader = true)
  123. {
  124. return $this->_oTemplate->parseHtmlByName('forms_forms.html', array(
  125. 'content' => parent::getCode($isDisplayHeader),
  126. 'js_object' => $this->getJsObject(),
  127. 'grid_object' => $this->_sObject,
  128. 'params_divider' => $this->sParamsDivider
  129. ));
  130. }
  131. protected function _addJsCss()
  132. {
  133. parent::_addJsCss();
  134. $this->_oTemplate->addJs(array('jquery.form.min.js', 'forms_forms.js'));
  135. $oForm = new BxTemplStudioFormView(array());
  136. $oForm->addCssJs();
  137. }
  138. protected function _getCellModule($mixedValue, $sKey, $aField, $aRow)
  139. {
  140. $mixedValue = $this->_limitMaxLength($this->getModuleTitle($aRow['module']), $sKey, $aField, $aRow, $this->_isDisplayPopupOnTextOverflow);
  141. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  142. }
  143. protected function _getCellDisplays ($mixedValue, $sKey, $aField, $aRow)
  144. {
  145. $aDisplayes = array();
  146. $this->oDb->getDisplays(array('type' => 'by_object', 'value' => $aRow['object']), $aDisplayes, false);
  147. $sLink = sprintf($this->sUrlViewDisplays, $aRow['module'], $aRow['object']);
  148. $mixedValue = $this->_oTemplate->parseLink($sLink, _t('_adm_form_txt_forms_n_displays', count($aDisplayes)), array(
  149. 'title' => _t('_adm_form_txt_forms_manage_displays')
  150. ));
  151. return parent::_getCellDefault ($mixedValue, $sKey, $aField, $aRow);
  152. }
  153. protected function _getFilterControls ()
  154. {
  155. parent::_getFilterControls();
  156. $sContent = "";
  157. $sJsObject = $this->getJsObject();
  158. $oForm = new BxTemplStudioFormView(array());
  159. $aInputModules = array(
  160. 'type' => 'select',
  161. 'name' => 'module',
  162. 'attrs' => array(
  163. 'id' => 'bx-grid-module-' . $this->_sObject,
  164. 'onChange' => 'javascript:' . $this->getJsObject() . '.onChangeFilter()'
  165. ),
  166. 'value' => '',
  167. 'values' => $this->getModules(false)
  168. );
  169. $aCounter = array();
  170. $this->oDb->getForms(array('type' => 'counter_by_modules'), $aCounter, false);
  171. foreach($aInputModules['values'] as $sKey => $sValue)
  172. $aInputModules['values'][$sKey] = $aInputModules['values'][$sKey] . " (" . (isset($aCounter[$sKey]) ? $aCounter[$sKey] : "0") . ")";
  173. $aInputModules['values'] = array_merge(array('' => _t('_adm_form_txt_all_modules')), $aInputModules['values']);
  174. $sContent .= $oForm->genRow($aInputModules);
  175. $aInputSearch = array(
  176. 'type' => 'text',
  177. 'name' => 'keyword',
  178. 'attrs' => array(
  179. 'id' => 'bx-grid-search-' . $this->_sObject,
  180. 'onKeyup' => 'javascript:$(this).off(\'keyup focusout\'); ' . $sJsObject . '.onChangeFilter()',
  181. 'onBlur' => 'javascript:' . $sJsObject . '.onChangeFilter()',
  182. )
  183. );
  184. $sContent .= $oForm->genRow($aInputSearch);
  185. return $sContent;
  186. }
  187. }
  188. /** @} */