Selaa lähdekoodia

Ticket #5384 - Add some way to disable visual editor.

AntonLV 6 kuukautta sitten
vanhempi
sitoutus
e2a8a25367

+ 2 - 0
install/sql/system.sql

@@ -462,6 +462,8 @@ INSERT INTO `sys_options`(`category_id`, `name`, `caption`, `value`, `type`, `ex
 (@iCategoryId, 'sys_std_show_header_right_site', '_adm_stg_cpt_option_sys_std_show_header_right_site', '', 'checkbox', '', '', '', '', 282),
 (@iCategoryId, 'sys_std_show_launcher_left', '_adm_stg_cpt_option_sys_std_show_launcher_left', '', 'checkbox', '', '', '', '', 285),
 
+(@iCategoryId, 'sys_std_pgt_etemplates_editor', '_adm_stg_cpt_option_sys_std_pgt_etemplates_editor', 'on', 'checkbox', '', '', '', '', 290),
+
 (@iCategoryId, 'sys_maintenance_mode', '_adm_stg_cpt_option_sys_maintenance_mode', '', 'checkbox', '', '', '', '', 400),
 (@iCategoryId, 'sys_maintenance_mode_html', '_adm_stg_cpt_option_sys_maintenance_mode_html', '', 'code', '', '', '', '', 402);
 

+ 2 - 0
modules/boonex/english/data/langs/system/en.xml

@@ -1398,6 +1398,7 @@
 	<string name="_adm_pgt_txt_text"><![CDATA[Text]]></string>
         <string name="_adm_pgt_txt_et_c_content"><![CDATA[Message itself will be here.]]></string>
 	<string name="_adm_pgt_txt_et_hf_inf"><![CDATA[Note, that improper use of HTML may break the email message's layout. Also make sure that {unsubscribe} marker presents in at least one of the templates (header and/or footer).]]></string>
+        <string name="_adm_pgt_btn_et_hf_editor"><![CDATA[Use visual editor]]></string>
 	<string name="_adm_pgt_btn_et_hf_submit"><![CDATA[Submit]]></string>
 	<string name="_adm_pgt_scs_et_hf_save"><![CDATA[The changes were successfully saved.]]></string>
 	<string name="_adm_pgt_err_et_hf_save"><![CDATA[Cannot save changes.]]></string>
@@ -1895,6 +1896,7 @@
     <string name="_adm_stg_cpt_option_sys_std_show_header_right_search"><![CDATA[Studio: Show search in header right]]></string>
     <string name="_adm_stg_cpt_option_sys_std_show_header_right_site"><![CDATA[Studio: Show 'site' link in header]]></string>
     <string name="_adm_stg_cpt_option_sys_std_show_launcher_left"><![CDATA[Studio: Show left area with menu in Launcher]]></string>
+    <string name="_adm_stg_cpt_option_sys_std_pgt_etemplates_editor"><![CDATA[Studio Polyglot: Enable visual editor]]></string>
     <string name="_adm_stg_cpt_option_sys_maintenance_mode"><![CDATA[Maintenance mode]]></string>
     <string name="_adm_stg_cpt_option_sys_maintenance_mode_html"><![CDATA[Maintenance mode custom HTML code]]></string>
 

+ 3 - 0
modules/boonex/russian/data/langs/system/ru.xml

@@ -1380,6 +1380,7 @@
 	<string name="_adm_pgt_txt_text"><![CDATA[Текст]]></string>
         <string name="_adm_pgt_txt_et_c_content"><![CDATA[Само сообщение будет здесь.]]></string>
         <string name="_adm_pgt_txt_et_hf_inf"><![CDATA[Внимание. Неправильное применение HTML может повредить дизайн email сообщения. Также убедитесь в том, что маркер {unsubscribe} присутствует хотя бы в одном из темплейтов (заголовок и/или основание).]]></string>
+        <string name="_adm_pgt_btn_et_hf_editor"><![CDATA[Использовать визуальный редактор]]></string>
         <string name="_adm_pgt_btn_et_hf_submit"><![CDATA[Выполнить]]></string>
         <string name="_adm_pgt_scs_et_hf_save"><![CDATA[Изменения сохранены.]]></string>
         <string name="_adm_pgt_err_et_hf_save"><![CDATA[Невозможно сохранить изменения.]]></string>
@@ -1870,6 +1871,8 @@
     <string name="_adm_stg_cpt_option_sys_std_show_header_right_search"><![CDATA[Студия: Показать поиск в заголовке справа]]></string>
     <string name="_adm_stg_cpt_option_sys_std_show_header_right_site"><![CDATA[Студия: Показывать ссылку 'сайт' в заголовке]]></string>
     <string name="_adm_stg_cpt_option_sys_std_show_launcher_left"><![CDATA[Студия: Показать левую область с меню в лаунчере]]></string>
+    <string name="_adm_stg_cpt_option_sys_std_pgt_etemplates_editor"><![CDATA[Полиглот в Студии: Включить визуальный редактор]]></string>
+
     <string name="_adm_stg_cpt_option_sys_maintenance_mode"><![CDATA[Режим технического обслуживания]]></string>
     <string name="_adm_stg_cpt_option_sys_maintenance_mode_html"><![CDATA[Пользовательский HTML-код для режима обслуживания]]></string>
     

+ 18 - 5
studio/classes/BxDolStudioPolyglot.php

@@ -18,6 +18,7 @@ class BxDolStudioPolyglot extends BxTemplStudioWidget
 {
     protected $sPage;
 
+    protected $sEtSettingEditor;
     protected $sEtcContent;
 
     function __construct($sPage = "")
@@ -30,6 +31,7 @@ class BxDolStudioPolyglot extends BxTemplStudioWidget
         if(is_string($sPage) && !empty($sPage))
             $this->sPage = $sPage;
 
+        $this->sEtSettingEditor = 'sys_std_pgt_etemplates_editor';
         $this->sEtcContent = '<pre id="etc_content">' . _t('_adm_pgt_txt_et_c_content') . '</pre>';
     }
 
@@ -48,12 +50,23 @@ class BxDolStudioPolyglot extends BxTemplStudioWidget
             case 'get-page-by-type':
                 $sValue = bx_process_input(bx_get('pgt_value'));
                 if(empty($sValue))
-                        break;
+                    break;
 
                 $this->sPage = $sValue;
                 $aResult = array('code' => 0, 'content' => $this->getPageCode());
                 break;
 
+            case 'enable-editor':
+                $iValue = false;
+                if(($iValue = bx_get('pgt_value')) !== false)
+                    $iValue = bx_process_input($iValue, BX_DATA_INT);
+                else
+                    break;
+
+                if(setParam($this->sEtSettingEditor, $iValue ? 'on' : ''))
+                    $aResult = ['code' => 0, 'reload' => 1];
+                break;
+
             /*
              * Available URL params:
              * pgt_action = recompile - action name
@@ -63,9 +76,9 @@ class BxDolStudioPolyglot extends BxTemplStudioWidget
                 $sLanguage = bx_process_input(bx_get('pgt_language'));
 
                 if($oLanguages->compileLanguage($sLanguage))
-                        $aResult = array('code' => 0, 'content' => _t('_adm_pgt_scs_recompiled'));
+                    $aResult = array('code' => 0, 'content' => _t('_adm_pgt_scs_recompiled'));
                 else
-                        $aResult = array('code' => 2, 'content' => _t('_adm_pgt_err_cannot_recompile_lang'));
+                    $aResult = array('code' => 2, 'content' => _t('_adm_pgt_err_cannot_recompile_lang'));
                 break;
 
             /*
@@ -79,9 +92,9 @@ class BxDolStudioPolyglot extends BxTemplStudioWidget
                 $sModule = bx_process_input(bx_get('pgt_module'));
 
                 if($oLanguages->restoreLanguage($sLanguage, $sModule))
-                        $aResult = array('code' => 0, 'content' => _t('_adm_pgt_scs_restored'));
+                    $aResult = array('code' => 0, 'content' => _t('_adm_pgt_scs_restored'));
                 else
-                        $aResult = array('code' => 2, 'content' => _t('_adm_pgt_err_cannot_restore_lang'));
+                    $aResult = array('code' => 2, 'content' => _t('_adm_pgt_err_cannot_restore_lang'));
                 break;
         }
 

+ 50 - 50
studio/js/polyglot.js

@@ -6,73 +6,73 @@
  * @{
  */
 function BxDolStudioPolyglot(oOptions) {
-	this.sActionsUrl = oOptions.sActionUrl;
+    this.sActionsUrl = oOptions.sActionUrl;
     this.sObjName = oOptions.sObjName == undefined ? 'oBxDolStudioPolyglot' : oOptions.sObjName;
     this.sAnimationEffect = oOptions.sAnimationEffect == undefined ? 'fade' : oOptions.sAnimationEffect;
     this.iAnimationSpeed = oOptions.iAnimationSpeed == undefined ? 'slow' : oOptions.iAnimationSpeed;
     this.sCodeMirror = oOptions.sCodeMirror == undefined ? '' : oOptions.sCodeMirror;
     this.sPage = oOptions.sPage == undefined ? 'general' : oOptions.sPage;
-
-    var $this = this;
-    $(document).ready (function () {
-    	if($this.sCodeMirror != '')
-    		$this.initCodeMirror($this.sCodeMirror);
-    });
 }
 
-BxDolStudioPolyglot.prototype.initCodeMirror = function(sSelector) {
-	var oSelector = $(sSelector);
-	for(var i = 0; i < oSelector.length; i++) {
-	    var e = CodeMirror.fromTextArea(oSelector.get(i), {
-	        lineNumbers: true,
-	        mode: "htmlmixed",
-	        htmlMode: true,
-	        matchBrackets: true
-	    });
-	}
+BxDolStudioPolyglot.prototype.enableEditor = function(oSource) {
+    var oDate = new Date();
+
+    $.post(
+        this.sActionsUrl, {
+            pgt_action: 'enable-editor',
+            pgt_value: $(oSource).prop('checked') ? 1 : 0,
+            _t:oDate.getTime()
+        },
+        function(oData) {
+            processJsonData(oData);
+        },
+        'json'
+    );
+
+    return true;
 };
 
 /**
  * Is needed if AJAX is used to change (reload) pages. 
  */
 BxDolStudioPolyglot.prototype.changePage = function(sType, iStart, iLength) {
-	var oDate = new Date();
-	var $this = this;
-	var oParams = {
-		pgt_action: 'get-page-by-type',
-		pgt_value: sType,
-		_t:oDate.getTime()
-	};
+    var oDate = new Date();
+    var $this = this;
+    var oParams = {
+        pgt_action: 'get-page-by-type',
+        pgt_value: sType,
+        _t:oDate.getTime()
+    };
 
-	if(sType == 'keys') {
-		oParams.pgt_category = $('#pgt-keys-category').val();
-		oParams.pgt_language = $('#pgt-keys-language').val();
-		oParams.pgt_keyword = $('#pgt-keys-keyword').val();
-		if(iStart)
-			oParams.pgt_start = iStart;
-		if(iLength)
-			oParams.pgt_length = iLength;
-	}
+    if(sType == 'keys') {
+        oParams.pgt_category = $('#pgt-keys-category').val();
+        oParams.pgt_language = $('#pgt-keys-language').val();
+        oParams.pgt_keyword = $('#pgt-keys-keyword').val();
+        if(iStart)
+            oParams.pgt_start = iStart;
+        if(iLength)
+            oParams.pgt_length = iLength;
+    }
 
-	$.get(
-		this.sActionsUrl,
-		oParams,
-		function(oData) {
-			if(oData.code != 0) {
-				bx_alert(oData.message);
-				return true;
-			}
+    $.get(
+        this.sActionsUrl,
+        oParams,
+        function(oData) {
+            if(oData.code != 0) {
+                bx_alert(oData.message);
+                return true;
+            }
 
-			$('#bx-std-pc-menu > .bx-std-pmi-active').removeClass('bx-std-pmi-active');
-			$('#bx-std-pmi-' + sType).addClass('bx-std-pmi-active');
+            $('#bx-std-pc-menu > .bx-std-pmi-active').removeClass('bx-std-pmi-active');
+            $('#bx-std-pmi-' + sType).addClass('bx-std-pmi-active');
 
-			$('#bx-std-pc-content').bx_anim('hide', $this.sAnimationEffect, $this.iAnimationSpeed, function() {
-				$(this).html(oData.content).bx_anim('show', $this.sAnimationEffect, $this.iAnimationSpeed);
-			});
-		},
-		'json'
-	);
+            $('#bx-std-pc-content').bx_anim('hide', $this.sAnimationEffect, $this.iAnimationSpeed, function() {
+                $(this).html(oData.content).bx_anim('show', $this.sAnimationEffect, $this.iAnimationSpeed);
+            });
+        },
+        'json'
+    );
 
-	return true;
+    return true;
 };
 /** @} */

+ 58 - 29
studio/template/scripts/BxBaseStudioPolyglot.php

@@ -100,69 +100,82 @@ class BxBaseStudioPolyglot extends BxDolStudioPolyglot
         return $this->getGrid($this->aGridObjects['etemplates']);
     }
 
-    /**
-     * TODO: Remove (after UNA 14) if new version is working fine.
-     */
-    protected function getEtemplatesHtmlOld()
+    protected function getEtemplatesHtml()
+    {
+        return $this->{'_getEtemplatesHtml' . ($this->isEtEditor() ? 'Editor' : 'Form')}();
+    }
+
+    protected function _getEtemplatesHtmlForm()
     {
         $oTemplate = BxDolStudioTemplate::getInstance();
 
         $sFormId = 'adm-dsg-et-hf-form';
         $sIFrameId = 'adm-dsg-et-hf-iframe';
 
-        $aForm = array(
-            'form_attrs' => array(
+        $aForm = [
+            'form_attrs' => [
                 'id' => $sFormId,
                 'name' => $sFormId,
                 'action' => BX_DOL_URL_STUDIO . 'polyglot.php',
                 'method' => 'post',
                 'enctype' => 'multipart/form-data',
                 'target' => $sIFrameId
-            ),
-            'params' => array(
-                'db' => array(
+            ],
+            'params' => [
+                'db' => [
                     'table' => '',
                     'key' => '',
                     'uri' => '',
                     'uri_title' => '',
                     'submit_name' => 'save'
-                ),
-            ),
-            'inputs' => array(
-                'page' => array(
+                ],
+            ],
+            'inputs' => [
+                'page' => [
                     'type' => 'hidden',
                     'name' => 'page',
                     'value' => $this->sPage
-                ),
-                'et_hf_header' => array(
+                ],
+                'editor' => [
+                    'type' => 'switcher',
+                    'name' => 'editor',
+                    'caption' => _t('_adm_pgt_btn_et_hf_editor'),
+                    'info' => '',
+                    'value' => 'on',
+                    'checked' => $this->isEtEditor(),
+                    'attrs' => [
+                        'onchange' => $this->getPageJsObject() . '.enableEditor(this)'
+                    ]
+                ],
+                'et_hf_header' => [
                     'type' => 'textarea',
                     'code' => true,
                     'name' => 'et_hf_header',
                     'caption' => _t('_adm_stg_cpt_option_site_email_html_template_header'),
                     'info' => _t('_adm_pgt_txt_et_hf_inf'),
                     'value' => getParam('site_email_html_template_header'),
-                    'db' => array (
+                    'db' => [
                         'pass' => 'Xss',
-                    ),
-                ),
-                'et_hf_footer' => array(
+                    ],
+                ],
+                'et_hf_footer' => [
                     'type' => 'textarea',
                     'code' => true,
                     'name' => 'et_hf_footer',
                     'caption' => _t('_adm_stg_cpt_option_site_email_html_template_footer'),
                     'info' => _t('_adm_pgt_txt_et_hf_inf'),
                     'value' => getParam('site_email_html_template_footer'),
-                    'db' => array (
+                    'db' => [
                         'pass' => 'Xss',
-                    ),
-                ),
-                'save' => array(
+                    ],
+                ],
+                'save' => [
                     'type' => 'submit',
                     'name' => 'save',
                     'value' => _t('_adm_pgt_btn_et_hf_submit'),
-                )
-            )
-        );
+                ]
+            ]
+        ];
 
         $oForm = new BxTemplStudioFormView($aForm, $oTemplate);
         $oForm->initChecker();
@@ -171,10 +184,10 @@ class BxBaseStudioPolyglot extends BxDolStudioPolyglot
             echo $this->submitEtemplatesHtmlOld($oForm);
             exit;
         }
-
+/*
         $oTemplate->addJs(array('codemirror/codemirror.min.js'));
         $oTemplate->addCss(BX_DIRECTORY_PATH_PLUGINS_PUBLIC . 'codemirror/|codemirror.css');
-
+*/
         return $oTemplate->parseHtmlByName('polyglot.html', array(
             'content' => $oTemplate->parseHtmlByName('pgt_etemplates_hf.html', array(
                 'warning' => '',
@@ -187,7 +200,7 @@ class BxBaseStudioPolyglot extends BxDolStudioPolyglot
         ));
     }
 
-    protected function getEtemplatesHtml()
+    protected function _getEtemplatesHtmlEditor()
     {
         $oTemplate = BxDolStudioTemplate::getInstance();
 
@@ -223,6 +236,17 @@ class BxBaseStudioPolyglot extends BxDolStudioPolyglot
                     'name' => 'page',
                     'value' => $this->sPage
                 ],
+                'editor' => [
+                    'type' => 'switcher',
+                    'name' => 'editor',
+                    'caption' => _t('_adm_pgt_btn_et_hf_editor'),
+                    'info' => '',
+                    'value' => 'on',
+                    'checked' => $this->isEtEditor(),
+                    'attrs' => [
+                        'onchange' => $this->getPageJsObject() . '.enableEditor(this)'
+                    ]
+                ],
                 'content' => [
                     'type' => 'custom',
                     'name' => 'content',
@@ -286,6 +310,11 @@ class BxBaseStudioPolyglot extends BxDolStudioPolyglot
             'js_content' => ''
         ));
     }
+
+    protected function isEtEditor()
+    {
+        return getParam($this->sEtSettingEditor) == 'on';
+    }
 }
 
 /** @} */