From 1158e7f99fb2fd63c5db1aa082e345500cd51acb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Geelen=20=28sge=29?= Date: Wed, 21 Apr 2021 09:19:55 +0000 Subject: [PATCH] [FIX] web_editor, mass_mailing: remove snippets from plain text mail --- .../static/src/js/mass_mailing_widget.js | 26 ++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/addons/mass_mailing/static/src/js/mass_mailing_widget.js b/addons/mass_mailing/static/src/js/mass_mailing_widget.js index 04d3da76fc6..f604afe79a0 100644 --- a/addons/mass_mailing/static/src/js/mass_mailing_widget.js +++ b/addons/mass_mailing/static/src/js/mass_mailing_widget.js @@ -19,6 +19,7 @@ var MassMailingFieldHtml = FieldHtml.extend({ custom_events: _.extend({}, FieldHtml.prototype.custom_events, { snippets_loaded: '_onSnippetsLoaded', }), + _wysiwygSnippetsActive: true, /** * @override @@ -137,6 +138,7 @@ var MassMailingFieldHtml = FieldHtml.extend({ */ _renderEdit: function () { this._isFromInline = !!this.value; + this._wysiwygSnippetsActive = !(this._isFromInline && $(this.value).is('.o_layout.o_basic_theme')); if (!this.value) { this.value = this.recordData[this.nodeOptions['inline-field']]; } @@ -291,7 +293,7 @@ var MassMailingFieldHtml = FieldHtml.extend({ return this.nodeType === 3 && this.textContent.match(/\S/); }).parent().addClass('o_default_snippet_text'); - if (themeParams.name == 'basic') { + if (themeParams.name === 'basic') { this.$content[0].focus(); } } @@ -322,6 +324,9 @@ var MassMailingFieldHtml = FieldHtml.extend({ _getWysiwygOptions: function () { const options = this._super.apply(this, arguments); options.resizable = false; + if (!this._wysiwygSnippetsActive) { + delete options.snippets; + } return options; }, @@ -343,6 +348,16 @@ var MassMailingFieldHtml = FieldHtml.extend({ this.wysiwyg.odooEditor.observerFlush(); this.wysiwyg.odooEditor.resetHistory(); }, + /** + * @private + * @param {boolean} activateSnippets + */ + _restartWysiwygIntance: async function (activateSnippets = true) { + this.wysiwyg.destroy(); + this.$el.empty(); + this._wysiwygSnippetsActive = activateSnippets; + await this._createWysiwygIntance(); + }, /** * @private * @param {OdooEvent} ev @@ -479,13 +494,16 @@ var MassMailingFieldHtml = FieldHtml.extend({ }; $themeSelector.on("click", ".dropdown-item", selectTheme); - $themeSelectorNew.on("click", ".dropdown-item", (e) => { + $themeSelectorNew.on("click", ".dropdown-item", async (e) => { e.preventDefault(); e.stopImmediatePropagation(); const themeParams = themesParams[$(e.currentTarget).index()]; - self._switchThemes(true, themeParams); - self.$content.closest('body').removeClass("o_force_mail_theme_choice"); + if (themeParams.name === "basic") { + await this._restartWysiwygIntance(false); + } + this._switchThemes(true, themeParams); + this.$content.closest('body').removeClass("o_force_mail_theme_choice"); $themeSelectorNew.remove();