BxBaseStudioPolyglotEtemplates.php 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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('BxDolStudioPolyglotEtemplates');
  11. bx_import('BxTemplStudioFormView');
  12. class BxBaseStudioPolyglotEtemplates extends BxDolStudioPolyglotEtemplates {
  13. function __construct($aOptions, $oTemplate = false) {
  14. parent::__construct($aOptions, $oTemplate);
  15. $this->_aOptions['actions_single']['edit']['attr']['title'] = _t('_adm_pgt_btn_etemplates_gl_edit_title');
  16. }
  17. public function performActionEdit() {
  18. $sAction = 'edit';
  19. $aIds = bx_get('ids');
  20. if(!$aIds || !is_array($aIds)) {
  21. $iId = (int)bx_get('id');
  22. if(!$iId) {
  23. $this->_echoResultJson(array());
  24. exit;
  25. }
  26. $aIds = array($iId);
  27. }
  28. $iId = $aIds[0];
  29. $aEtemplate = array();
  30. $this->oDb->getEtemplates(array('type' => 'by_id', 'value' => $iId), $aEtemplate, false);
  31. if(empty($aEtemplate) || !is_array($aEtemplate)){
  32. $this->_echoResultJson(array());
  33. exit;
  34. }
  35. $aForm = array(
  36. 'form_attrs' => array(
  37. 'id' => 'adm-pgt-etemplate-edit',
  38. 'action' => BX_DOL_URL_ROOT . 'grid.php?o=' . $this->_sObject . '&a=' . $sAction,
  39. 'method' => BX_DOL_STUDIO_METHOD_DEFAULT
  40. ),
  41. 'params' => array (
  42. 'db' => array(
  43. 'table' => 'sys_email_templates',
  44. 'key' => 'ID',
  45. 'uri' => '',
  46. 'uri_title' => '',
  47. 'submit_name' => 'do_submit'
  48. ),
  49. ),
  50. 'inputs' => array (
  51. 'ID' => array(
  52. 'type' => 'hidden',
  53. 'name' => 'id',
  54. 'value' => $iId,
  55. 'db' => array (
  56. 'pass' => 'Int',
  57. ),
  58. ),
  59. 'NameSystem' => array(
  60. 'type' => 'text_translatable',
  61. 'name' => 'NameSystem',
  62. 'caption' => _t('_adm_pgt_txt_etemplates_name_system'),
  63. 'info' => _t('_adm_pgt_dsc_etemplates_name_system'),
  64. 'value' => $aEtemplate['name_system'],
  65. 'required' => '1',
  66. 'db' => array (
  67. 'pass' => 'Xss',
  68. ),
  69. 'checker' => array (
  70. 'func' => 'LengthTranslatable',
  71. 'params' => array(3,100, 'NameSystem'),
  72. 'error' => _t('_adm_pgt_err_etemplates_name_system'),
  73. ),
  74. ),
  75. 'Subject' => array(
  76. 'type' => 'text_translatable',
  77. 'name' => 'Subject',
  78. 'caption' => _t('_adm_pgt_txt_etemplates_subject'),
  79. 'info' => _t('_adm_pgt_dsc_etemplates_subject'),
  80. 'value' => $aEtemplate['subject'],
  81. 'required' => '1',
  82. 'db' => array (
  83. 'pass' => 'Xss',
  84. ),
  85. 'checker' => array (
  86. 'func' => 'AvailTranslatable',
  87. 'params' => array('Subject'),
  88. 'error' => _t('_adm_pgt_err_etemplates_subject'),
  89. ),
  90. ),
  91. 'Body' => array(
  92. 'type' => 'textarea_translatable',
  93. 'name' => 'Body',
  94. 'caption' => _t('_adm_pgt_txt_etemplates_body'),
  95. 'info' => _t('_adm_pgt_dsc_etemplates_body'),
  96. 'value' => $aEtemplate['body'],
  97. 'required' => '1',
  98. 'db' => array (
  99. 'pass' => 'Xss',
  100. ),
  101. 'checker' => array (
  102. 'func' => 'AvailTranslatable',
  103. 'params' => array('Body'),
  104. 'error' => _t('_adm_pgt_err_etemplates_body'),
  105. ),
  106. ),
  107. 'controls' => array(
  108. 'name' => 'controls',
  109. 'type' => 'input_set',
  110. array(
  111. 'type' => 'submit',
  112. 'name' => 'do_submit',
  113. 'value' => _t('_adm_pgt_btn_etemplates_save'),
  114. ),
  115. array (
  116. 'type' => 'reset',
  117. 'name' => 'close',
  118. 'value' => _t('_adm_pgt_btn_etemplates_cancel'),
  119. 'attrs' => array(
  120. 'onclick' => "$('.bx-popup-applied:visible').dolPopupHide()",
  121. 'class' => 'bx-def-margin-sec-left',
  122. ),
  123. )
  124. )
  125. )
  126. );
  127. $oForm = new BxTemplStudioFormView($aForm);
  128. $oForm->initChecker();
  129. if($oForm->isSubmittedAndValid()) {
  130. if($oForm->update($iId) !== false)
  131. $aRes = array('grid' => $this->getCode(false), 'blink' => $iId);
  132. else
  133. $aRes = array('msg' => _t('_adm_pgt_err_etemplates_edit'));
  134. $this->_echoResultJson($aRes, true);
  135. }
  136. else {
  137. bx_import('BxTemplStudioFunctions');
  138. $sContent = BxTemplStudioFunctions::getInstance()->popupBox('adm-pgt-etemplate-edit-popup', _t('_adm_pgt_txt_etemplates_edit_popup', _t($aEtemplate['name_system'])), $this->_oTemplate->parseHtmlByName('pgt_new_etemplate.html', array(
  139. 'form_id' => $aForm['form_attrs']['id'],
  140. 'form' => $oForm->getCode(true),
  141. 'object' => $this->_sObject,
  142. 'action' => $sAction
  143. )));
  144. $this->_echoResultJson(array('popup' => array('html' => $sContent, 'options' => array('closeOnOuterClick' => false))), true);
  145. }
  146. }
  147. function getJsObject() {
  148. return 'oBxDolStudioPolyglotEtemplates';
  149. }
  150. function getCode($isDisplayHeader = true) {
  151. return $this->_oTemplate->parseHtmlByName('pgt_etemplates.html', array(
  152. 'content' => parent::getCode($isDisplayHeader),
  153. 'js_object' => $this->getJsObject(),
  154. 'grid_object' => $this->_sObject
  155. ));
  156. }
  157. protected function _addJsCss() {
  158. parent::_addJsCss();
  159. $this->_oTemplate->addJs(array('jquery.form.js', 'polyglot_etemplates.js'));
  160. bx_import('BxTemplStudioFormView');
  161. $oForm = new BxTemplStudioFormView(array());
  162. $oForm->addCssJs();
  163. }
  164. protected function _getCellModule($mixedValue, $sKey, $aField, $aRow) {
  165. $mixedValue = $this->_limitMaxLength($this->getModuleTitle($aRow['Module']), $sKey, $aField, $aRow, $this->_isDisplayPopupOnTextOverflow);
  166. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  167. }
  168. protected function _getFilterControls () {
  169. parent::_getFilterControls();
  170. $sContent = "";
  171. bx_import('BxTemplStudioFormView');
  172. $oForm = new BxTemplStudioFormView(array());
  173. $aInputModules = array(
  174. 'type' => 'select',
  175. 'name' => 'module',
  176. 'attrs' => array(
  177. 'id' => 'bx-grid-module-' . $this->_sObject,
  178. 'onChange' => 'javascript:' . $this->getJsObject() . '.onChangeFilter()'
  179. ),
  180. 'value' => '',
  181. 'values' => $this->getModules(false)
  182. );
  183. $aCounter = array();
  184. $this->oDb->getEtemplates(array('type' => 'counter_by_modules'), $aCounter, false);
  185. foreach($aInputModules['values'] as $sKey => $sValue)
  186. $aInputModules['values'][$sKey] = $aInputModules['values'][$sKey] . " (" . (isset($aCounter[$sKey]) ? $aCounter[$sKey] : "0") . ")";
  187. $aInputModules['values'] = array_merge(array('' => _t('_adm_pgt_txt_all_modules')), $aInputModules['values']);
  188. $sContent .= $oForm->genRow($aInputModules);
  189. $aInputSearch = array(
  190. 'type' => 'text',
  191. 'name' => 'keyword',
  192. 'attrs' => array(
  193. 'id' => 'bx-grid-search-' . $this->_sObject,
  194. 'onKeyup' => 'javascript:$(this).off(\'keyup\'); ' . $this->getJsObject() . '.onChangeFilter()'
  195. )
  196. );
  197. $sContent .= $oForm->genRow($aInputSearch);
  198. return $sContent;
  199. }
  200. }
  201. /** @} */