1
0

BxBaseStudioFormsDisplays.php 8.7 KB

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