[REF] mass_mailing: update to the new module system

This commit is contained in:
Géry Debongnie
2015-03-18 09:09:22 +01:00
parent 5e6171bb6f
commit 81333ade84
3 changed files with 270 additions and 255 deletions
@@ -1,22 +1,28 @@
openerp.mass_mailing = function (instance) {
var _t = instance.web._t;
odoo.define('mass_mailing.mass_mailing', ['web.core', 'web_kanban.common', 'web_kanban.KanbanView'], function (require) {
openerp.web_kanban.KanbanRecord.include({
on_card_clicked: function (event) {
if (this.view.dataset.model === 'mail.mass_mailing.campaign') {
this.$('.oe_mailings').click();
} else {
this._super.apply(this, arguments);
}
},
});
var core = require('web.core');
var common = require('web_kanban.common');
var KanbanView = require('web_kanban.KanbanView');
openerp.web_kanban.KanbanView.include({
on_groups_started: function() {
var _t = core._t;
common.KanbanRecord.include({
on_card_clicked: function (event) {
if (this.view.dataset.model === 'mail.mass_mailing.campaign') {
this.$('.oe_mailings').click();
} else {
this._super.apply(this, arguments);
if (this.dataset.model === 'mail.mass_mailing') {
this.$el.find('.oe_kanban_draghandle').removeClass('oe_kanban_draghandle');
}
},
});
};
}
},
});
KanbanView.include({
on_groups_started: function() {
this._super.apply(this, arguments);
if (this.dataset.model === 'mail.mass_mailing') {
this.$el.find('.oe_kanban_draghandle').removeClass('oe_kanban_draghandle');
}
},
});
});
@@ -1,104 +1,109 @@
(function () {
'use strict';
odoo.define('website_mass_mailing.editor', ['web.core', 'website.editor', 'website.snippet.editor', 'website.website'], function (require) {
'use strict';
var website = openerp.website;
var _t = openerp._t;
var core = require('web.core');
var editor = require('website.editor');
var snippet_editor = require('website.snippet.editor');
var website = require('website.website');
website.snippet.options.mailing_list_subscribe = website.snippet.Option.extend({
choose_mailing_list: function (type, value) {
var self = this;
if (type !== "click") return;
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.choose_mailing_list('click').fail(function () {
self.editor.on_remove($.Event( "click" ));
});
},
clean_for_save: function () {
this.$target.addClass("hidden");
},
});
var _t = core._t;
website.snippet.options.newsletter_popup = website.snippet.Option.extend({
select_mailing_list: function (type) {
var self = this;
if (type !== "click") return;
return website.prompt({
id: "editor_new_mailing_list_subscribe_popup",
window_title: _t("Add a Newsletter Subscribe Popup"),
select: _t("Newsletter"),
init: function () {
return website.session.model('mail.mass_mailing.list')
.call('name_search', [], { context: website.get_context() });
},
}).then(function (mailing_list_id) {
openerp.jsonRpc('/web/dataset/call', 'call', {
model: 'mail.mass_mailing.list',
method: 'read',
args: [[parseInt(mailing_list_id)], ['popup_content'], website.get_context()],
}).then(function (data) {
self.$target.find(".o_popup_content_dev").empty();
if (data && data[0].popup_content) {
$(data[0].popup_content).appendTo(self.$target.find(".o_popup_content_dev"));
}
});
self.$target.attr("data-list-id", mailing_list_id);
});
},
drop_and_build_snippet: function() {
var self = this;
this._super();
this.select_mailing_list('click').fail(function () {
self.editor.on_remove($.Event( "click" ));
});
},
});
website.EditorBar.include({
edit: function () {
this._super();
$('body').on('click','#edit_dialog',_.bind(this.edit_dialog, this.rte.editor));
},
save : function() {
var $target = $('#wrapwrap').find('#o_newsletter_popup');
if ($target && $target.length) {
$target.modal('hide');
$target.css("display", "none");
$('.o_popup_bounce_small').show();
if (!$target.find('.o_popup_content_dev').length) {
$target.find('.o_popup_modal_body').prepend($('<div class="o_popup_content_dev" data-oe-placeholder="Type Here ..."></div>'));
}
var content = $('#wrapwrap .o_popup_content_dev').html();
var newsletter_id = $target.parent().attr('data-list-id');
openerp.jsonRpc('/web/dataset/call', 'call', {
model: 'mail.mass_mailing.list',
method: 'write',
args: [parseInt(newsletter_id),
{'popup_content':content},
website.get_context()],
});
}
return this._super();
},
edit_dialog : function() {
$('#wrapwrap').find('#o_newsletter_popup').modal('show');
$('.o_popup_bounce_small').hide();
$('.modal-backdrop').css("z-index", "0");
snippet_editor.options.mailing_list_subscribe = snippet_editor.Option.extend({
choose_mailing_list: function (type, value) {
var self = this;
if (type !== "click") return;
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.choose_mailing_list('click').fail(function () {
self.editor.on_remove($.Event( "click" ));
});
},
clean_for_save: function () {
this.$target.addClass("hidden");
},
});
website.snippet.options.newsletter_popup = website.snippet.Option.extend({
select_mailing_list: function (type) {
var self = this;
if (type !== "click") return;
return website.prompt({
id: "editor_new_mailing_list_subscribe_popup",
window_title: _t("Add a Newsletter Subscribe Popup"),
select: _t("Newsletter"),
init: function () {
return website.session.model('mail.mass_mailing.list')
.call('name_search', [], { context: website.get_context() });
},
}).then(function (mailing_list_id) {
openerp.jsonRpc('/web/dataset/call', 'call', {
model: 'mail.mass_mailing.list',
method: 'read',
args: [[parseInt(mailing_list_id)], ['popup_content'], website.get_context()],
}).then(function (data) {
self.$target.find(".o_popup_content_dev").empty();
if (data && data[0].popup_content) {
$(data[0].popup_content).appendTo(self.$target.find(".o_popup_content_dev"));
}
});
self.$target.attr("data-list-id", mailing_list_id);
});
},
drop_and_build_snippet: function() {
var self = this;
this._super();
this.select_mailing_list('click').fail(function () {
self.editor.on_remove($.Event( "click" ));
});
},
});
editor.EditorBar.include({
edit: function () {
this._super();
$('body').on('click','#edit_dialog',_.bind(this.edit_dialog, this.rte.editor));
},
save : function() {
var $target = $('#wrapwrap').find('#o_newsletter_popup');
if ($target && $target.length) {
$target.modal('hide');
$target.css("display", "none");
$('.o_popup_bounce_small').show();
if (!$target.find('.o_popup_content_dev').length) {
$target.find('.o_popup_modal_body').prepend($('<div class="o_popup_content_dev" data-oe-placeholder="Type Here ..."></div>'));
}
var content = $('#wrapwrap .o_popup_content_dev').html();
var newsletter_id = $target.parent().attr('data-list-id');
openerp.jsonRpc('/web/dataset/call', 'call', {
model: 'mail.mass_mailing.list',
method: 'write',
args: [parseInt(newsletter_id),
{'popup_content':content},
website.get_context()],
});
}
return this._super();
},
edit_dialog : function() {
$('#wrapwrap').find('#o_newsletter_popup').modal('show');
$('.o_popup_bounce_small').hide();
$('.modal-backdrop').css("z-index", "0");
},
});
});
@@ -1,144 +1,148 @@
(function () {
'use strict';
odoo.define('mass_mailing.website_integration', ['web.ajax', 'web.utils', 'website.snippets.animation', 'website.website'], function (require) {
"use strict";
var website = openerp.website;
var ajax = require('web.ajax');
var utils = require('web.utils');
var animation = require('website.snippets.animation');
var website = require('website.website');
website.snippet.animationRegistry.subscribe = website.snippet.Animation.extend({
selector: ".js_subscribe",
start: function (editable_mode) {
var self = this;
animation.registry.subscribe = animation.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')
.attr("disabled", data.is_subscriber && data.email.length ? "disabled" : false);
self.$target.removeClass("hidden");
self.$target.find('.js_subscribe_btn').toggleClass('hidden', !!data.is_subscriber);
self.$target.find('.js_subscribed_btn').toggleClass('hidden', !data.is_subscriber);
});
// 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');
});
},
});
website.snippet.animationRegistry.newsletter_popup = website.snippet.Animation.extend({
selector: ".o_newsletter_popup",
start: function (editable_mode) {
var self = this;
var popupcontent = self.$target.find(".o_popup_content_dev").empty();
openerp.jsonRpc('/website_mass_mailing/get_content', 'call', {
newsletter_id: self.$target.data('list-id')
}).then(function (data) {
if (data.content) {
$('<div></div>').append(data.content).appendTo(popupcontent);
}
self.$target.find('input.popup_subscribe_email').val(data.email || "");
self.redirect_url = data.redirect_url;
if (!editable_mode && !data.is_subscriber) {
$(document).on('mouseleave', _.bind(self.show_banner, self));
self.$target.find('.popup_subscribe_btn').on('click', function (event) {
event.preventDefault();
self.on_click_subscribe();
});
} else { $(document).off('mouseleave'); }
});
},
on_click_subscribe: function () {
var self = this;
var $email = self.$target.find(".popup_subscribe_email:visible");
if ($email.length && !$email.val().match(/.+@.+/)) {
self.$target.addClass('has-error');
return false;
}
self.$target.removeClass('has-error');
openerp.jsonRpc('/website_mass_mailing/subscribe', 'call', {
'list_id': self.$target.data('list-id'),
'email': $email.length ? $email.val() : false
}).then(function (subscribe) {
self.$target.find('#o_newsletter_popup').modal('hide');
$(document).off('mouseleave');
if (self.redirect_url) {
if (_.contains(self.redirect_url.split('/'), window.location.host) || self.redirect_url.indexOf('/')== 0) {
window.location.href = self.redirect_url;
} else { window.open(self.redirect_url, '_blank'); }
}
});
},
show_banner: function() {
var self = this;
if (!openerp.get_cookie("newsletter-popup-"+ self.$target.data('list-id')) && self.$target) {
$('#o_newsletter_popup:first').modal('show').css({
'margin-top': '70px',
'position': 'fixed'
});
document.cookie = "newsletter-popup-"+ self.$target.data('list-id') +"=" + true + ";path=/";
}
}
});
openerp.website.if_dom_contains('div.o_unsubscribe_form', function() {
$('#unsubscribe_form').on('submit', function(e) {
e.preventDefault();
var email = $("input[name='email']").val();
var mailing_id = parseInt($("input[name='mailing_id']").val());
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());
});
openerp.jsonRpc('/mail/mailing/unsubscribe', 'call', {'opt_in_ids': checked_ids, 'opt_out_ids': unchecked_ids, 'email': email, 'mailing_id': mailing_id})
.then(function(result) {
$('.alert-info').html('Your changes has been saved.').removeClass('alert-info').addClass('alert-success');
})
.fail(function() {
$('.alert-info').html('You changes has not been saved, try again later.').removeClass('alert-info').addClass('alert-warning');
});
// set value and display button
self.$target.find("input").removeClass("hidden");
ajax.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')
.attr("disabled", data.is_subscriber && data.email.length ? "disabled" : false);
self.$target.removeClass("hidden");
self.$target.find('.js_subscribe_btn').toggleClass('hidden', !!data.is_subscriber);
self.$target.find('.js_subscribed_btn').toggleClass('hidden', !data.is_subscriber);
});
// 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');
ajax.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');
});
},
});
animation.registry.newsletter_popup = animation.Animation.extend({
selector: ".o_newsletter_popup",
start: function (editable_mode) {
var self = this;
var popupcontent = self.$target.find(".o_popup_content_dev").empty();
ajax.jsonRpc('/website_mass_mailing/get_content', 'call', {
newsletter_id: self.$target.data('list-id')
}).then(function (data) {
if (data.content) {
$('<div></div>').append(data.content).appendTo(popupcontent);
}
self.$target.find('input.popup_subscribe_email').val(data.email || "");
self.redirect_url = data.redirect_url;
if (!editable_mode && !data.is_subscriber) {
$(document).on('mouseleave', _.bind(self.show_banner, self));
self.$target.find('.popup_subscribe_btn').on('click', function (event) {
event.preventDefault();
self.on_click_subscribe();
});
} else { $(document).off('mouseleave'); }
});
},
on_click_subscribe: function () {
var self = this;
var $email = self.$target.find(".popup_subscribe_email:visible");
if ($email.length && !$email.val().match(/.+@.+/)) {
self.$target.addClass('has-error');
return false;
}
self.$target.removeClass('has-error');
ajax.jsonRpc('/website_mass_mailing/subscribe', 'call', {
'list_id': self.$target.data('list-id'),
'email': $email.length ? $email.val() : false
}).then(function () {
self.$target.find('#o_newsletter_popup').modal('hide');
$(document).off('mouseleave');
if (self.redirect_url) {
if (_.contains(self.redirect_url.split('/'), window.location.host) || self.redirect_url.indexOf('/')=== 0) {
window.location.href = self.redirect_url;
} else { window.open(self.redirect_url, '_blank'); }
}
});
},
show_banner: function() {
var self = this;
if (!utils.get_cookie("newsletter-popup-"+ self.$target.data('list-id')) && self.$target) {
$('#o_newsletter_popup:first').modal('show').css({
'margin-top': '70px',
'position': 'fixed'
});
document.cookie = "newsletter-popup-"+ self.$target.data('list-id') +"=" + true + ";path=/";
}
}
});
website.if_dom_contains('div.o_unsubscribe_form', function() {
$('#unsubscribe_form').on('submit', function(e) {
e.preventDefault();
var email = $("input[name='email']").val();
var mailing_id = parseInt($("input[name='mailing_id']").val());
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})
.then(function() {
$('.alert-info').html('Your changes has been saved.').removeClass('alert-info').addClass('alert-success');
})
.fail(function() {
$('.alert-info').html('You changes has not been saved, try again later.').removeClass('alert-info').addClass('alert-warning');
});
});
})();
});
});