Преглед изворни кода

Ticket #4705 - Intergrate Grapesjs in Massmailer.

AntonLV пре 2 година
родитељ
комит
ad77fde7af

+ 10 - 2
modules/boonex/massmailer/classes/BxMassMailerConfig.php

@@ -9,7 +9,7 @@
  * @{
  */
 
-class BxMassMailerConfig extends BxBaseModGeneralConfig
+class BxMassMailerConfig extends BxBaseModTextConfig
 {
     function __construct($aModule)
     {
@@ -56,7 +56,10 @@ class BxMassMailerConfig extends BxBaseModGeneralConfig
             'URI_EDIT_CAMPAIGN' => 'edit-campaign',
             'URI_VIEW_CAMPAIGN' => 'view-campaign',
             'URL_MANAGE_CAMPAIGNS' => 'page.php?i=massmailer-campaigns',
-            
+
+            // some params
+            'PARAM_USE_CREATIVE' => true,
+
             // objects
             'OBJECT_FORM_ENTRY' => 'bx_massmailer',
             'OBJECT_FORM_ENTRY_DISPLAY_EDIT' => 'bx_massmailer_campaign_edit',
@@ -81,6 +84,11 @@ class BxMassMailerConfig extends BxBaseModGeneralConfig
             'campaigns' => $this->CNF['OBJECT_GRID_CAMPAIGNS'],
             'letters' => $this->CNF['OBJECT_GRID_LETTERS'],
         );
+
+        $sPrefix = str_replace('_', '-', $this->_sName);
+        $this->_aHtmlIds = array_merge($this->_aHtmlIds, [
+            'campaign_body' => $sPrefix . '-campaign-body',
+        ]);
     }
 }
 

+ 56 - 0
modules/boonex/massmailer/classes/BxMassMailerFormEntry.php

@@ -39,23 +39,79 @@ class BxMassMailerFormCheckerHelper extends BxDolFormCheckerHelper
  */
 class BxMassMailerFormEntry extends BxBaseModTextFormEntry
 {
+    protected $_bCreative;
+
     public function __construct($aInfo, $oTemplate = false)
     {
         $this->MODULE = 'bx_massmailer';
         $this->_oModule = BxDolModule::getInstance($this->MODULE);
+
         parent::__construct($aInfo, $oTemplate);
         
         $CNF = &$this->_oModule->_oConfig->CNF;
+
+        $this->_bCreative = $CNF['PARAM_USE_CREATIVE'];
+
         if (isset( $this->aInputs[$CNF['FIELD_SEGMENTS']]))
             $this->aInputs[$CNF['FIELD_SEGMENTS']]['values'] = $this->_oModule->getSegments();
     }
+    
+    public function getCode($bDynamicMode = false)
+    {
+        $sResult = parent::getCode($bDynamicMode);
+
+        $this->_oModule->_oTemplate->addJs([
+            'grapesjs/grapes.min.js',
+            'grapesjs/grapesjs-preset-newsletter.min.js'
+        ]);
+        $this->_oModule->_oTemplate->addCss([
+            BX_DIRECTORY_PATH_PLUGINS_PUBLIC . 'grapesjs/|grapes.min.css'
+        ]);
+
+        return $sResult;
+    }
+
+    public function initChecker ($aValues = [], $aSpecificValues = [])
+    {
+        $CNF = &$this->_oModule->_oConfig->CNF;
+
+        $bValues = $aValues && !empty($aValues['id']);
+        $iCampaignId = $bValues ? (int)$aValues['id'] : 0;
+        $aCampaignInfo = $bValues ? $this->_oModule->_oDb->getCampaignInfoById($aValues['id']) : false;
+
+        if($this->_bCreative && isset($this->aInputs[$CNF['FIELD_BODY']])) {
+            $sContent = !empty($aCampaignInfo['body']) ? $aCampaignInfo['body'] : '';
+
+            $this->aInputs[$CNF['FIELD_BODY']] = array_merge($this->aInputs[$CNF['FIELD_BODY']], [
+                'type' => 'custom',
+                'content' => $this->_oModule->_oTemplate->parseHtmlByName('campaign_body.html', [
+                    'name' => $this->aInputs[$CNF['FIELD_BODY']]['name'],
+                    'html_id' => $this->_oModule->_oConfig->getHtmlIds('campaign_body'),
+                    'content_html' => $sContent,
+                    'content_data' => json_encode([
+                        'pages' => [
+                            ['component' => $sContent]
+                        ]
+                    ])
+                ]),
+            ]);
+        }
+
+        parent::initChecker ($aValues, $aSpecificValues);
+    }
 
     public function insert ($aValsToAdd = array(), $isIgnore = false)
     {
         $CNF = &$this->_oModule->_oConfig->CNF;
+
         $aValsToAdd[$CNF['FIELD_AUTHOR']] = bx_get_logged_profile_id();
         return parent::insert ($aValsToAdd, $isIgnore);
     }
+
+    protected function genCustomInputBodyInfo ($aInput)
+    {
+        return $this->_oModule->serviceAttributes();
+    }
 }
 
 /** @} */

