diff --git a/addons/mass_mailing/static/src/js/mass_mailing_html_field.js b/addons/mass_mailing/static/src/js/mass_mailing_html_field.js index b71b8dc753f..d500a383f28 100644 --- a/addons/mass_mailing/static/src/js/mass_mailing_html_field.js +++ b/addons/mass_mailing/static/src/js/mass_mailing_html_field.js @@ -104,7 +104,7 @@ export class MassMailingHtmlField extends HtmlField { this._pendingCommitChanges = (async () => { const codeViewEl = this._getCodeViewEl(); if (codeViewEl) { - this.wysiwyg.setValue(codeViewEl.value); + this.wysiwyg.setValue(this._getCodeViewValue(codeViewEl)); } if (this.wysiwyg.$iframeBody.find('.o_basic_theme').length) { @@ -248,7 +248,7 @@ export class MassMailingHtmlField extends HtmlField { this.wysiwyg.odooEditor.observerActive(); if ($codeview.hasClass('d-none')) { - this.wysiwyg.setValue($codeview.val()); + this.wysiwyg.setValue(this._getCodeViewValue($codeview[0])); this.wysiwyg.odooEditor.sanitize(); this.wysiwyg.odooEditor.historyStep(true); } else { @@ -444,6 +444,24 @@ export class MassMailingHtmlField extends HtmlField { this.wysiwyg.$iframe.contents().find('textarea.o_codeview')[0]; return codeView && !codeView.classList.contains('d-none') && codeView; } + /** + * The .o_mail_wrapper_td element is where snippets can be dropped into. + * This getter wraps the codeview value in such element in case it got + * removed during edition in the codeview, in order to preserve the snippets + * dropping functionality. + */ + _getCodeViewValue(codeViewEl) { + const editable = this.wysiwyg.$editable[0]; + const initialDropZone = editable.querySelector('.o_mail_wrapper_td'); + if (initialDropZone) { + const parsedHtml = new DOMParser().parseFromString(codeViewEl.value, "text/html"); + if (!parsedHtml.querySelector('.o_mail_wrapper_td')) { + initialDropZone.replaceChildren(...parsedHtml.body.childNodes); + return editable.innerHTML; + } + } + return codeViewEl.value; + } /** * This method will take the model in argument and will hide all mailing template * in the mass mailing widget that do not belong to this model. diff --git a/addons/mass_mailing/static/src/js/mass_mailing_wysiwyg.js b/addons/mass_mailing/static/src/js/mass_mailing_wysiwyg.js index a63b5232193..23185dd16db 100644 --- a/addons/mass_mailing/static/src/js/mass_mailing_wysiwyg.js +++ b/addons/mass_mailing/static/src/js/mass_mailing_wysiwyg.js @@ -82,18 +82,6 @@ export class MassMailingWysiwyg extends Wysiwyg { } } - /** - * @override - */ - setValue(currentValue) { - const initialDropZone = this.$editable[0].querySelector('.o_mail_wrapper_td'); - const parsedHtml = new DOMParser().parseFromString(currentValue, "text/html"); - if (initialDropZone && !parsedHtml.querySelector('.o_mail_wrapper_td')) { - initialDropZone.replaceChildren(...parsedHtml.body.childNodes); - } else { - super.setValue(...arguments); - } - } //-------------------------------------------------------------------------- // Private //-------------------------------------------------------------------------- diff --git a/addons/mass_mailing/static/tests/tours/mailing_editor_theme.js b/addons/mass_mailing/static/tests/tours/mailing_editor_theme.js index c35de1e29c5..c3c11910aed 100644 --- a/addons/mass_mailing/static/tests/tours/mailing_editor_theme.js +++ b/addons/mass_mailing/static/tests/tours/mailing_editor_theme.js @@ -18,7 +18,21 @@ registry.category("web_tour.tours").add('mailing_editor_theme', { trigger: 'button.o_list_button_add', }, { - content: "Wait for the theme selector to load and pick the basic theme.", + content: "Fill in Subject", + trigger: '#subject_0', + run: 'text Test Basic Theme', + }, + { + content: "Fill in Mailing list", + trigger: '#contact_list_ids_0', + run: 'text Newsletter', + }, + { + content: "Pick 'Newsletter' option", + trigger: '.o_input_dropdown a:contains(Newsletter)', + }, + { + content: "Pick the basic theme", trigger: 'iframe #basic', extra_trigger: 'iframe .o_mail_theme_selector_new', }, @@ -27,6 +41,47 @@ registry.category("web_tour.tours").add('mailing_editor_theme', { trigger: 'iframe html:has(#oe_snippets.d-none)', run: () => null, // no click, just check }, + { + content: "Click on the New button to create another mailing", + trigger: 'button.o_form_button_create', + }, + { + content: "Fill in Subject", + trigger: '#subject_0', + extra_trigger: 'iframe .o_mail_theme_selector_new', + run: 'text Test Newsletter Theme', + }, + { + content: "Fill in Mailing list", + trigger: '#contact_list_ids_0', + run: 'text Newsletter', + }, + { + content: "Pick 'Newsletter' option", + trigger: '.o_input_dropdown a:contains(Newsletter)', + }, + { + content: "Pick the newsletter theme", + trigger: 'iframe #newsletter', + }, + { + content: "Make sure the snippets menu is displayed", + trigger: 'iframe #oe_snippets', + run: () => null, // no click, just check + }, + { + content: 'Save form', + trigger: '.o_form_button_save', + }, + { + content: 'Go back to previous mailing', + trigger: 'button.o_pager_previous', + }, + { + content: "Make sure the snippets menu is hidden", + trigger: 'iframe html:has(#oe_snippets.d-none)', + run: () => null, + }, { content: "Add some content to be selected afterwards", trigger: 'iframe p', @@ -58,26 +113,16 @@ registry.category("web_tour.tours").add('mailing_editor_theme', { run: () => null, }, { - content: "Fill in Subject", - trigger: '[name="subject"] input', - run: 'text TestFromTour', + content: 'Save changes', + trigger: '.o_form_button_save', }, { - content: "Fill in Mailing list", - trigger: '[name="contact_list_ids"] input', - run: 'text Newsletter', - }, - { - content: "Pick 'Newsletter' option", - trigger: '.o_input_dropdown a:contains(Newsletter)', - }, - { - content: "Save and go to 'Mailings' list view", + content: "Go to 'Mailings' list view", trigger: '.breadcrumb a:contains(Mailings)' }, { content: "Open newly created mailing", - trigger: 'td:contains(TestFromTour)', + trigger: 'td:contains("Test Basic Theme")', }, { content: "Make sure the snippets menu is hidden",