BxBaseStudioFormsDisplays.php 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
  4. * CC-BY License - http://creativecommons.org/licenses/by/3.0/
  5. *
  6. * @defgroup DolphinView Dolphin Studio Representation classes
  7. * @ingroup DolphinStudio
  8. * @{
  9. */
  10. bx_import('BxDolStudioFormsDisplays');
  11. bx_import('BxTemplStudioFormView');
  12. class BxBaseStudioFormsDisplays extends BxDolStudioFormsDisplays {
  13. protected $sUrlPage;
  14. protected $sUrlViewFields;
  15. function __construct($aOptions, $oTemplate = false) {
  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. $sAction = 'edit';
  23. $aIds = bx_get('ids');
  24. if(!$aIds || !is_array($aIds)) {
  25. $iId = (int)bx_get('id');
  26. if(!$iId) {
  27. $this->_echoResultJson(array());
  28. exit;
  29. }
  30. $aIds = array($iId);
  31. }
  32. $iId = $aIds[0];
  33. $aDisplay = array();
  34. $iDisplay = $this->oDb->getDisplays(array('type' => 'by_id', 'value' => $iId), $aDisplay);
  35. if($iDisplay != 1 || empty($aDisplay)){
  36. $this->_echoResultJson(array());
  37. exit;
  38. }
  39. $aForm = array(
  40. 'form_attrs' => array(
  41. 'id' => 'adm-form-display-edit',
  42. 'action' => BX_DOL_URL_ROOT . 'grid.php?o=' . $this->_sObject . '&a=' . $sAction . '&object=' . $this->sObject,
  43. 'method' => BX_DOL_STUDIO_METHOD_DEFAULT
  44. ),
  45. 'params' => array (
  46. 'db' => array(
  47. 'table' => 'sys_form_displays',
  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_displays_title'),
  67. 'info' => _t('_adm_form_dsc_displays_title'),
  68. 'value' => $aDisplay['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_displays_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_displays_save'),
  86. ),
  87. array (
  88. 'type' => 'reset',
  89. 'name' => 'close',
  90. 'value' => _t('_adm_form_btn_displays_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_displays_edit'));
  106. $this->_echoResultJson($aRes, true);
  107. }
  108. else {
  109. bx_import('BxTemplStudioFunctions');
  110. $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(
  111. 'form_id' => $aForm['form_attrs']['id'],
  112. 'form' => $oForm->getCode(true),
  113. 'object' => $this->_sObject,
  114. 'action' => $sAction
  115. )));
  116. $this->_echoResultJson(array('popup' => array('html' => $sContent, 'options' => array('closeOnOuterClick' => false))), true);
  117. }
  118. }
  119. function getJsObject() {
  120. return 'oBxDolStudioFormsDisplays';
  121. }
  122. function getFormsSelector($sModule = '') {
  123. bx_import('BxTemplStudioFormView');
  124. $oForm = new BxTemplStudioFormView(array());
  125. $aInputForms = array(
  126. 'type' => 'select',
  127. 'name' => 'form',
  128. 'attrs' => array(
  129. 'id' => 'bx-grid-form-' . $this->_sObject,
  130. 'onChange' => 'javascript:' . $this->getJsObject() . '.onChangeForm()'
  131. ),
  132. 'value' => $this->sObject,
  133. 'values' => array()
  134. );
  135. $aForms = array();
  136. if(!empty($sModule))
  137. $this->oDb->getForms(array('type' => 'by_module', 'value' => $sModule), $aForms, false);
  138. else
  139. $aInputForms['attrs']['disabled'] = 'disabled';
  140. if(!empty($aForms)) {
  141. $aCounter = array();
  142. $this->oDb->getDisplays(array('type' => 'counter_by_forms'), $aCounter, false);
  143. foreach($aForms as $aForm)
  144. $aInputForms['values'][$aForm['object']] = _t($aForm['title']) . " (" . (isset($aCounter[$aForm['object']]) ? $aCounter[$aForm['object']] : "0") . ")";
  145. asort($aInputForms['values']);
  146. }
  147. $aInputForms['values'] = array_merge(array('' => _t('_adm_form_txt_select_form')), $aInputForms['values']);
  148. return $oForm->genRow($aInputForms);
  149. }
  150. function getCode($isDisplayHeader = true) {
  151. return $this->_oTemplate->parseHtmlByName('forms_displays.html', array(
  152. 'content' => parent::getCode($isDisplayHeader),
  153. 'js_object' => $this->getJsObject(),
  154. 'page_url' => $this->sUrlPage,
  155. 'grid_object' => $this->_sObject,
  156. 'params_divider' => $this->sParamsDivider
  157. ));
  158. }
  159. protected function _addJsCss() {
  160. parent::_addJsCss();
  161. $this->_oTemplate->addJs(array('jquery.form.js', 'forms_displays.js'));
  162. bx_import('BxTemplStudioFormView');
  163. $oForm = new BxTemplStudioFormView(array());
  164. $oForm->addCssJs();
  165. }
  166. protected function _getCellModule($mixedValue, $sKey, $aField, $aRow) {
  167. $mixedValue = $this->_limitMaxLength($this->getModuleTitle($aRow['module']), $sKey, $aField, $aRow, $this->_isDisplayPopupOnTextOverflow);
  168. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  169. }
  170. protected function _getCellFields ($mixedValue, $sKey, $aField, $aRow) {
  171. $aFields = array();
  172. $this->oDb->getInputs(array('type' => 'by_object_display', 'object' => $aRow['object'], 'display' => $aRow['display_name']), $aFields, false);
  173. $mixedValue = $this->_oTemplate->parseHtmlByName('bx_a.html', array(
  174. 'href' => sprintf($this->sUrlViewFields, $aRow['module'], $aRow['object'], $aRow['display_name']),
  175. 'title' => _t('_adm_form_txt_displays_manage_fields'),
  176. 'bx_repeat:attrs' => array(),
  177. 'content' => _t('_adm_form_txt_forms_n_fields', count($aFields))
  178. ));
  179. return parent::_getCellDefault ($mixedValue, $sKey, $aField, $aRow);
  180. }
  181. protected function _getFilterControls () {
  182. parent::_getFilterControls();
  183. $sContent = $this->getModulesSelectOne('getDisplays', false) . $this->getFormsSelector($this->sModule);
  184. bx_import('BxTemplStudioFormView');
  185. $oForm = new BxTemplStudioFormView(array());
  186. $aInputSearch = array(
  187. 'type' => 'text',
  188. 'name' => 'keyword',
  189. 'attrs' => array(
  190. 'id' => 'bx-grid-search-' . $this->_sObject,
  191. ),
  192. 'tr_attrs' => array(
  193. 'style' => 'display:none;'
  194. )
  195. );
  196. $sContent .= $oForm->genRow($aInputSearch);
  197. return $sContent;
  198. }
  199. }
  200. /** @} */