+ 3 - 3
modules/boonex/massmailer/install/config.php

@@ -18,12 +18,12 @@ $aConfig = array(
     'name' => 'bx_massmailer',
     'title' => 'Mass mailer',
     'note' => 'Mass mailer module.',
-    'version' => '13.0.8.DEV',
-    'vendor' => 'BoonEx',
+    'version' => '14.0.0.DEV',
+    'vendor' => 'UNA INC',
     'help_url' => 'http://feed.una.io/?section={module_name}',
 
     'compatible_with' => array(
-        '13.0.x'
+        '14.0.x'
     ),
 
     /**

+ 2 - 0
modules/boonex/massmailer/install/langs/en.xml

@@ -82,6 +82,8 @@
   <string name="_bx_massmailer_form_campaign_input_sys_body"><![CDATA[Body]]></string>
   <string name="_bx_massmailer_form_campaign_input_body"><![CDATA[Body]]></string>
   <string name="_bx_massmailer_form_campaign_input_body_err"><![CDATA[Body can't be empty and {unsubscribe_url} marker must be present]]></string>
+  <string name="_bx_massmailer_form_campaign_input_sys_body_info"><![CDATA[Body Info]]></string>
+  <string name="_bx_massmailer_form_campaign_input_body_info"><![CDATA[]]></string>
   <string name="_bx_massmailer_form_campaign_input_is_one_per_account"><![CDATA[One letter per one account]]></string>
   <string name="_bx_massmailer_form_campaign_input_is_track_links"><![CDATA[Click tracking]]></string>
   <string name="_bx_massmailer_form_campaign_input_sys_test_email"><![CDATA[Email]]></string>

+ 6 - 6
modules/boonex/massmailer/install/sql/enable.sql

@@ -17,21 +17,21 @@ INSERT INTO `sys_options` (`category_id`, `name`, `caption`, `value`, `type`, `e
 
 -- PAGE: create campaign
 INSERT INTO `sys_objects_page`(`object`, `title_system`, `title`, `module`, `layout_id`, `visible_for_levels`, `visible_for_levels_editable`, `uri`, `url`, `meta_description`, `meta_keywords`, `meta_robots`, `cache_lifetime`, `cache_editable`, `deletable`, `override_class_name`, `override_class_file`) VALUES 
-('bx_massmailer_create_campaign', '_bx_massmailer_page_title_sys_create_campaign', '_bx_massmailer_page_title_create_campaign', 'bx_massmailer', 7, 128, 1, 'create-campaign', 'page.php?i=create-campaign', '', '', '', 0, 1, 0, 'BxMassMailerPageEntry', 'modules/boonex/massmailer/classes/BxMassMailerPageEntry.php');
+('bx_massmailer_create_campaign', '_bx_massmailer_page_title_sys_create_campaign', '_bx_massmailer_page_title_create_campaign', 'bx_massmailer', 5, 128, 1, 'create-campaign', 'page.php?i=create-campaign', '', '', '', 0, 1, 0, 'BxMassMailerPageEntry', 'modules/boonex/massmailer/classes/BxMassMailerPageEntry.php');
 
 INSERT INTO `sys_pages_blocks` (`object`, `cell_id`, `module`, `title`, `designbox_id`, `visible_for_levels`, `type`, `content`, `deletable`, `copyable`, `order`) VALUES
 ('bx_massmailer_create_campaign', 1, @sName, '_bx_massmailer_page_block_title_entry_breadcrumb', 13, 128, 'service', 'a:2:{s:6:"module";s:13:"bx_massmailer";s:6:"method";s:17:"entity_breadcrumb";}', 0, 0, 0),
-('bx_massmailer_create_campaign', 2, @sName, '_bx_massmailer_page_block_title_create_campaign', 11, 128, 'service', 'a:2:{s:6:"module";s:13:"bx_massmailer";s:6:"method";s:13:"entity_create";}', 0, 1, 1),
-('bx_massmailer_create_campaign', 3, @sName, '_bx_massmailer_page_block_title_attributes', 11, 128, 'service', 'a:2:{s:6:"module";s:13:"bx_massmailer";s:6:"method";s:10:"attributes";}', 0, 0, 1);
+('bx_massmailer_create_campaign', 1, @sName, '_bx_massmailer_page_block_title_create_campaign', 11, 128, 'service', 'a:2:{s:6:"module";s:13:"bx_massmailer";s:6:"method";s:13:"entity_create";}', 0, 1, 1),
+('bx_massmailer_create_campaign', 0, @sName, '_bx_massmailer_page_block_title_attributes', 11, 128, 'service', 'a:2:{s:6:"module";s:13:"bx_massmailer";s:6:"method";s:10:"attributes";}', 0, 0, 1);
 
 -- PAGE: edit campaign
 INSERT INTO `sys_objects_page`(`object`, `title_system`, `title`, `module`, `layout_id`, `visible_for_levels`, `visible_for_levels_editable`, `uri`, `url`, `meta_description`, `meta_keywords`, `meta_robots`, `cache_lifetime`, `cache_editable`, `deletable`, `override_class_name`, `override_class_file`) VALUES 
-('bx_massmailer_edit_campaign', '_bx_massmailer_page_title_sys_edit_campaign', '_bx_massmailer_page_title_edit_campaign', 'bx_massmailer', 7, 128, 1, 'edit-campaign', '', '', '', '', 0, 1, 0, 'BxMassMailerPageEntry', 'modules/boonex/massmailer/classes/BxMassMailerPageEntry.php');
+('bx_massmailer_edit_campaign', '_bx_massmailer_page_title_sys_edit_campaign', '_bx_massmailer_page_title_edit_campaign', 'bx_massmailer', 5, 128, 1, 'edit-campaign', '', '', '', '', 0, 1, 0, 'BxMassMailerPageEntry', 'modules/boonex/massmailer/classes/BxMassMailerPageEntry.php');
 
 INSERT INTO `sys_pages_blocks` (`object`, `cell_id`, `module`, `title`, `designbox_id`, `visible_for_levels`, `type`, `content`, `deletable`, `copyable`, `order`) VALUES
 ('bx_massmailer_edit_campaign', 1, @sName, '_bx_massmailer_page_block_title_entry_breadcrumb', 13, 2147483647, 'service', 'a:2:{s:6:"module";s:13:"bx_massmailer";s:6:"method";s:17:"entity_breadcrumb";}', 0, 0, 0),
-('bx_massmailer_edit_campaign', 2, @sName, '_bx_massmailer_page_block_title_edit_campaign', 11, 128, 'service', 'a:2:{s:6:"module";s:13:"bx_massmailer";s:6:"method";s:11:"entity_edit";}', 0, 0, 1),
-('bx_massmailer_edit_campaign', 3, @sName, '_bx_massmailer_page_block_title_attributes', 11, 128, 'service', 'a:2:{s:6:"module";s:13:"bx_massmailer";s:6:"method";s:10:"attributes";}', 0, 0, 1);
+('bx_massmailer_edit_campaign', 1, @sName, '_bx_massmailer_page_block_title_edit_campaign', 11, 128, 'service', 'a:2:{s:6:"module";s:13:"bx_massmailer";s:6:"method";s:11:"entity_edit";}', 0, 0, 1),
+('bx_massmailer_edit_campaign', 0, @sName, '_bx_massmailer_page_block_title_attributes', 11, 128, 'service', 'a:2:{s:6:"module";s:13:"bx_massmailer";s:6:"method";s:10:"attributes";}', 0, 0, 1);
 
 -- PAGE: view campaign
 INSERT INTO `sys_objects_page`(`object`, `title_system`, `title`, `module`, `layout_id`, `visible_for_levels`, `visible_for_levels_editable`, `uri`, `url`, `meta_description`, `meta_keywords`, `meta_robots`, `cache_lifetime`, `cache_editable`, `deletable`, `override_class_name`, `override_class_file`) VALUES 

+ 9 - 6
modules/boonex/massmailer/install/sql/install.sql

@@ -98,6 +98,7 @@ INSERT INTO `sys_form_inputs` (`object`, `module`, `name`, `value`, `values`, `c
 (@sName, @sName, 'from_name', '', '', 0, 'text', '_bx_massmailer_form_campaign_input_sys_from_name', '_bx_massmailer_form_campaign_input_from_name', '_bx_massmailer_form_campaign_input_from_name_info', 0, 0, 0, 2, '', '', '', '', '', '', 'XssHtml', '', 1, 0),
 (@sName, @sName, 'reply_to', '', '', 0, 'text', '_bx_massmailer_form_campaign_input_sys_reply_to', '_bx_massmailer_form_campaign_input_reply_to', '_bx_massmailer_form_campaign_input_reply_to_info', 0, 0, 0, 2, '', '', '', 'EmailOrEmpty', '', '_bx_massmailer_form_campaign_input_reply_to_err', 'XssHtml', '', 1, 0),
 (@sName, @sName, 'body', '', '', 0, 'textarea', '_bx_massmailer_form_campaign_input_sys_body', '_bx_massmailer_form_campaign_input_body', '', 1, 0, 0, 2, '', '', '', 'UnsubscribeUrl', '', '_bx_massmailer_form_campaign_input_body_err', 'XssHtml', '', 1, 0),
+(@sName, @sName, 'body_info', '', '', 0, 'custom', '_bx_massmailer_form_campaign_input_sys_body_info', '_bx_massmailer_form_campaign_input_body_info', '', 0, 0, 0, 0, '', '', '', '', '', '', '', '', 1, 0),
 (@sName, @sName, 'is_one_per_account', '1', '', 1, 'switcher', '_bx_massmailer_form_campaign_input_sys_is_one_per_account', '_bx_massmailer_form_campaign_input_is_one_per_account', '', 0, 0, 0, 0, '', '', '', '', '', '', 'Int', '', 1, 0),
 (@sName, @sName, 'is_track_links', '1', '', 1, 'switcher', '_bx_massmailer_form_campaign_input_sys_is_track_links', '_bx_massmailer_form_campaign_input_is_track_links', '', 0, 0, 0, 0, '', '', '', '', '', '', 'Int', '', 1, 0),
 (@sName, @sName, 'email', '', '', 0, 'text', '_bx_massmailer_form_campaign_input_sys_test_email', '_bx_massmailer_form_campaign_input_email', '', 1, 0, 0, 2, '', '', '', 'Email', '', '_sys_form_account_input_email_error', 'XssHtml', '', 1, 0),
@@ -112,9 +113,10 @@ INSERT INTO `sys_form_display_inputs` (`display_name`, `input_name`, `visible_fo
 ('bx_massmailer_campaign_add', 'from_name', 2147483647, 1, 4),
 ('bx_massmailer_campaign_add', 'reply_to', 2147483647, 1, 5),
 ('bx_massmailer_campaign_add', 'body', 2147483647, 1, 6),
-('bx_massmailer_campaign_add', 'is_one_per_account', 2147483647, 1, 7),
-('bx_massmailer_campaign_add', 'is_track_links', 2147483647, 1, 8),
-('bx_massmailer_campaign_add', 'do_submit', 2147483647, 1, 9),
+('bx_massmailer_campaign_add', 'body_info', 2147483647, 1, 7),
+('bx_massmailer_campaign_add', 'is_one_per_account', 2147483647, 1, 8),
+('bx_massmailer_campaign_add', 'is_track_links', 2147483647, 1, 9),
+('bx_massmailer_campaign_add', 'do_submit', 2147483647, 1, 10),
 
 ('bx_massmailer_campaign_edit', 'title', 2147483647, 1, 1),
 ('bx_massmailer_campaign_edit', 'segments', 2147483647, 1, 2),
@@ -122,9 +124,10 @@ INSERT INTO `sys_form_display_inputs` (`display_name`, `input_name`, `visible_fo
 ('bx_massmailer_campaign_edit', 'from_name', 2147483647, 1, 4),
 ('bx_massmailer_campaign_edit', 'reply_to', 2147483647, 1, 5),
 ('bx_massmailer_campaign_edit', 'body', 2147483647, 1, 6),
-('bx_massmailer_campaign_edit', 'is_one_per_account', 2147483647, 1, 7),
-('bx_massmailer_campaign_edit', 'is_track_links', 2147483647, 1, 8),
-('bx_massmailer_campaign_edit', 'do_submit', 2147483647, 1, 9),
+('bx_massmailer_campaign_edit', 'body_info', 2147483647, 1, 7),
+('bx_massmailer_campaign_edit', 'is_one_per_account', 2147483647, 1, 8),
+('bx_massmailer_campaign_edit', 'is_track_links', 2147483647, 1, 9),
+('bx_massmailer_campaign_edit', 'do_submit', 2147483647, 1, 10),
 
 ('bx_massmailer_campaign_send_test', 'email', 2147483647, 1, 1),
 ('bx_massmailer_campaign_send_test', 'controls', 2147483647, 1, 2),

+ 8 - 3
modules/boonex/massmailer/template/attributes.html

@@ -1,3 +1,8 @@
-<bx_repeat:items>
-<strong>__title__</strong><br>__list__<br>
-</bx_repeat:items>
+<div class="bx-massmailer-attrs flex flex-col space-y-4">
+    <bx_repeat:items>
+    <div class="bx-massmailer-attrs-group">
+        <div class="bx-massmailer-ag-title font-bold">__title__</div>
+        <div class="bx-massmailer-ag-list pt-1">__list__</div>
+    </div>
+    </bx_repeat:items>
+</div>

+ 3 - 1
modules/boonex/massmailer/template/attributes_part.html

@@ -1 +1,3 @@
-<bx_repeat:items>__title__ : {__attribute__}<br></bx_repeat:items>
+<bx_repeat:items>
+    <div class="bx-massmailer-agl-item">__title__ : {__attribute__}</div>
+</bx_repeat:items>

+ 39 - 0
modules/boonex/massmailer/template/campaign_body.html

@@ -0,0 +1,39 @@
+<div class="bx-form-input-wrapper bx-form-input-wrapper-textarea">
+    <textarea id="__html_id__-html" class="hidden" name="__name__">__content_html__</textarea>
+    <textarea id="__html_id__-data" class="hidden">__content_data__</textarea>
+    <div id="__html_id__" class="bx-form-input-textarea"></div>
+</div>
+<script type="text/javascript">
+    var inlineStorage = null;
+    if(inlineStorage == undefined) {
+        inlineStorage = (editor) => {
+            const oStorageData = document.getElementById('__html_id__-data');
+            const oStorageHtml = document.getElementById('__html_id__-html');
+
+            editor.Storage.add('inline', {
+                load() {
+                  return JSON.parse(oStorageData.value || '{}');
+                },
+                store(data) {
+                  const component = editor.Pages.getSelected().getMainComponent();
+
+                  oStorageData.value = JSON.stringify(data);
+                  oStorageHtml.value = `<style>${editor.getCss({ component })}</style>${editor.getHtml({ component })}`;
+                }
+            });
+        };
+    }
+
+    var oBuilder = grapesjs.init({
+        container : '#__html_id__',
+        plugins: [inlineStorage, 'grapesjs-preset-newsletter'],
+        pluginsOpts: {
+            'grapesjs-preset-newsletter': {}
+        },
+        storageManager: { 
+            type: 'inline',
+            autosave: true,
+            autoload: true
+        }
+    });
+</script>

+ 10 - 1
modules/boonex/massmailer/template/css/main.css

@@ -64,4 +64,13 @@ table.dataTable thead .sorting_asc:after{ margin-left:10px;font-family: "sys-use
 table.dataTable thead .sorting_desc:after{ margin-left:10px; font-family: "sys-user", "sys-user-fal", sans-serif; content: "\f0dd"; display:inline-block}
 table.dataTable.no-footer {border-bottom:none !important}
 table.dataTable thead th{border-bottom:none !important; padding: 10px 10px !important}
-table.dataTable thead .sorting {background-image: none !important}
+table.dataTable thead .sorting {background-image: none !important}
+
+/* Campaign form */
+.bx-form-element .bx-massmailer-attrs {
+    flex-direction: row;
+}
+.bx-form-element .bx-massmailer-attrs-group {
+    margin-right: 1.0rem;
+}
+    

+ 2 - 0
modules/boonex/russian/data/langs/bx_massmailer/ru.xml

@@ -83,6 +83,8 @@
   <string name="_bx_massmailer_form_campaign_input_sys_body"><![CDATA[Тело письма]]></string>
   <string name="_bx_massmailer_form_campaign_input_body"><![CDATA[Тело письма]]></string>
   <string name="_bx_massmailer_form_campaign_input_body_err"><![CDATA[Тело письма не может быть пустым и в нем должен обязательно присутствовать маркер {unsubscribe_url}]]></string>
+  <string name="_bx_massmailer_form_campaign_input_sys_body_info"><![CDATA[Тело письма: Справка]]></string>
+  <string name="_bx_massmailer_form_campaign_input_body_info"><![CDATA[]]></string>
   <string name="_bx_massmailer_form_campaign_input_is_one_per_account"><![CDATA[Одно письмо на один аккаунт]]></string>
   <string name="_bx_massmailer_form_campaign_input_is_track_links"><![CDATA[Отслеживать клики]]></string>
   <string name="_bx_massmailer_form_campaign_input_sys_test_email"><![CDATA[Email]]></string>