[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) <gdi@odoo.com>
This commit is contained in:
Benjamin Vray
2023-12-21 16:07:47 +00:00
parent 47a6e12be3
commit 90cf5596de
2 changed files with 18 additions and 14 deletions
@@ -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
@@ -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;
}