summaryrefslogtreecommitdiff
path: root/addons/mass_mailing/static
diff options
context:
space:
mode:
authorDavid Beguin <dbe@odoo.com>2018-07-12 17:02:36 +0200
committerDavid Beguin <dbe@odoo.com>2018-08-10 17:46:08 +0200
commit59b4836e8d14abdca49e43cdd72b2151e78230d4 (patch)
tree65585f3fe32dc96470e79264d99433e1004b2f10 /addons/mass_mailing/static
parent98ce81cac51793dbab45e8f305a2086b9095aead (diff)
[IMP] mail, mass_mailing : apply blacklist, opt_out per mailing list
Purpose ======= - Apply the blacklist implementation to Improve mailing subscription to be more compliant with the European GDPR law. Keep a list of people who does not want to receive promotional emails (or mass mailing in general) anymore. - Allows the recipient to update himself his mailing preferences Specifications =========== This commit is regrouping some main changes on mass mailing. Apply Blacklist for following models through blacklist.mixin : - crm.lead - res.partner - mail.mass_mailing.contact - mail.channel.partner - Opt_out per mailing list instead of per mailing contact. - Replace opt_out by blacklist in crm.lead + res.partner models - Added 'ignored' state for mass_mailing. Ignored = blacklisted, opted-out Ignored email are not included into final statistics to avoid confusion. - Unsubscribe(d) pages migrated from website_mass_mailing to mass_mailing module as thoses pages should work without having the website module installed Detailed implementation =================== Mass-mailing : - A blacklisted email is notified by the ban icon next to the email field. (at the left of the email field for display purpose) - Renaming the '_get_blacklist' method that was actually searching opt_out list into 'get_opt_out_list' - Opt out per mailing list : Add opt_out + related fields (for display and ergonomy reasons) on the relational model - Display relational model tree view instead of mass_mailing.contact tree view when clicking on mass_mailing_list in kanban view -> In order to be align between contact_nbr displayed in kanban tile and the content of the tree view -> mass_mailing contact is accesible via the user icon in this tree view - Remove custom filters 'filter_contact_subscription' and 'filter_contact_unsubscription' as opt_out is not on mass_mailing.contact model anymore - Add 'is_public' to mailing list The name of this mailing list can be seen (or not) by recipient in the unsubscription page If the mailing lists used in the mass mailing are not public, the user in only informed that he has been unsubscribed. If the mailing lists are public, the user is informed that he has been unsubscribed from the mailing lists and he has the choice to modify his subscription to all the public mailing list he is or was subscribed to. - Unsubscription Page : - mass_mailing_contact : Opt_out per mailing list, done by email and not by id, as multiple contact can have the same email The recipient can add/remove himself to/from the blacklist The recipient can send a feedback about why he unsubscribed - crm.lead + res.partner : Once the recipient unsubscribe, he is automatically blacklisted The recipient can 'Come back' and remove himself from the blacklist if he changes his mind - Show blacklist button parameter added in config : The idea is to enable/disable the fact that the recipient can add himself to the blacklist by showing or not the 'blacklist me' button Only applies for mass_mailing.contact. The recipient, once blacklisted, can always, no matter the value of this parameter, 'come back' and unblacklist himself crm.lead + res.partner : - Replace opt_out by blacklist in crm.lead + res.partner models. As when a res.partner or crm.lead unsubcribe, we assume that the recipient does not want to receive mass mailing anymore, at all, even if we adds him to a mailing list afterwards. He is then blacklisted to avoid this. With this behaviour, if a new lead is created with the same email address, he won't be able to receive mail in mass_mode. But he will still be able to receive '1 to 1' direct email. Task ID 33224 Closes #25966
Diffstat (limited to 'addons/mass_mailing/static')
-rw-r--r--addons/mass_mailing/static/src/js/unsubscribe.js192
-rw-r--r--addons/mass_mailing/static/src/scss/mass_mailing.scss4
2 files changed, 196 insertions, 0 deletions
diff --git a/addons/mass_mailing/static/src/js/unsubscribe.js b/addons/mass_mailing/static/src/js/unsubscribe.js
new file mode 100644
index 00000000000..5da1a195dd5
--- /dev/null
+++ b/addons/mass_mailing/static/src/js/unsubscribe.js
@@ -0,0 +1,192 @@
+odoo.define('mass_mailing.unsubscribe', function (require) {
+ 'use strict';
+
+ var ajax = require('web.ajax');
+ var core = require('web.core');
+ require('web.dom_ready');
+
+ var _t = core._t;
+
+ var email = $("input[name='email']").val();
+ var mailing_id = parseInt($("input[name='mailing_id']").val());
+ var res_id = parseInt($("input[name='res_id']").val());
+ var token = (location.search.split('token' + '=')[1] || '').split('&')[0];
+
+ if (!$('.o_unsubscribe_form').length) {
+ return $.Deferred().reject("DOM doesn't contain '.o_unsubscribe_form'");
+ }
+ if (email != '' && email != undefined){
+ ajax.jsonRpc('/mailing/blacklist/check', 'call', {'email': email, 'mailing_id': mailing_id, 'res_id': res_id, 'token': token})
+ .then(function (result) {
+ if (result == 'unauthorized'){
+ $('#button_add_blacklist').hide();
+ $('#button_remove_blacklist').hide();
+ }
+ else if (result == true) {
+ $('#button_remove_blacklist').show();
+ toggle_opt_out_section(false);
+ }
+ else if (result == false) {
+ $('#button_add_blacklist').show();
+ toggle_opt_out_section(true);
+ }
+ else {
+ $('#subscription_info').html(_t('An error occured. Please try again later or contact us.'));
+ $('#info_state').removeClass('alert-success').removeClass('alert-info').removeClass('alert-warning').addClass('alert-error');
+ }
+ })
+ .fail(function () {
+ $('#subscription_info').html(_t('An error occured. Please try again later or contact us.'));
+ $('#info_state').removeClass('alert-success').removeClass('alert-info').removeClass('alert-warning').addClass('alert-error');
+ });
+ }
+ else {
+ $('#div_blacklist').hide();
+ }
+
+ var unsubscribed_list = $("input[name='unsubscribed_list']").val();
+ if (unsubscribed_list){
+ $('#subscription_info').html(_t('You have been <strong>successfully unsubscribed from ' + unsubscribed_list + "</strong>."));
+ }
+ else{
+ $('#subscription_info').html(_t('You have been <strong>successfully unsubscribed</strong>.'));
+ }
+
+ $('#unsubscribe_form').on('submit', function (e) {
+ e.preventDefault();
+
+ var checked_ids = [];
+ $("input[type='checkbox']:checked").each(function (i){
+ checked_ids[i] = parseInt($(this).val());
+ });
+
+ var unchecked_ids = [];
+ $("input[type='checkbox']:not(:checked)").each(function (i){
+ unchecked_ids[i] = parseInt($(this).val());
+ });
+
+ ajax.jsonRpc('/mail/mailing/unsubscribe', 'call', {'opt_in_ids': checked_ids, 'opt_out_ids': unchecked_ids, 'email': email, 'mailing_id': mailing_id, 'res_id': res_id, 'token': token})
+ .then(function (result) {
+ if (result == 'unauthorized'){
+ $('#subscription_info').html(_t('You are not authorized to do this!'));
+ $('#info_state').removeClass('alert-success').removeClass('alert-info').removeClass('alert-error').addClass('alert-warning');
+ }
+ else if (result == true) {
+ $('#subscription_info').html(_t('Your changes have been saved.'));
+ $('#info_state').removeClass('alert-info').addClass('alert-success');
+ }
+ else {
+ $('#subscription_info').html(_t('An error occurred. Your changes have not been saved, try again later.'));
+ $('#info_state').removeClass('alert-info').addClass('alert-warning');
+ }
+ })
+ .fail(function () {
+ $('#subscription_info').html(_t('An error occurred. Your changes have not been saved, try again later.'));
+ $('#info_state').removeClass('alert-info').addClass('alert-warning');
+ });
+ });
+
+ // ==================
+ // Blacklist
+ // ==================
+ $('#button_add_blacklist').click(function (e) {
+ e.preventDefault();
+
+ ajax.jsonRpc('/mailing/blacklist/add', 'call', {'email': email, 'mailing_id': mailing_id, 'res_id': res_id, 'token': token})
+ .then(function (result) {
+ if (result == 'unauthorized'){
+ $('#subscription_info').html(_t('You are not authorized to do this!'));
+ $('#info_state').removeClass('alert-success').removeClass('alert-info').removeClass('alert-error').addClass('alert-warning');
+ }
+ else
+ {
+ if (result) {
+ $('#subscription_info').html(_t('You have been successfully <strong>added to our blacklist</strong>. '
+ + 'You will not be contacted anymore by our services.'));
+ $('#info_state').removeClass('alert-warning').removeClass('alert-info').removeClass('alert-error').addClass('alert-success');
+ toggle_opt_out_section(false);
+ }
+ else {
+ $('#subscription_info').html(_t('An error occured. Please try again later or contact us.'));
+ $('#info_state').removeClass('alert-success').removeClass('alert-info').removeClass('alert-warning').addClass('alert-error');
+ }
+ $('#button_add_blacklist').hide();
+ $('#button_remove_blacklist').show();
+ $('#unsubscribed_info').hide();
+ }
+ })
+ .fail(function () {
+ $('#subscription_info').html(_t('An error occured. Please try again later or contact us.'));
+ $('#info_state').removeClass('alert-success').removeClass('alert-info').removeClass('alert-warning').addClass('alert-error');
+ });
+ });
+
+ $('#button_remove_blacklist').click(function (e) {
+ e.preventDefault();
+
+ ajax.jsonRpc('/mailing/blacklist/remove', 'call', {'email': email, 'mailing_id': mailing_id, 'res_id': res_id, 'token': token})
+ .then(function (result) {
+ if (result == 'unauthorized'){
+ $('#subscription_info').html(_t('You are not authorized to do this!'));
+ $('#info_state').removeClass('alert-success').removeClass('alert-info').removeClass('alert-error').addClass('alert-warning');
+ }
+ else
+ {
+ if (result) {
+ $('#subscription_info').html(_t("You have been successfully <strong>removed from our blacklist</strong>. "
+ + "You are now able to be contacted by our services."));
+ $('#info_state').removeClass('alert-warning').removeClass('alert-info').removeClass('alert-error').addClass('alert-success');
+ toggle_opt_out_section(true);
+ }
+ else {
+ $('#subscription_info').html(_t('An error occured. Please try again later or contact us.'));
+ $('#info_state').removeClass('alert-success').removeClass('alert-info').removeClass('alert-warning').addClass('alert-error');
+ }
+ $('#button_add_blacklist').show();
+ $('#button_remove_blacklist').hide();
+ $('#unsubscribed_info').hide();
+ }
+ })
+ .fail(function () {
+ $('#subscription_info').html(_t('An error occured. Please try again later or contact us.'));
+ $('#info_state').removeClass('alert-success').removeClass('alert-info').removeClass('alert-warning').addClass('alert-error');
+ });
+ });
+
+ // ==================
+ // Feedback
+ // ==================
+ $('#button_feedback').click(function (e) {
+ var feedback = $("textarea[name='opt_out_feedback']").val();
+ e.preventDefault();
+ ajax.jsonRpc('/mailing/feedback', 'call', {'mailing_id': mailing_id, 'res_id': res_id, 'email': email, 'feedback': feedback, 'token': token})
+ .then(function (result) {
+ if (result == 'unauthorized'){
+ $('#subscription_info').html(_t('You are not authorized to do this!'));
+ $('#info_state').removeClass('alert-success').removeClass('alert-info').removeClass('alert-error').addClass('alert-warning');
+ }
+ else if (result == true){
+ $('#subscription_info').html(_t('Thank you! Your feedback has been sent successfully!'));
+ $('#info_state').removeClass('alert-warning').removeClass('alert-info').removeClass('alert-error').addClass('alert-success');
+ $("#div_feedback").hide();
+ }
+ else {
+ $('#subscription_info').html(_t('An error occured. Please try again later or contact us.'));
+ $('#info_state').removeClass('alert-success').removeClass('alert-info').removeClass('alert-error').addClass('alert-warning');
+ }
+ })
+ .fail(function () {
+ $('#subscription_info').html(_t('An error occured. Please try again later or contact us.'));
+ $('#info_state').removeClass('alert-info').removeClass('alert-success').removeClass('alert-error').addClass('alert-warning');
+ });
+ });
+});
+
+function toggle_opt_out_section(value) {
+ var result = !value;
+ $("#div_opt_out").find('*').attr('disabled',result);
+ $("#button_add_blacklist").attr('disabled', false);
+ $("#button_remove_blacklist").attr('disabled', false);
+ if (value) { $('[name="button_subscription"]').addClass('clickable'); }
+ else { $('[name="button_subscription"]').removeClass('clickable'); }
+}
diff --git a/addons/mass_mailing/static/src/scss/mass_mailing.scss b/addons/mass_mailing/static/src/scss/mass_mailing.scss
index 24b1bd08615..e13cea29676 100644
--- a/addons/mass_mailing/static/src/scss/mass_mailing.scss
+++ b/addons/mass_mailing/static/src/scss/mass_mailing.scss
@@ -14,3 +14,7 @@
}
}
}
+
+.o_white_body {
+ background-color: white;
+}