[MERGE] [ADD] mass_mailing: add a snippet to allow subscribing to a contact list (newsletter). Also cleaned the wording of the snippet allowing to subscribe do a discussion group to avoid confusion.
bzr revid: tde@openerp.com-20140509135051-tt1blzojwtpt86lr
This commit is contained in:
commit
b9c62c7adb
|
@ -48,6 +48,8 @@ professional emails and reuse templates in a few clicks.
|
||||||
'views/res_config.xml',
|
'views/res_config.xml',
|
||||||
'views/res_partner.xml',
|
'views/res_partner.xml',
|
||||||
'views/email_template.xml',
|
'views/email_template.xml',
|
||||||
|
'views/website_mass_mailing.xml',
|
||||||
|
'views/snippets.xml',
|
||||||
'security/ir.model.access.csv',
|
'security/ir.model.access.csv',
|
||||||
],
|
],
|
||||||
'js': [
|
'js': [
|
||||||
|
|
|
@ -40,3 +40,35 @@ class MassMailController(http.Controller):
|
||||||
if 'opt_out' in request.registry[mailing.mailing_model]._all_columns:
|
if 'opt_out' in request.registry[mailing.mailing_model]._all_columns:
|
||||||
request.registry[mailing.mailing_model].write(cr, SUPERUSER_ID, record_ids, {'opt_out': True}, context=context)
|
request.registry[mailing.mailing_model].write(cr, SUPERUSER_ID, record_ids, {'opt_out': True}, context=context)
|
||||||
return 'OK'
|
return 'OK'
|
||||||
|
|
||||||
|
@http.route(['/website_mass_mailing/is_subscriber'], type='json', auth="public", website=True)
|
||||||
|
def is_subscriber(self, list_id, **post):
|
||||||
|
cr, uid, context = request.cr, request.uid, request.context
|
||||||
|
Contacts = request.registry['mail.mass_mailing.contact']
|
||||||
|
Users = request.registry['res.users']
|
||||||
|
|
||||||
|
public_id = request.registry['website'].get_public_user(cr, uid, context)
|
||||||
|
is_subscriber = False
|
||||||
|
email = None
|
||||||
|
if uid != public_id:
|
||||||
|
email = Users.browse(cr, SUPERUSER_ID, uid, context).email
|
||||||
|
elif request.session.get('mass_mailing_email'):
|
||||||
|
email = request.session['mass_mailing_email']
|
||||||
|
|
||||||
|
if email:
|
||||||
|
contact_ids = Contacts.search(cr, SUPERUSER_ID, [('list_id', '=', int(list_id)), ('email', '=', email)], context=context)
|
||||||
|
is_subscriber = len(contact_ids) > 0
|
||||||
|
|
||||||
|
return {'is_subscriber': is_subscriber, 'email': email}
|
||||||
|
|
||||||
|
@http.route(['/website_mass_mailing/subscribe'], type='json', auth="public", website=True)
|
||||||
|
def subscribe(self, list_id, email, **post):
|
||||||
|
cr, uid, context = request.cr, request.uid, request.context
|
||||||
|
Contacts = request.registry['mail.mass_mailing.contact']
|
||||||
|
|
||||||
|
contact_ids = Contacts.search(cr, SUPERUSER_ID, [('list_id', '=', int(list_id)), ('email', '=', email)], context=context)
|
||||||
|
if not contact_ids:
|
||||||
|
Contacts.name_create(cr, SUPERUSER_ID, email, context=context)
|
||||||
|
# add email to session
|
||||||
|
request.session['mass_mailing_email'] = email
|
||||||
|
return True
|
||||||
|
|
|
@ -33,5 +33,10 @@
|
||||||
<field name="sequence">30</field>
|
<field name="sequence">30</field>
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
|
<!-- Create mailing lists -->
|
||||||
|
<record id="mass_mail_list_1" model="mail.mass_mailing.list">
|
||||||
|
<field name="name">Newsletter</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
</data>
|
</data>
|
||||||
</openerp>
|
</openerp>
|
|
@ -9,7 +9,7 @@
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
<!-- Create mailing lists -->
|
<!-- Create mailing lists -->
|
||||||
<record id="mass_mail_list_1" model="mail.mass_mailing.list">
|
<record id="mass_mail_list_2" model="mail.mass_mailing.list">
|
||||||
<field name="name">Imported Contacts</field>
|
<field name="name">Imported Contacts</field>
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
|
@ -17,17 +17,17 @@
|
||||||
<record id="mass_mail_contact_1" model="mail.mass_mailing.contact">
|
<record id="mass_mail_contact_1" model="mail.mass_mailing.contact">
|
||||||
<field name="name">Aristide Antario</field>
|
<field name="name">Aristide Antario</field>
|
||||||
<field name="email">aa@example.com</field>
|
<field name="email">aa@example.com</field>
|
||||||
<field name="list_id" ref="mass_mailing.mass_mail_list_1"/>
|
<field name="list_id" ref="mass_mailing.mass_mail_list_2"/>
|
||||||
</record>
|
</record>
|
||||||
<record id="mass_mail_contact_2" model="mail.mass_mailing.contact">
|
<record id="mass_mail_contact_2" model="mail.mass_mailing.contact">
|
||||||
<field name="name">Beverly Bridge</field>
|
<field name="name">Beverly Bridge</field>
|
||||||
<field name="email">bb@example.com</field>
|
<field name="email">bb@example.com</field>
|
||||||
<field name="list_id" ref="mass_mailing.mass_mail_list_1"/>
|
<field name="list_id" ref="mass_mailing.mass_mail_list_2"/>
|
||||||
</record>
|
</record>
|
||||||
<record id="mass_mail_contact_3" model="mail.mass_mailing.contact">
|
<record id="mass_mail_contact_3" model="mail.mass_mailing.contact">
|
||||||
<field name="name">Carol Cartridge</field>
|
<field name="name">Carol Cartridge</field>
|
||||||
<field name="email">cc@example.com</field>
|
<field name="email">cc@example.com</field>
|
||||||
<field name="list_id" ref="mass_mailing.mass_mail_list_1"/>
|
<field name="list_id" ref="mass_mailing.mass_mail_list_2"/>
|
||||||
<field name="opt_out" eval="True"/>
|
<field name="opt_out" eval="True"/>
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
|
|
Binary file not shown.
After Width: | Height: | Size: 4.1 KiB |
|
@ -0,0 +1,40 @@
|
||||||
|
(function () {
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
var website = openerp.website;
|
||||||
|
var _t = openerp._t;
|
||||||
|
|
||||||
|
website.snippet.options.mailing_list_subscribe = website.snippet.Option.extend({
|
||||||
|
on_prompt: function () {
|
||||||
|
var self = this;
|
||||||
|
return website.prompt({
|
||||||
|
id: "editor_new_mailing_list_subscribe_button",
|
||||||
|
window_title: _t("Add a Newsletter Subscribe Button"),
|
||||||
|
select: _t("Newsletter"),
|
||||||
|
init: function (field) {
|
||||||
|
return website.session.model('mail.mass_mailing.list')
|
||||||
|
.call('name_search', ['', []], { context: website.get_context() });
|
||||||
|
},
|
||||||
|
}).then(function (mailing_list_id) {
|
||||||
|
self.$target.attr("data-list-id", mailing_list_id);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
drop_and_build_snippet: function() {
|
||||||
|
var self = this;
|
||||||
|
this._super();
|
||||||
|
this.on_prompt().fail(function () {
|
||||||
|
self.editor.on_remove();
|
||||||
|
});
|
||||||
|
},
|
||||||
|
start : function () {
|
||||||
|
var self = this;
|
||||||
|
this.$el.find(".js_mailing_list").on("click", _.bind(this.on_prompt, this));
|
||||||
|
this._super();
|
||||||
|
},
|
||||||
|
clean_for_save: function () {
|
||||||
|
this.$target.addClass("hidden");
|
||||||
|
},
|
||||||
|
});
|
||||||
|
})();
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,57 @@
|
||||||
|
(function () {
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
var website = openerp.website;
|
||||||
|
|
||||||
|
website.snippet.animationRegistry.subscribe = website.snippet.Animation.extend({
|
||||||
|
selector: ".js_subscribe",
|
||||||
|
start: function (editable_mode) {
|
||||||
|
var self = this;
|
||||||
|
|
||||||
|
// set value and display button
|
||||||
|
self.$target.find("input").removeClass("hidden");
|
||||||
|
openerp.jsonRpc('/website_mass_mailing/is_subscriber', 'call', {
|
||||||
|
list_id: this.$target.data('list-id'),
|
||||||
|
}).always(function (data) {
|
||||||
|
self.$target.find('input.js_subscribe_email')
|
||||||
|
.val(data.email ? data.email : "")
|
||||||
|
.attr("disabled", data.is_subscriber && data.email.length ? "disabled" : false);
|
||||||
|
self.$target.attr("data-subscribe", data.is_subscriber ? 'on' : 'off');
|
||||||
|
self.$target.find('a.js_subscribe_btn')
|
||||||
|
.val(data.email ? data.email : "")
|
||||||
|
.attr("disabled", data.is_subscriber && data.email.length ? "disabled" : false);
|
||||||
|
self.$target.removeClass("hidden");
|
||||||
|
});
|
||||||
|
|
||||||
|
// not if editable mode to allow designer to edit alert field
|
||||||
|
if (!editable_mode) {
|
||||||
|
$('.js_subscribe > .alert').addClass("hidden");
|
||||||
|
$('.js_subscribe > .input-group-btn.hidden').removeClass("hidden");
|
||||||
|
this.$target.find('.js_subscribe_btn').on('click', function (event) {
|
||||||
|
event.preventDefault();
|
||||||
|
self.on_click();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
on_click: function () {
|
||||||
|
var self = this;
|
||||||
|
var $email = this.$target.find(".js_subscribe_email:visible");
|
||||||
|
|
||||||
|
if ($email.length && !$email.val().match(/.+@.+/)) {
|
||||||
|
this.$target.addClass('has-error');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
this.$target.removeClass('has-error');
|
||||||
|
|
||||||
|
openerp.jsonRpc('/website_mass_mailing/subscribe', 'call', {
|
||||||
|
'list_id': this.$target.data('list-id'),
|
||||||
|
'email': $email.length ? $email.val() : false,
|
||||||
|
}).then(function (subscribe) {
|
||||||
|
self.$target.find(".js_subscribe_email, .input-group-btn").addClass("hidden");
|
||||||
|
self.$target.find(".alert").removeClass("hidden");
|
||||||
|
self.$target.find('input.js_subscribe_email').attr("disabled", subscribe ? "disabled" : false);
|
||||||
|
self.$target.attr("data-subscribe", subscribe ? 'on' : 'off');
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
|
})();
|
|
@ -0,0 +1,44 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<openerp>
|
||||||
|
<data>
|
||||||
|
|
||||||
|
<template id="mailing_list_subscribe" inherit_id="website.snippets" name="Subscribe to Newsletter">
|
||||||
|
|
||||||
|
<xpath expr="//div[@id='snippet_content']" position="inside">
|
||||||
|
<div>
|
||||||
|
<div class="oe_snippet_thumbnail">
|
||||||
|
<img class="oe_snippet_thumbnail_img" src="/mass_mailing/static/src/img/blocks/button_newsletter.png"/>
|
||||||
|
<span class="oe_snippet_thumbnail_title">Newsletter</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="oe_snippet_body input-group js_subscribe"
|
||||||
|
data-list-id="0">
|
||||||
|
<input
|
||||||
|
type="email"
|
||||||
|
name="email"
|
||||||
|
class="js_subscribe_email form-control"
|
||||||
|
placeholder="your email..."/>
|
||||||
|
<span class="input-group-btn">
|
||||||
|
<a href="#" class="btn btn-primary js_subscribe_btn">Subscribe</a>
|
||||||
|
</span>
|
||||||
|
<div class="alert alert-success hidden">Thanks for your subscription!</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</xpath>
|
||||||
|
|
||||||
|
<xpath expr="//div[@id='snippet_options']" position="inside">
|
||||||
|
<div data-snippet-option-id='mailing_list_subscribe'
|
||||||
|
data-selector=".js_subscribe"
|
||||||
|
data-selector-siblings="p, h1, h2, h3, blockquote, .well, .panel"
|
||||||
|
>
|
||||||
|
<li>
|
||||||
|
<a href="#" class="button js_mailing_list">Change Newsletter</a>
|
||||||
|
</li>
|
||||||
|
</div>
|
||||||
|
</xpath>
|
||||||
|
|
||||||
|
</template>
|
||||||
|
|
||||||
|
</data>
|
||||||
|
</openerp>
|
|
@ -0,0 +1,14 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<openerp>
|
||||||
|
<data>
|
||||||
|
|
||||||
|
<template id="head" inherit_id="website.layout" name="Mail customization">
|
||||||
|
<xpath expr="//head" position="inside">
|
||||||
|
<script type="text/javascript" src="/mass_mailing/static/src/js/website_mass_mailing.editor.js" groups="base.group_website_publisher"></script>
|
||||||
|
<script type="text/javascript" src="/mass_mailing/static/src/js/website_mass_mailing.js"></script>
|
||||||
|
<link rel='stylesheet' href='/website_mail/static/src/css/website_mail.css'/>
|
||||||
|
</xpath>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
</data>
|
||||||
|
</openerp>
|
|
@ -3,9 +3,9 @@
|
||||||
<data noupdate="1">
|
<data noupdate="1">
|
||||||
|
|
||||||
<record model="mail.group" id="group_all_employees">
|
<record model="mail.group" id="group_all_employees">
|
||||||
<field name="name">Newsletter</field>
|
<field name="name">Discussion Group</field>
|
||||||
<field name="public">public</field>
|
<field name="public">public</field>
|
||||||
<field name="description">Public Newsletter.</field>
|
<field name="description">Public Discussion Group</field>
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
</data>
|
</data>
|
||||||
|
|
Binary file not shown.
After Width: | Height: | Size: 2.7 KiB |
|
@ -10,7 +10,7 @@
|
||||||
return website.prompt({
|
return website.prompt({
|
||||||
id: "editor_new_subscribe_button",
|
id: "editor_new_subscribe_button",
|
||||||
window_title: _t("Add a Subscribe Button"),
|
window_title: _t("Add a Subscribe Button"),
|
||||||
select: _t("Mailing List"),
|
select: _t("Discussion List"),
|
||||||
init: function (field) {
|
init: function (field) {
|
||||||
return website.session.model('mail.group')
|
return website.session.model('mail.group')
|
||||||
.call('name_search', ['', [['public','=','public']]], { context: website.get_context() });
|
.call('name_search', ['', [['public','=','public']]], { context: website.get_context() });
|
||||||
|
|
|
@ -499,8 +499,8 @@
|
||||||
<xpath expr="//div[@id='snippet_content']" position="inside">
|
<xpath expr="//div[@id='snippet_content']" position="inside">
|
||||||
<div>
|
<div>
|
||||||
<div class="oe_snippet_thumbnail">
|
<div class="oe_snippet_thumbnail">
|
||||||
<img class="oe_snippet_thumbnail_img" src="/website/static/src/img/blocks/block_button.png"/>
|
<img class="oe_snippet_thumbnail_img" src="/website_mail/static/src/img/blocks/button_group_subscribe.png"/>
|
||||||
<span class="oe_snippet_thumbnail_title">Subscribe Button</span>
|
<span class="oe_snippet_thumbnail_title">Discussion Group</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="oe_snippet_body input-group js_follow"
|
<div class="oe_snippet_body input-group js_follow"
|
||||||
|
@ -516,7 +516,7 @@
|
||||||
<a href="#" class="btn btn-default js_unfollow_btn">Unsubscribe</a>
|
<a href="#" class="btn btn-default js_unfollow_btn">Unsubscribe</a>
|
||||||
<a href="#" class="btn btn-primary js_follow_btn">Subscribe</a>
|
<a href="#" class="btn btn-primary js_follow_btn">Subscribe</a>
|
||||||
</span>
|
</span>
|
||||||
<div class="alert alert-success hidden">thanks for your subscription!</div>
|
<div class="alert alert-success hidden">Thanks for your subscription!</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
@ -529,7 +529,7 @@
|
||||||
data-selector-siblings="p, h1, h2, h3, blockquote, .well, .panel"
|
data-selector-siblings="p, h1, h2, h3, blockquote, .well, .panel"
|
||||||
>
|
>
|
||||||
<li>
|
<li>
|
||||||
<a href="#" class="button js_mailing_list">Change mailing list</a>
|
<a href="#" class="button js_mailing_list">Change Discussion List</a>
|
||||||
</li>
|
</li>
|
||||||
</div>
|
</div>
|
||||||
</xpath>
|
</xpath>
|
||||||
|
|
Loading…
Reference in New Issue