[FIX] website_mass_mailing: improve configuration usability
1. The option to change newsletter becomes a select instead of a button that open a modal 2. If no mailing list exists, we show a warning and user can be redirected to the backend to create one if he wants. 3. Add name to the snippet so it is not "Block" in the right panel Community: https://github.com/odoo/odoo/pull/74667 Upgrade: https://github.com/odoo/upgrade/pull/2742 task-2246975 closes odoo/odoo#74667 Related: odoo/upgrade#2742 Signed-off-by: Romain Derie <rdeodoo@users.noreply.github.com>
This commit is contained in:
@@ -33,23 +33,12 @@ for (const snippet of snippetsNames) {
|
||||
content: 'Close API Key popup',
|
||||
trigger: ".modal-footer .btn-secondary",
|
||||
});
|
||||
} else if (snippet === 's_popup') {
|
||||
} else if (['s_popup', 's_newsletter_subscribe_popup'].includes(snippet)) {
|
||||
snippetSteps[2]['in_modal'] = false;
|
||||
snippetSteps.splice(3, 2, {
|
||||
content: `Hide the ${snippet} popup`,
|
||||
trigger: ".s_popup_close",
|
||||
});
|
||||
} else if (['s_newsletter_block', 's_newsletter_subscribe_form', 's_newsletter_subscribe_popup'].includes(snippet)) {
|
||||
snippetSteps.splice(1, 0, {
|
||||
content: `Confirm the ${snippet} popup`,
|
||||
trigger: `.modal-footer button.btn-primary`,
|
||||
});
|
||||
}
|
||||
if (snippet === 's_newsletter_subscribe_popup') {
|
||||
snippetSteps.splice(3, 2, {
|
||||
content: `Hide the ${snippet} popup`,
|
||||
trigger: "button.close",
|
||||
});
|
||||
}
|
||||
steps = steps.concat(snippetSteps);
|
||||
}
|
||||
|
||||
@@ -2,65 +2,63 @@ odoo.define('website_mass_mailing.editor', function (require) {
|
||||
'use strict';
|
||||
|
||||
var core = require('web.core');
|
||||
var rpc = require('web.rpc');
|
||||
const Dialog = require('web.Dialog');
|
||||
var options = require('web_editor.snippets.options');
|
||||
var wUtils = require('website.utils');
|
||||
|
||||
const qweb = core.qweb;
|
||||
var _t = core._t;
|
||||
|
||||
|
||||
options.registry.mailing_list_subscribe = options.Class.extend({
|
||||
popup_template_id: "editor_new_mailing_list_subscribe_button",
|
||||
popup_title: _t("Add a Newsletter Subscribe Button"),
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Options
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Allows to select mailing list.
|
||||
*
|
||||
* @see this.selectClass for parameters
|
||||
*/
|
||||
select_mailing_list: function (previewMode, value) {
|
||||
var self = this;
|
||||
var def = wUtils.prompt({
|
||||
'id': this.popup_template_id,
|
||||
'window_title': this.popup_title,
|
||||
'select': _t("Newsletter"),
|
||||
'init': function (field, dialog) {
|
||||
return rpc.query({
|
||||
model: 'mailing.list',
|
||||
method: 'name_search',
|
||||
args: ['', [['is_public', '=', true]]],
|
||||
context: self.options.recordInfo.context,
|
||||
}).then(function (data) {
|
||||
$(dialog).find('.btn-primary').prop('disabled', !data.length);
|
||||
var list_id = self.$target.attr("data-list-id");
|
||||
$(dialog).on('show.bs.modal', function () {
|
||||
if (list_id !== "0"){
|
||||
$(dialog).find('select').val(list_id);
|
||||
};
|
||||
});
|
||||
return data;
|
||||
});
|
||||
},
|
||||
});
|
||||
def.then(function (result) {
|
||||
self.$target.attr("data-list-id", result.val);
|
||||
});
|
||||
return def;
|
||||
},
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
onBuilt: function () {
|
||||
var self = this;
|
||||
this._super();
|
||||
this.select_mailing_list('click').guardedCatch(function () {
|
||||
self.getParent()._onRemoveClick($.Event( "click" ));
|
||||
onBuilt() {
|
||||
this._super(...arguments);
|
||||
if (this.mailingLists.length) {
|
||||
this.$target.attr("data-list-id", this.mailingLists[0][0]);
|
||||
} else {
|
||||
Dialog.confirm(this, _t("No mailing list found, do you want to create a new one? This will save all your changes, are you sure you want to proceed?"), {
|
||||
confirm_callback: () => {
|
||||
this.trigger_up('request_save', {
|
||||
reload: false,
|
||||
onSuccess: () => {
|
||||
window.location.href = '/web#action=mass_mailing.action_view_mass_mailing_lists';
|
||||
},
|
||||
});
|
||||
},
|
||||
cancel_callback: () => {
|
||||
this.trigger_up('remove_snippet', {
|
||||
$snippet: this.$target,
|
||||
});
|
||||
},
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Private
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
async _renderCustomXML(uiFragment) {
|
||||
this.mailingLists = await this._rpc({
|
||||
model: 'mailing.list',
|
||||
method: 'name_search',
|
||||
args: ['', [['is_public', '=', true]]],
|
||||
context: this.options.recordInfo.context,
|
||||
});
|
||||
if (this.mailingLists.length) {
|
||||
const selectEl = uiFragment.querySelector('we-select[data-attribute-name="listId"]');
|
||||
for (const mailingList of this.mailingLists) {
|
||||
const button = document.createElement('we-button');
|
||||
button.dataset.selectDataAttribute = mailingList[0];
|
||||
button.textContent = mailingList[1];
|
||||
selectEl.appendChild(button);
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -12,10 +12,6 @@ tour.register('newsletter_popup_edition', {
|
||||
id: 's_newsletter_subscribe_popup',
|
||||
name: 'Newsletter Popup',
|
||||
}),
|
||||
{
|
||||
content: "Confirm newsletter choice",
|
||||
trigger: '.modal-footer .btn-primary',
|
||||
},
|
||||
{
|
||||
content: "Check the modal is opened for edition",
|
||||
trigger: '.o_newsletter_popup .modal:visible',
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
</template>
|
||||
|
||||
<template id="s_newsletter_subscribe_form" name="Newsletter">
|
||||
<div class="s_newsletter_subscribe_form js_subscribe" data-vxml="001" data-list-id="0">
|
||||
<div class="s_newsletter_subscribe_form js_subscribe" data-vxml="001" data-list-id="0" data-name="Newsletter Form">
|
||||
<div class="input-group">
|
||||
<input type="email" name="email" class="js_subscribe_email form-control" placeholder="your email..."/>
|
||||
<span class="input-group-append">
|
||||
@@ -87,7 +87,7 @@
|
||||
<t t-set="selector" t-value="'.js_subscribe'"/>
|
||||
<div data-js="mailing_list_subscribe"
|
||||
t-att-data-selector="selector">
|
||||
<we-button data-select_mailing_list="" data-no-preview="true">Change Newsletter</we-button>
|
||||
<we-select string="Newsletter" data-attribute-name="listId"></we-select>
|
||||
</div>
|
||||
<div data-js="recaptchaSubscribe"
|
||||
t-att-data-selector="selector">
|
||||
|
||||
Reference in New Issue
Block a user