From 90cf5596dea29d88fee9fa5cbee4a6403decfa96 Mon Sep 17 00:00:00 2001 From: Benjamin Vray Date: Thu, 7 Dec 2023 14:40:37 +0100 Subject: [PATCH] [FIX] website_mass_mailing: fix display thanks button on form newsletter Steps to reproduce the issue: - In website edit mode, add newsletter block onto the page. - In the options of the snippet, change the template to "form". - Click on the "Display Thanks Button" checkbox. - => Traceback. In this commit [1], a button has been added to the options of the "Newsletter Block" snippet to allow the user to display the "thanks" button in edit mode to be able to edit it. Later, in another commit [2], a new "Form" template was added to the "Newsletter Block" snippet, but the "Display Thanks Button" option was not adapted for it. This commit adapts the "Display Thanks Button" option for the "Form" template of the "Newsletter Block" snippet so that it displays the thank you message on the page, and the user can also edit it. [1]: https://github.com/odoo/odoo/commit/a9eae10af88a0aba88ce6d3e3f517926edf36c00 [2]: https://github.com/odoo/odoo/commit/bd6ef64f4c79b9c04dc8b85dc2daccb61d55cad0 task-3610063 closes odoo/odoo#146867 X-original-commit: ccf338c67219b10fe86b15012e143a84c886654f Signed-off-by: Guillaume Dieleman (gdi) --- .../src/js/website_mass_mailing.editor.js | 29 ++++++++++--------- .../scss/website_mass_mailing_edit_mode.scss | 3 +- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/addons/website_mass_mailing/static/src/js/website_mass_mailing.editor.js b/addons/website_mass_mailing/static/src/js/website_mass_mailing.editor.js index 42412c80f02..0454a2f819b 100644 --- a/addons/website_mass_mailing/static/src/js/website_mass_mailing.editor.js +++ b/addons/website_mass_mailing/static/src/js/website_mass_mailing.editor.js @@ -43,10 +43,12 @@ options.registry.mailing_list_subscribe = options.Class.extend({ */ cleanForSave() { const previewClasses = ['o_disable_preview', 'o_enable_preview']; - const subscribeBtn = this.$target[0].querySelector('.js_subscribe_btn'); - subscribeBtn && subscribeBtn.classList.remove(...previewClasses); - const subscribedBtn = this.$target[0].querySelector('.js_subscribed_btn'); - subscribedBtn && subscribedBtn.classList.remove(...previewClasses); + const toCleanElsSelector = + ".js_subscribe_btn, .js_subscribed_btn, #newsletter_form, .s_website_form_end_message"; + const toCleanEls = this.$target[0].querySelectorAll(toCleanElsSelector); + toCleanEls.forEach(element => { + element.classList.remove(...previewClasses); + }); }, //-------------------------------------------------------------------------- @@ -57,13 +59,14 @@ options.registry.mailing_list_subscribe = options.Class.extend({ * @see this.selectClass for parameters */ toggleThanksButton(previewMode, widgetValue, params) { - const subscribeBtnEl = this.$target[0].querySelector('.js_subscribe_btn'); - const thanksBtnEl = this.$target[0].querySelector('.js_subscribed_btn'); + const toSubscribeEl = this.$target[0].querySelector(".js_subscribe_btn, #newsletter_form"); + const thanksMessageEl = + this.$target[0].querySelector(".js_subscribed_btn, .s_website_form_end_message"); - thanksBtnEl.classList.toggle('o_disable_preview', !widgetValue); - thanksBtnEl.classList.toggle('o_enable_preview', widgetValue); - subscribeBtnEl.classList.toggle('o_enable_preview', !widgetValue); - subscribeBtnEl.classList.toggle('o_disable_preview', widgetValue); + thanksMessageEl.classList.toggle("o_disable_preview", !widgetValue); + thanksMessageEl.classList.toggle("o_enable_preview", widgetValue); + toSubscribeEl.classList.toggle("o_enable_preview", !widgetValue); + toSubscribeEl.classList.toggle("o_disable_preview", widgetValue); }, //-------------------------------------------------------------------------- @@ -77,9 +80,9 @@ options.registry.mailing_list_subscribe = options.Class.extend({ if (methodName !== 'toggleThanksButton') { return this._super(...arguments); } - const subscribeBtnEl = this.$target[0].querySelector('.js_subscribe_btn'); - return subscribeBtnEl && subscribeBtnEl.classList.contains('o_disable_preview') ? - 'true' : ''; + const toSubscribeElSelector = + ".js_subscribe_btn.o_disable_preview, #newsletter_form.o_disable_preview"; + return this.$target[0].querySelector(toSubscribeElSelector) ? "true" : ""; }, /** * @override diff --git a/addons/website_mass_mailing/static/src/scss/website_mass_mailing_edit_mode.scss b/addons/website_mass_mailing/static/src/scss/website_mass_mailing_edit_mode.scss index f1995ed3eac..6797c017ffd 100644 --- a/addons/website_mass_mailing/static/src/scss/website_mass_mailing_edit_mode.scss +++ b/addons/website_mass_mailing/static/src/scss/website_mass_mailing_edit_mode.scss @@ -1,5 +1,6 @@ body.editor_enable { - .s_newsletter_subscribe_form { + .s_newsletter_subscribe_form, + .s_newsletter_block[data-newsletter-template="form"] { .o_enable_preview { display: block !important; }