1
0

BxBaseStudioPolyglotEtemplates.php 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup UnaView UNA Studio Representation classes
  7. * @ingroup UnaStudio
  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. echoJson(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. echoJson(array());
  34. exit;
  35. }
  36. bx_import('BxTemplStudioFormView');
  37. $aForm = array(
  38. 'form_attrs' => array(
  39. 'id' => 'adm-pgt-etemplate-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_email_templates',
  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. 'NameSystem' => array(
  62. 'type' => 'text_translatable',
  63. 'name' => 'NameSystem',
  64. 'caption' => _t('_adm_pgt_txt_etemplates_name_system'),
  65. 'info' => _t('_adm_pgt_dsc_etemplates_name_system'),
  66. 'value' => $aEtemplate['name_system'],
  67. 'required' => '1',
  68. 'db' => array (
  69. 'pass' => 'Xss',
  70. ),
  71. 'checker' => array (
  72. 'func' => 'LengthTranslatable',
  73. 'params' => array(3,100, 'NameSystem'),
  74. 'error' => _t('_adm_pgt_err_etemplates_name_system'),
  75. ),
  76. ),
  77. 'Subject' => array(
  78. 'type' => 'text_translatable',
  79. 'name' => 'Subject',
  80. 'caption' => _t('_adm_pgt_txt_etemplates_subject'),
  81. 'info' => _t('_adm_pgt_dsc_etemplates_subject'),
  82. 'value' => $aEtemplate['subject'],
  83. 'required' => '1',
  84. 'db' => array (
  85. 'pass' => 'Xss',
  86. ),
  87. 'checker' => array (
  88. 'func' => 'AvailTranslatable',
  89. 'params' => array('Subject'),
  90. 'error' => _t('_adm_pgt_err_etemplates_subject'),
  91. ),
  92. ),
  93. 'Body' => array(
  94. 'type' => 'textarea_translatable',
  95. 'name' => 'Body',
  96. 'caption' => _t('_adm_pgt_txt_etemplates_body'),
  97. 'info' => _t('_adm_pgt_dsc_etemplates_body'),
  98. 'value' => $aEtemplate['body'],
  99. 'code' => 1,
  100. 'required' => '1',
  101. 'db' => array (
  102. 'pass' => 'XssHtml',
  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. echoJson($aRes);
  138. }
  139. else {
  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. echoJson(array('popup' => array('html' => $sContent, 'options' => array('closeOnOuterClick' => false))));
  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. $oForm = new BxTemplStudioFormView(array());
  166. $oForm->addCssJs();
  167. }
  168. protected function _getCellModule($mixedValue, $sKey, $aField, $aRow)
  169. {
  170. $mixedValue = $this->_limitMaxLength($this->getModuleTitle($aRow['Module']), $sKey, $aField, $aRow, $this->_isDisplayPopupOnTextOverflow);
  171. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  172. }
  173. protected function _getFilterControls ()
  174. {
  175. parent::_getFilterControls();
  176. $sContent = "";
  177. $sJsObject = $this->getJsObject();
  178. $oForm = new BxTemplStudioFormView(array());
  179. $aInputModules = array(
  180. 'type' => 'select',
  181. 'name' => 'module',
  182. 'attrs' => array(
  183. 'id' => 'bx-grid-module-' . $this->_sObject,
  184. 'aria-label' => _t('_adm_grid_lbl_module'),
  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. 'aria-label' => _t('_adm_grid_lbl_search'),
  202. 'onKeyup' => 'javascript:$(this).off(\'keyup focusout\'); ' . $sJsObject . '.onChangeFilter()',
  203. 'onBlur' => 'javascript:' . $sJsObject . '.onChangeFilter()',
  204. )
  205. );
  206. $sContent .= $oForm->genRow($aInputSearch);
  207. return $sContent;
  208. }
  209. }
  210. /** @} */