BxBaseStudioPolyglotEtemplates.php 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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 TridentView Trident Studio Representation classes
  7. * @ingroup TridentStudio
  8. * @{
  9. */
  10. class BxBaseStudioPolyglotEtemplates extends BxDolStudioPolyglotEtemplates
  11. {
  12. function __construct($aOptions, $oTemplate = false)
  13. {
  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. {
  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. $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. {
  149. return 'oBxDolStudioPolyglotEtemplates';
  150. }
  151. function getCode($isDisplayHeader = true)
  152. {
  153. return $this->_oTemplate->parseHtmlByName('pgt_etemplates.html', array(
  154. 'content' => parent::getCode($isDisplayHeader),
  155. 'js_object' => $this->getJsObject(),
  156. 'grid_object' => $this->_sObject
  157. ));
  158. }
  159. protected function _addJsCss()
  160. {
  161. parent::_addJsCss();
  162. $this->_oTemplate->addJs(array('jquery.form.min.js', 'polyglot_etemplates.js'));
  163. $oForm = new BxTemplStudioFormView(array());
  164. $oForm->addCssJs();
  165. }
  166. protected function _getCellModule($mixedValue, $sKey, $aField, $aRow)
  167. {
  168. $mixedValue = $this->_limitMaxLength($this->getModuleTitle($aRow['Module']), $sKey, $aField, $aRow, $this->_isDisplayPopupOnTextOverflow);
  169. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  170. }
  171. protected function _getFilterControls ()
  172. {
  173. parent::_getFilterControls();
  174. $sContent = "";
  175. $oForm = new BxTemplStudioFormView(array());
  176. $aInputModules = array(
  177. 'type' => 'select',
  178. 'name' => 'module',
  179. 'attrs' => array(
  180. 'id' => 'bx-grid-module-' . $this->_sObject,
  181. 'onChange' => 'javascript:' . $this->getJsObject() . '.onChangeFilter()'
  182. ),
  183. 'value' => '',
  184. 'values' => $this->getModules(false)
  185. );
  186. $aCounter = array();
  187. $this->oDb->getEtemplates(array('type' => 'counter_by_modules'), $aCounter, false);
  188. foreach($aInputModules['values'] as $sKey => $sValue)
  189. $aInputModules['values'][$sKey] = $aInputModules['values'][$sKey] . " (" . (isset($aCounter[$sKey]) ? $aCounter[$sKey] : "0") . ")";
  190. $aInputModules['values'] = array_merge(array('' => _t('_adm_pgt_txt_all_modules')), $aInputModules['values']);
  191. $sContent .= $oForm->genRow($aInputModules);
  192. $aInputSearch = array(
  193. 'type' => 'text',
  194. 'name' => 'keyword',
  195. 'attrs' => array(
  196. 'id' => 'bx-grid-search-' . $this->_sObject,
  197. 'onKeyup' => 'javascript:$(this).off(\'keyup\'); ' . $this->getJsObject() . '.onChangeFilter()'
  198. )
  199. );
  200. $sContent .= $oForm->genRow($aInputSearch);
  201. return $sContent;
  202. }
  203. }
  204. /** @} */