[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) <tde@openerp.com>
This commit is contained in:
@@ -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),
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user