BxBaseStudioPolyglotEtemplates.php 8.8 KB

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