BxBaseStudioFormsForms.php 8.0 KB

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