BxBaseStudioFormsDisplays.php 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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 BxBaseStudioFormsDisplays extends BxDolStudioFormsDisplays
  11. {
  12. protected $sUrlPage;
  13. protected $sUrlViewFields;
  14. function __construct($aOptions, $oTemplate = false)
  15. {
  16. parent::__construct($aOptions, $oTemplate);
  17. $this->_aOptions['actions_single']['edit']['attr']['title'] = _t('_adm_form_btn_displays_edit');
  18. $this->sUrlPage = BX_DOL_URL_STUDIO . 'builder_forms.php?page=displays';
  19. $this->sUrlViewFields = BX_DOL_URL_STUDIO . 'builder_forms.php?page=fields&module=%s&object=%s&display=%s';
  20. }
  21. public function performActionEdit()
  22. {
  23. $sAction = 'edit';
  24. $aIds = bx_get('ids');
  25. if(!$aIds || !is_array($aIds)) {
  26. $iId = (int)bx_get('id');
  27. if(!$iId) {
  28. echoJson(array());
  29. exit;
  30. }
  31. $aIds = array($iId);
  32. }
  33. $iId = $aIds[0];
  34. $aDisplay = array();
  35. $iDisplay = $this->oDb->getDisplays(array('type' => 'by_id', 'value' => $iId), $aDisplay);
  36. if($iDisplay != 1 || empty($aDisplay)){
  37. echoJson(array());
  38. exit;
  39. }
  40. bx_import('BxTemplStudioFormView');
  41. $aForm = array(
  42. 'form_attrs' => array(
  43. 'id' => 'adm-form-display-edit',
  44. 'action' => BX_DOL_URL_ROOT . 'grid.php?o=' . $this->_sObject . '&a=' . $sAction . '&object=' . $this->sObject,
  45. 'method' => BX_DOL_STUDIO_METHOD_DEFAULT
  46. ),
  47. 'params' => array (
  48. 'db' => array(
  49. 'table' => 'sys_form_displays',
  50. 'key' => 'id',
  51. 'uri' => '',
  52. 'uri_title' => '',
  53. 'submit_name' => 'do_submit'
  54. ),
  55. ),
  56. 'inputs' => array (
  57. 'id' => array(
  58. 'type' => 'hidden',
  59. 'name' => 'id',
  60. 'value' => $iId,
  61. 'db' => array (
  62. 'pass' => 'Int',
  63. ),
  64. ),
  65. 'title' => array(
  66. 'type' => 'text_translatable',
  67. 'name' => 'title',
  68. 'caption' => _t('_adm_form_txt_displays_title'),
  69. 'info' => _t('_adm_form_dsc_displays_title'),
  70. 'value' => $aDisplay['title'],
  71. 'required' => '1',
  72. 'db' => array (
  73. 'pass' => 'Xss',
  74. ),
  75. 'checker' => array (
  76. 'func' => 'LengthTranslatable',
  77. 'params' => array(3,100, 'title'),
  78. 'error' => _t('_adm_form_err_displays_title'),
  79. ),
  80. ),
  81. 'controls' => array(
  82. 'name' => 'controls',
  83. 'type' => 'input_set',
  84. array(
  85. 'type' => 'submit',
  86. 'name' => 'do_submit',
  87. 'value' => _t('_adm_form_btn_displays_save'),
  88. ),
  89. array (
  90. 'type' => 'reset',
  91. 'name' => 'close',
  92. 'value' => _t('_adm_form_btn_displays_cancel'),
  93. 'attrs' => array(
  94. 'onclick' => "$('.bx-popup-applied:visible').dolPopupHide()",
  95. 'class' => 'bx-def-margin-sec-left',
  96. ),
  97. )
  98. )
  99. )
  100. );
  101. $oForm = new BxTemplStudioFormView($aForm);
  102. $oForm->initChecker();
  103. if($oForm->isSubmittedAndValid()) {
  104. if($oForm->update($iId) !== false)
  105. $aRes = array('grid' => $this->getCode(false), 'blink' => $iId);
  106. else
  107. $aRes = array('msg' => _t('_adm_form_err_displays_edit'));
  108. echoJson($aRes);
  109. }
  110. else {
  111. $sContent = BxTemplStudioFunctions::getInstance()->popupBox('adm-form-forms-edit-popup', _t('_adm_form_txt_displays_edit_popup', _t($aDisplay['title'])), $this->_oTemplate->parseHtmlByName('form_add_display.html', array(
  112. 'form_id' => $aForm['form_attrs']['id'],
  113. 'form' => $oForm->getCode(true),
  114. 'object' => $this->_sObject,
  115. 'action' => $sAction
  116. )));
  117. echoJson(array('popup' => array('html' => $sContent, 'options' => array('closeOnOuterClick' => false))));
  118. }
  119. }
  120. function getJsObject()
  121. {
  122. return 'oBxDolStudioFormsDisplays';
  123. }
  124. function getFormsSelector($sModule = '')
  125. {
  126. $oForm = new BxTemplStudioFormView(array());
  127. $aInputForms = array(
  128. 'type' => 'select',
  129. 'name' => 'form',
  130. 'attrs' => array(
  131. 'id' => 'bx-grid-form-' . $this->_sObject,
  132. 'onChange' => 'javascript:' . $this->getJsObject() . '.onChangeForm()'
  133. ),
  134. 'value' => $this->sObject,
  135. 'values' => array()
  136. );
  137. $aForms = array();
  138. if(!empty($sModule))
  139. $this->oDb->getForms(array('type' => 'by_module', 'value' => $sModule), $aForms, false);
  140. else
  141. $aInputForms['attrs']['disabled'] = 'disabled';
  142. if(!empty($aForms)) {
  143. $aCounter = array();
  144. $this->oDb->getDisplays(array('type' => 'counter_by_forms'), $aCounter, false);
  145. foreach($aForms as $aForm)
  146. $aInputForms['values'][$aForm['object']] = _t($aForm['title']) . " (" . (isset($aCounter[$aForm['object']]) ? $aCounter[$aForm['object']] : "0") . ")";
  147. asort($aInputForms['values']);
  148. }
  149. $aInputForms['values'] = array_merge(array('' => _t('_adm_form_txt_select_form')), $aInputForms['values']);
  150. return $oForm->genRow($aInputForms);
  151. }
  152. function getCode($isDisplayHeader = true)
  153. {
  154. return $this->_oTemplate->parseHtmlByName('forms_displays.html', array(
  155. 'content' => parent::getCode($isDisplayHeader),
  156. 'js_object' => $this->getJsObject(),
  157. 'page_url' => $this->sUrlPage,
  158. 'grid_object' => $this->_sObject,
  159. 'params_divider' => $this->sParamsDivider
  160. ));
  161. }
  162. protected function _addJsCss()
  163. {
  164. parent::_addJsCss();
  165. $this->_oTemplate->addJs(array('jquery.form.min.js', 'forms_displays.js'));
  166. $oForm = new BxTemplStudioFormView(array());
  167. $oForm->addCssJs();
  168. }
  169. protected function _getCellModule($mixedValue, $sKey, $aField, $aRow)
  170. {
  171. $mixedValue = $this->_limitMaxLength($this->getModuleTitle($aRow['module']), $sKey, $aField, $aRow, $this->_isDisplayPopupOnTextOverflow);
  172. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  173. }
  174. protected function _getCellFields ($mixedValue, $sKey, $aField, $aRow)
  175. {
  176. $aFields = array();
  177. $this->oDb->getInputs(array('type' => 'by_object_display', 'object' => $aRow['object'], 'display' => $aRow['display_name'], 'active' => 1), $aFields, false);
  178. $sLink = sprintf($this->sUrlViewFields, $aRow['module'], $aRow['object'], $aRow['display_name']);
  179. $mixedValue = $this->_oTemplate->parseLink($sLink, _t('_adm_form_txt_forms_n_fields', count($aFields)), array(
  180. 'title' => _t('_adm_form_txt_displays_manage_fields')
  181. ));
  182. return parent::_getCellDefault ($mixedValue, $sKey, $aField, $aRow);
  183. }
  184. protected function _getFilterControls ()
  185. {
  186. parent::_getFilterControls();
  187. $sContent = $this->getModulesSelectOne('getDisplays', false) . $this->getFormsSelector($this->sModule);
  188. $oForm = new BxTemplStudioFormView(array());
  189. $aInputSearch = array(
  190. 'type' => 'text',
  191. 'name' => 'keyword',
  192. 'attrs' => array(
  193. 'id' => 'bx-grid-search-' . $this->_sObject,
  194. 'aria-label' => _t('_adm_grid_lbl_search'),
  195. ),
  196. 'tr_attrs' => array(
  197. 'style' => 'display:none;'
  198. )
  199. );
  200. $sContent .= $oForm->genRow($aInputSearch);
  201. return $sContent;
  202. }
  203. }
  204. /** @} */