[IMP] (website_)mass_mailing: allows subscribing through the form snippet
PURPOSE This commit adds the possibility the create a subscribing form from the form snippet, it creates default inputs automatically. LINKS Task-2672194 Part-of: odoo/odoo#79582
This commit is contained in:
@@ -12,6 +12,7 @@ On a simple click, your visitors can subscribe to mailing lists managed in the E
|
||||
'category': 'Website/Website',
|
||||
'depends': ['website', 'mass_mailing', 'google_recaptcha'],
|
||||
'data': [
|
||||
'data/ir_model_data.xml',
|
||||
'views/snippets/s_popup.xml',
|
||||
'views/snippets_templates.xml',
|
||||
],
|
||||
@@ -26,6 +27,9 @@ On a simple click, your visitors can subscribe to mailing lists managed in the E
|
||||
'website_mass_mailing/static/src/scss/website_mass_mailing_edit_mode.scss',
|
||||
'website_mass_mailing/static/src/snippets/s_popup/options.js',
|
||||
],
|
||||
'website.assets_editor': [
|
||||
'website_mass_mailing/static/src/js/mass_mailing_form_editor.js',
|
||||
],
|
||||
'web.assets_tests': [
|
||||
'website_mass_mailing/static/tests/**/*',
|
||||
],
|
||||
|
||||
@@ -2,3 +2,4 @@
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from . import main
|
||||
from . import website_form
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
import json
|
||||
|
||||
from odoo import _
|
||||
from odoo.http import request
|
||||
from odoo.addons.website.controllers.form import WebsiteForm
|
||||
|
||||
|
||||
class WebsiteNewsletterForm(WebsiteForm):
|
||||
|
||||
def _handle_website_form(self, model_name, **kwargs):
|
||||
if model_name == 'mailing.contact':
|
||||
list_ids = [int(x) for x in kwargs['list_ids'].split(',')]
|
||||
private_list_ids = request.env['mailing.list'].search([
|
||||
('id', 'in', list_ids), ('is_public', '=', False)])
|
||||
if private_list_ids:
|
||||
return json.dumps({
|
||||
'error': _('You cannot subscribe to the following list anymore : %s',
|
||||
', '.join(private_list_ids.mapped('name')))
|
||||
})
|
||||
return super()._handle_website_form(model_name, **kwargs)
|
||||
@@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
<data>
|
||||
<record id="mass_mailing.model_mailing_contact" model="ir.model">
|
||||
<field name="website_form_key">create_mailing_contact</field>
|
||||
<field name="website_form_access">True</field>
|
||||
<field name="website_form_label">Subscribe to Newsletter</field>
|
||||
</record>
|
||||
|
||||
<function model="ir.model.fields" name="formbuilder_whitelist">
|
||||
<value>mailing.contact</value>
|
||||
<value eval="[
|
||||
'name',
|
||||
'company_name',
|
||||
'title_id',
|
||||
'email',
|
||||
'list_ids',
|
||||
'country_id',
|
||||
'tag_ids',
|
||||
]"/>
|
||||
</function>
|
||||
</data>
|
||||
</odoo>
|
||||
@@ -0,0 +1,26 @@
|
||||
/** @odoo-module **/
|
||||
|
||||
import core from "web.core";
|
||||
import FormEditorRegistry from "website.form_editor_registry";
|
||||
|
||||
const _t = core._t;
|
||||
|
||||
FormEditorRegistry.add('create_mailing_contact', {
|
||||
formFields: [{
|
||||
name: 'name',
|
||||
required: true,
|
||||
string: _t('Your Name'),
|
||||
type: 'char',
|
||||
}, {
|
||||
name: 'email',
|
||||
required: true,
|
||||
string: _t('Your Email'),
|
||||
type: 'email',
|
||||
}, {
|
||||
name: 'list_ids',
|
||||
relation: 'mailing.list',
|
||||
required: true,
|
||||
string: _t('Subscribe to'),
|
||||
type: 'many2many',
|
||||
}],
|
||||
});
|
||||
Reference in New Issue
Block a user