BxBaseStudioFormsForms.php 8.1 KB

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