BxBaseStudioPolyglotEtemplates.php 8.6 KB

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