Răsfoiți Sursa

Ticket #5439 - Notifications: Allow to customize email templates.

AntonLV 6 luni în urmă
părinte
comite
82aae8927e

+ 1 - 0
modules/boonex/notifications/classes/BxNtfsConfig.php

@@ -128,6 +128,7 @@ class BxNtfsConfig extends BxBaseModNotificationsConfig
                 'event' => $sHtmlPrefix . '-event-',
                 'add_etemplate_popup' => $sHtmlPrefix . '-etemplate-add',
                 'edit_etemplate_popup' => $sHtmlPrefix . '-etemplate-edit',
+                'preview_etemplate_popup' => $sHtmlPrefix . '-etemplate-preview',
             ]
         ];
     }

+ 24 - 1
modules/boonex/notifications/classes/BxNtfsGridEtemplates.php

@@ -47,6 +47,7 @@ class BxNtfsGridEtemplates extends BxTemplGrid
         }
         else {
             $sContent = BxTemplFunctions::getInstance()->popupBox($this->_oModule->_oConfig->getHtmlIds('view', 'add_etemplate_popup'), _t('_bx_ntfs_grid_popup_title_ett_add'), $this->_oModule->_oTemplate->parseHtmlByName('etemplate_form.html', [
+                'style_prefix' => $this->_oModule->_oConfig->getPrefix('style'),
                 'form_id' => $oForm->aFormAttrs['id'],
                 'form' => $oForm->getCode(true),
                 'object' => $this->_sObject,
@@ -77,7 +78,8 @@ class BxNtfsGridEtemplates extends BxTemplGrid
             echoJson($aRes);
         }
         else {
-            $sContent = BxTemplFunctions::getInstance()->popupBox($this->_oModule->_oConfig->getHtmlIds('edit_profile_popup'), _t('_bx_ntfs_grid_popup_title_ett_edit'), $this->_oModule->_oTemplate->parseHtmlByName('etemplate_form.html', [
+            $sContent = BxTemplFunctions::getInstance()->popupBox($this->_oModule->_oConfig->getHtmlIds('view', 'edit_etemplate_popup'), _t('_bx_ntfs_grid_popup_title_ett_edit'), $this->_oModule->_oTemplate->parseHtmlByName('etemplate_form.html', [
+                'style_prefix' => $this->_oModule->_oConfig->getPrefix('style'),
                 'form_id' => $oForm->aFormAttrs['id'],
                 'form' => $oForm->getCode(true),
                 'object' => $this->_sObject,
@@ -88,6 +90,27 @@ class BxNtfsGridEtemplates extends BxTemplGrid
         }
     }
 
+    public function performActionPreview()
+    {
+        $iId = $this->_getId();
+        $aEtemplate = $this->_oModule->_oDb->getEtemplates(['sample' => 'id', 'id' => $iId]);
+        if(empty($aEtemplate) || !is_array($aEtemplate))
+            return echoJson([]);
+
+        $aTemplate = BxDolEmailTemplates::getInstance()->parseTemplate('bx_notifications_new_event', [
+            'subject' => !empty($aEtemplate['subject']) ? $aEtemplate['subject'] : _t('_bx_ntfs_txt_new_event_subject', getParam('site_title')),
+            'content' => $aEtemplate['body']
+        ]);
+
+        $sContent = BxTemplFunctions::getInstance()->popupBox($this->_oModule->_oConfig->getHtmlIds('view', 'preview_etemplate_popup'), _t('_bx_ntfs_grid_popup_title_ett_preview'), $this->_oModule->_oTemplate->parseHtmlByName('etemplate_preview.html', [
+            'style_prefix' => $this->_oModule->_oConfig->getPrefix('style'),
+            'subject' => $aTemplate['Subject'],
+            'body' => $aTemplate['Body']
+        ]));
+
+        echoJson(['popup' => ['html' => $sContent, 'options' => ['closeOnOuterClick' => true, 'removeOnClose' => true]]]);
+    }
+
     protected function _getCellType($mixedValue, $sKey, $aField, $aRow)
     {
         return parent::_getCellDefault($this->_oModule->_oTemplate->getTypeTitle($mixedValue), $sKey, $aField, $aRow);

+ 4 - 2
modules/boonex/notifications/classes/BxNtfsTemplate.php

@@ -352,14 +352,16 @@ class BxNtfsTemplate extends BxBaseModNotificationsTemplate
 
         $sSubject = $sBody = '';
         if(!empty($aEtemplate) && is_array($aEtemplate)) {
-            $sSubject = $aEtemplate['subject'];
-            $sBody = bx_replace_markers($aEtemplate['body'], [
+            $aEtParams = array_merge($aContent, [
                 'icon_url' => $sIconUrl,
                 'content_url' => $sContentUrl,
                 'content' => $sContent,
                 'summary' => $sSummary,
                 'date' => $sDate
             ]);
+
+            $sSubject = bx_replace_markers($aEtemplate['subject'], $aEtParams);
+            $sBody = bx_replace_markers($aEtemplate['body'], $aEtParams);
         }
         else {
             $sSubject = $sContent;

+ 4 - 1
modules/boonex/notifications/install/langs/en.xml

@@ -184,6 +184,8 @@
     <string name="_bx_ntfs_txt_subobject_added"><![CDATA[<b class="bx-ntfs-content-profile">{owner_name}</b> added a {subentry_sample} <b class="bx-ntfs-content-entry">{entry_caption}</b>]]></string>
     <string name="_bx_ntfs_txt_subobject_added_in_context"><![CDATA[<b class="bx-ntfs-content-profile">{owner_name}</b> has got a {subentry_sample} <b class="bx-ntfs-content-entry">{entry_caption}</b>]]></string>
     <string name="_bx_ntfs_txt_new_event_subject"><![CDATA[New on "{0}"]]></string>
+    <string name="_bx_ntfs_txt_et_preview_subject"><![CDATA[Subject:]]></string>
+    <string name="_bx_ntfs_txt_et_preview_body"><![CDATA[Body:]]></string>
 
     <string name="_bx_ntfs_email_new_event"><![CDATA[New notification]]></string>
     <string name="_bx_ntfs_email_new_event_subject"><![CDATA[{subject}]]></string>
@@ -207,9 +209,10 @@
     <string name="_bx_ntfs_grid_column_title_ett_action"><![CDATA[Action]]></string>
     <string name="_bx_ntfs_grid_column_title_ett_subject"><![CDATA[Subject]]></string>
     <string name="_bx_ntfs_grid_action_title_ett_add"><![CDATA[Add]]></string>
+    <string name="_bx_ntfs_grid_action_title_ett_preview"><![CDATA[Preview]]></string>
     <string name="_bx_ntfs_grid_action_title_ett_edit"><![CDATA[Edit]]></string>
     <string name="_bx_ntfs_grid_action_title_ett_delete"><![CDATA[Delete]]></string>
     <string name="_bx_ntfs_grid_popup_title_ett_add"><![CDATA[Add Email Template]]></string>
     <string name="_bx_ntfs_grid_popup_title_ett_edit"><![CDATA[Edit Email Template]]></string>
-    
+    <string name="_bx_ntfs_grid_popup_title_ett_preview"><![CDATA[Preview Email Template]]></string>
 </resources>

+ 3 - 2
modules/boonex/notifications/install/sql/enable.sql

@@ -191,8 +191,9 @@ INSERT INTO `sys_grid_fields` (`object`, `name`, `title`, `width`, `translatable
 
 INSERT INTO `sys_grid_actions` (`object`, `type`, `name`, `title`, `icon`, `icon_only`, `confirm`, `order`) VALUES
 ('bx_notifications_etemplates', 'independent', 'add', '_bx_ntfs_grid_action_title_ett_add', '', 0, 0, 1),
-('bx_notifications_etemplates', 'single', 'edit', '_bx_ntfs_grid_action_title_ett_edit', 'pencil-alt', 1, 0, 1),
-('bx_notifications_etemplates', 'single', 'delete', '_bx_ntfs_grid_action_title_ett_delete', 'remove', 1, 1, 2);
+('bx_notifications_etemplates', 'single', 'preview', '_bx_ntfs_grid_action_title_ett_preview', 'eye', 1, 0, 1),
+('bx_notifications_etemplates', 'single', 'edit', '_bx_ntfs_grid_action_title_ett_edit', 'pencil-alt', 1, 0, 2),
+('bx_notifications_etemplates', 'single', 'delete', '_bx_ntfs_grid_action_title_ett_delete', 'remove', 1, 1, 3);
 
 
 -- CRON

+ 12 - 0
modules/boonex/notifications/template/etemplate_preview.html

@@ -0,0 +1,12 @@
+<div class="__style_prefix__-etemplate-preview">
+    <div class="__style_prefix__-etemplate-preview-cnt">
+        <div class="__style_prefix__-etp-row">
+            <div class="font-bold"><bx_text:_bx_ntfs_txt_et_preview_subject /></div>
+            <div>__subject__</div>
+        </div>
+        <div class="__style_prefix__-etp-row mt-4">
+            <div class="font-bold"><bx_text:_bx_ntfs_txt_et_preview_body /></div>
+            <div>__body__</div>
+        </div>
+    </div>
+</div>

+ 4 - 0
modules/boonex/russian/data/langs/bx_notifications/ru.xml

@@ -184,6 +184,8 @@
     <string name="_bx_ntfs_txt_subobject_added"><![CDATA[<b class="bx-ntfs-content-profile">{owner_name}</b> - {subentry_sample} <b class="bx-ntfs-content-entry">{entry_caption}</b>]]></string>
     <string name="_bx_ntfs_txt_subobject_added_in_context"><![CDATA[<b class="bx-ntfs-content-profile">{owner_name}</b> - {subentry_sample} <b class="bx-ntfs-content-entry">{entry_caption}</b>]]></string>
     <string name="_bx_ntfs_txt_new_event_subject"><![CDATA[Новое на сайте "{0}"]]></string>
+    <string name="_bx_ntfs_txt_et_preview_subject"><![CDATA[Тема:]]></string>
+    <string name="_bx_ntfs_txt_et_preview_body"><![CDATA[Текст:]]></string>
 
     <string name="_bx_ntfs_email_new_event"><![CDATA[Новое уведомление]]></string>
     <string name="_bx_ntfs_email_new_event_subject"><![CDATA[{subject}]]></string>
@@ -207,8 +209,10 @@
     <string name="_bx_ntfs_grid_column_title_ett_action"><![CDATA[Действие]]></string>
     <string name="_bx_ntfs_grid_column_title_ett_subject"><![CDATA[Тема]]></string>
     <string name="_bx_ntfs_grid_action_title_ett_add"><![CDATA[Добавить]]></string>
+    <string name="_bx_ntfs_grid_action_title_ett_preview"><![CDATA[Предварительный просмотр]]></string>
     <string name="_bx_ntfs_grid_action_title_ett_edit"><![CDATA[Редактировать]]></string>
     <string name="_bx_ntfs_grid_action_title_ett_delete"><![CDATA[Удалить]]></string>
     <string name="_bx_ntfs_grid_popup_title_ett_add"><![CDATA[Добавить шаблон электронного письма]]></string>
     <string name="_bx_ntfs_grid_popup_title_ett_edit"><![CDATA[Редактировать шаблон электронного письма]]></string>
+    <string name="_bx_ntfs_grid_popup_title_ett_preview"><![CDATA[Предпросмотр шаблона электронного письма]]></string>
 </resources>