BxBaseStudioFormsDisplays.php 8.8 KB

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