diff options
| author | Géry Debongnie <ged@odoo.com> | 2015-03-10 08:50:52 +0100 |
|---|---|---|
| committer | Géry Debongnie <ged@odoo.com> | 2015-03-18 09:23:36 +0100 |
| commit | 131ca70d834e2e00318a70673edb5eb038fa8a81 (patch) | |
| tree | 0297b34d331e96d8b3e56611dd97fb80cf80efb0 /addons/website_mail_group/static/src/js | |
| parent | 838cfe66642b9b76d41c9660edd5230fec7234fe (diff) | |
[REF] website_mail: update to the new module system
Diffstat (limited to 'addons/website_mail_group/static/src/js')
3 files changed, 128 insertions, 116 deletions
diff --git a/addons/website_mail_group/static/src/js/website_mail_group.editor.js b/addons/website_mail_group/static/src/js/website_mail_group.editor.js index 420afb736af..1295818186e 100644 --- a/addons/website_mail_group/static/src/js/website_mail_group.editor.js +++ b/addons/website_mail_group/static/src/js/website_mail_group.editor.js @@ -1,36 +1,39 @@ -(function () { - 'use strict'; +odoo.define('website_mail_group.editor', ['web.core', 'web.Model', 'website.snippets.editor', 'website.website'], function (require) { +'use strict'; - var website = openerp.website; - var _t = openerp._t; +var core = require('web.core'); +var Model = require('web.Model'); +var snippet_editor = require('website.snippets.editor'); +var website = require('website.website'); - website.snippet.options.subscribe = website.snippet.Option.extend({ - choose_mailing_list: function (type, value) { - var self = this; - if (type !== "click") return; - return website.prompt({ - id: "editor_new_subscribe_button", - window_title: _t("Add a Subscribe Button"), - select: _t("Discussion List"), - init: function (field) { - return website.session.model('mail.group') - .call('name_search', ['', [['public','=','public']]], { context: website.get_context() }); - }, - }).then(function (mail_group_id) { - self.$target.attr("data-id", mail_group_id); - }); - }, - drop_and_build_snippet: function() { - var self = this; - this._super(); - this.choose_mailing_list("click").fail(function () { - self.editor.on_remove(); - }); - }, - clean_for_save: function () { - this.$target.addClass("hidden"); - }, - }); -})(); +var _t = core._t; +snippet_editor.options.subscribe = snippet_editor.Option.extend({ + choose_mailing_list: function (type, value) { + var self = this; + if (type !== "click") return; + return website.prompt({ + id: "editor_new_subscribe_button", + window_title: _t("Add a Subscribe Button"), + select: _t("Discussion List"), + init: function (field) { + return new Model('mail.group') + .call('name_search', ['', [['public','=','public']]], { context: website.get_context() }); + }, + }).then(function (mail_group_id) { + self.$target.attr("data-id", mail_group_id); + }); + }, + drop_and_build_snippet: function() { + var self = this; + this._super(); + this.choose_mailing_list("click").fail(function () { + self.editor.on_remove(); + }); + }, + clean_for_save: function () { + this.$target.addClass("hidden"); + }, +}); +}); diff --git a/addons/website_mail_group/static/src/js/website_mail_group.js b/addons/website_mail_group/static/src/js/website_mail_group.js index c9b8ae797ed..30f9e43f60c 100644 --- a/addons/website_mail_group/static/src/js/website_mail_group.js +++ b/addons/website_mail_group/static/src/js/website_mail_group.js @@ -1,3 +1,8 @@ +odoo.define('website_mail_group', ['web.ajax'], function (require) { +"use strict"; + +var ajax = require('web.ajax'); + $(document).ready(function () { $('.o_mg_link_hide').on('click', function (ev) { @@ -22,7 +27,7 @@ $(document).ready(function () { $('body').on('click', 'button.o_mg_read_more', function (ev) { var $link = $(ev.target); - return openerp.jsonRpc($link.data('href'), 'call', { + return ajax.jsonRpc($link.data('href'), 'call', { 'last_displayed_id': $link.data('msg-id'), }).then(function (data) { if (! data) { @@ -39,4 +44,6 @@ $(document).ready(function () { return true; }); }); -});
\ No newline at end of file +}); + +}); diff --git a/addons/website_mail_group/static/src/js/website_mail_group.snippet.js b/addons/website_mail_group/static/src/js/website_mail_group.snippet.js index 8ad4f9ba796..0cf1050c4d5 100644 --- a/addons/website_mail_group/static/src/js/website_mail_group.snippet.js +++ b/addons/website_mail_group/static/src/js/website_mail_group.snippet.js @@ -1,93 +1,95 @@ -(function () { - 'use strict'; +odoo.define('website_mail_group.snippet', ['web.ajax', 'website.snippets.animation'], function (require) { +'use strict'; - var website = openerp.website; +var ajax = require('web.ajax'); +var animation = require('website.snippets.animation'); - website.snippet.animationRegistry.follow_alias = website.snippet.Animation.extend({ - selector: ".js_follow_alias", - start: function (editable_mode) { - var self = this; - this.is_user = false; +animation.registry.follow_alias = animation.Animation.extend({ + selector: ".js_follow_alias", + start: function (editable_mode) { + var self = this; + this.is_user = false; - openerp.jsonRpc('/website_mail/is_follower', 'call', { - model: this.$target.data('object'), - id: this.$target.data('id'), - get_alias_info: true, - }).always(function (data) { - self.is_user = data.is_user; - self.email = data.email; - self.$target.find('.js_mg_link').attr('href', '/groups/' + self.$target.data('id')); - self.toggle_subscription(data.is_follower, data.email); - self.$target.removeClass("hidden"); - }); + ajax.jsonRpc('/website_mail/is_follower', 'call', { + model: this.$target.data('object'), + id: this.$target.data('id'), + get_alias_info: true, + }).always(function (data) { + self.is_user = data.is_user; + self.email = data.email; + self.$target.find('.js_mg_link').attr('href', '/groups/' + self.$target.data('id')); + self.toggle_subscription(data.is_follower, data.email); + self.$target.removeClass("hidden"); + }); - // not if editable mode to allow designer to edit alert field - if (!editable_mode) { - $('.js_follow_alias > .alert').addClass("hidden"); - $('.js_follow_alias > .input-group-btn.hidden').removeClass("hidden"); - this.$target.find('.js_follow_btn, .js_unfollow_btn').on('click', function (event) { - event.preventDefault(); - self.on_click(); - }); - } - return; - }, - on_click: function () { - var self = this; - var $email = this.$target.find(".js_follow_email"); + // not if editable mode to allow designer to edit alert field + if (!editable_mode) { + $('.js_follow_alias > .alert').addClass("hidden"); + $('.js_follow_alias > .input-group-btn.hidden').removeClass("hidden"); + this.$target.find('.js_follow_btn, .js_unfollow_btn').on('click', function (event) { + event.preventDefault(); + self.on_click(); + }); + } + return; + }, + on_click: function () { + var self = this; + var $email = this.$target.find(".js_follow_email"); - if ($email.length && !$email.val().match(/.+@.+/)) { - this.$target.addClass('has-error'); - return false; - } - this.$target.removeClass('has-error'); + if ($email.length && !$email.val().match(/.+@.+/)) { + this.$target.addClass('has-error'); + return false; + } + this.$target.removeClass('has-error'); - openerp.jsonRpc('/website_mail/follow', 'call', { - 'id': +this.$target.data('id'), - 'object': this.$target.data('object'), - 'message_is_follower': this.$target.attr("data-follow") || "off", - 'email': $email.length ? $email.val() : false, - }).then(function (follow) { - self.toggle_subscription(follow, self.email); - }); - }, - toggle_subscription: function(follow, email) { - var alias_done = this.get_alias_info(); - if (follow) { - this.$target.find(".js_mg_follow_form").addClass("hidden"); - this.$target.find(".js_mg_details").removeClass("hidden"); + ajax.jsonRpc('/website_mail/follow', 'call', { + 'id': +this.$target.data('id'), + 'object': this.$target.data('object'), + 'message_is_follower': this.$target.attr("data-follow") || "off", + 'email': $email.length ? $email.val() : false, + }).then(function (follow) { + self.toggle_subscription(follow, self.email); + }); + }, + toggle_subscription: function(follow, email) { + var alias_done = this.get_alias_info(); + if (follow) { + this.$target.find(".js_mg_follow_form").addClass("hidden"); + this.$target.find(".js_mg_details").removeClass("hidden"); + } + else { + this.$target.find(".js_mg_follow_form").removeClass("hidden"); + this.$target.find(".js_mg_details").addClass("hidden"); + } + this.$target.find('input.js_follow_email') + .val(email ? email : "") + .attr("disabled", follow || (email.length && this.is_user) ? "disabled" : false); + this.$target.attr("data-follow", follow ? 'on' : 'off'); + return $.when(alias_done); + }, + get_alias_info: function() { + var self = this; + if (! this.$target.data('id')) { + return $.Deferred().resolve(); + } + return ajax.jsonRpc('/groups/' + this.$target.data('id') + '/get_alias_info', 'call', {}).then(function (data) { + if (data.alias_name) { + self.$target.find('.js_mg_email').attr('href', 'mailto:' + data.alias_name); + self.$target.find('.js_mg_email').removeClass('hidden'); } else { - this.$target.find(".js_mg_follow_form").removeClass("hidden"); - this.$target.find(".js_mg_details").addClass("hidden"); - } - this.$target.find('input.js_follow_email') - .val(email ? email : "") - .attr("disabled", follow || (email.length && this.is_user) ? "disabled" : false); - this.$target.attr("data-follow", follow ? 'on' : 'off'); - return $.when(alias_done); - }, - get_alias_info: function() { - var self = this; - if (! this.$target.data('id')) { - return $.Deferred().resolve(); + self.$target.find('.js_mg_email').addClass('hidden'); } - return openerp.jsonRpc('/groups/' + this.$target.data('id') + '/get_alias_info', 'call', {}).then(function (data) { - if (data.alias_name) { - self.$target.find('.js_mg_email').attr('href', 'mailto:' + data.alias_name); - self.$target.find('.js_mg_email').removeClass('hidden'); - } - else { - self.$target.find('.js_mg_email').addClass('hidden'); - } - }); - } - }); - - $(document).ready(function () { - $('.js_follow_btn').on('click', function (ev) { - var email = $(ev.currentTarget).parents('.js_mg_follow_form').first().find('.js_follow_email').val(); - $(document).find('.js_follow_email').val(email); }); + } +}); + +$(document).ready(function () { + $('.js_follow_btn').on('click', function (ev) { + var email = $(ev.currentTarget).parents('.js_mg_follow_form').first().find('.js_follow_email').val(); + $(document).find('.js_follow_email').val(email); }); -})(); +}); + +}); |
