From f6e1095c92fe6a0533b38b4a342a0f40b87cc89a Mon Sep 17 00:00:00 2001 From: Pierre-Yves Dufays Date: Mon, 7 Nov 2022 14:02:13 +0000 Subject: [PATCH] [FIX] mass_mailing: fix mobile preview The preview of a mailing was displayed twice: - after a save and when clicking on the preview button - when double-clicking on the preview button This solves those problems. Technical notes: quick explanation of the fixes: - double display after a save: the click event was registered twice (same for the code preview button), the fix unregister the click before registering it again. - double display when double-clicking quickly on the button: the modal is not displayed immediately and the button remains active a brief moment allowing a second click. The fix disables the button when the button is clicked and reenables it when the modal is closed. Task-3047479 closes odoo/odoo#105974 X-original-commit: 0403938c3e0103d97ae828afdae06fcda06bd406 Signed-off-by: Thibault Delavallee (tde) --- .../static/src/js/mass_mailing_html_field.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) 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 1c9149b4444..49015f1d3e9 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 @@ -217,6 +217,8 @@ export class MassMailingHtmlField extends HtmlField { $snippetsSideBar.find('.o_codeview_btn').hide(); } const $codeview = this.wysiwyg.$iframe.contents().find('textarea.o_codeview'); + // Unbind first the event handler as this method can be called multiple time during the component life. + $snippetsSideBar.off('click', '.o_codeview_btn'); $snippetsSideBar.on('click', '.o_codeview_btn', () => { this.wysiwyg.odooEditor.observerUnactive(); $codeview.toggleClass('d-none'); @@ -230,8 +232,10 @@ export class MassMailingHtmlField extends HtmlField { } this.onIframeUpdated(); }); - - $snippetsSideBar.on('click', '.o_mobile_preview_btn', () => { + const $previewBtn = $snippetsSideBar.find('.o_mobile_preview_btn'); + $previewBtn.off('click'); + $previewBtn.on('click', () => { + $previewBtn.prop('disabled', true); // Prevent double execution when double-clicking on the button let mailingHtml = new DOMParser().parseFromString(this.wysiwyg.getValue(), 'text/html'); [...mailingHtml.querySelectorAll('a')].forEach(el => { el.style.setProperty('pointer-events', 'none'); @@ -239,6 +243,8 @@ export class MassMailingHtmlField extends HtmlField { this.mobilePreview = this.dialog.add(MassMailingMobilePreviewDialog, { title: this.env._t("Mobile Preview"), preview: mailingHtml.body.innerHTML, + }, { + onClose: () => $previewBtn.prop('disabled', false), }); });