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 f4bef9c5c58..04d3da76fc6 100644 --- a/addons/mass_mailing/static/src/js/mass_mailing_widget.js +++ b/addons/mass_mailing/static/src/js/mass_mailing_widget.js @@ -298,6 +298,24 @@ var MassMailingFieldHtml = FieldHtml.extend({ this.wysiwyg.trigger('reload_snippet_dropzones'); }, + /** + * Toggle the code view. + */ + _toggleCodeView: function () { + this.wysiwyg.odooEditor.observerUnactive(); + const $codeview = this.$content.parent().find('textarea.o_codeview'); + $codeview.toggleClass('d-none'); + this.$content.toggleClass('d-none'); + if ($codeview.hasClass('d-none')) { + this.wysiwyg.odooEditor.observerActive(); + this.wysiwyg.setValue($codeview.val()); + this.wysiwyg.odooEditor.historyStep(); + } else { + $codeview.val(this.$content.html()); + this.wysiwyg.odooEditor.observerActive(); + } + }, + /** * @override */ @@ -338,7 +356,8 @@ var MassMailingFieldHtml = FieldHtml.extend({ var $snippetsSideBar = ev.data; var $themes = $snippetsSideBar.find("#email_designer_themes").children(); var $snippets = $snippetsSideBar.find(".oe_snippet"); - $snippetsSideBar.find('.o_we_website_top_actions>*:not(.o_we_external_history_buttons)').hide(); + var selectorToKeep = '.o_we_external_history_buttons, .email_designer_top_actions'; + $snippetsSideBar.find(`.o_we_website_top_actions>*:not(${selectorToKeep})`).hide(); var $snippets_menu = $snippetsSideBar.find("#snippets_menu"); var $selectTemplateBtn = $snippets_menu.find('.o_we_select_template'); @@ -347,6 +366,12 @@ var MassMailingFieldHtml = FieldHtml.extend({ this.$content.attr('style', 'padding-left: 0px !important'); } + if (!odoo.debug) { + $snippetsSideBar.find('.o_codeview_btn').hide(); + } + + $snippetsSideBar.on('click', '.o_codeview_btn', this._toggleCodeView.bind(this)); + if ($themes.length === 0) { return; } diff --git a/addons/mass_mailing/views/snippets_themes.xml b/addons/mass_mailing/views/snippets_themes.xml index 87c3c6498c7..a542c037e95 100644 --- a/addons/mass_mailing/views/snippets_themes.xml +++ b/addons/mass_mailing/views/snippets_themes.xml @@ -2,11 +2,18 @@