[CLEAN] website_mail: cleaned a lost console.log and a commented line that should...
[odoo/odoo.git] / addons / website_mail / static / src / js / website_mail.js
1 (function () {
2     'use strict';
3
4     var website = openerp.website;
5
6     website.snippet.animationRegistry.follow = website.snippet.Animation.extend({
7         selector: ".js_follow",
8         start: function (editable_mode) {
9             var self = this;
10             this.is_user = false;
11
12             openerp.jsonRpc('/website_mail/is_follower', 'call', {
13                 model: this.$target.data('object'),
14                 id: this.$target.data('id'),
15                 fields: ['name', 'alias_id'],
16             }).always(function (data) {
17                 self.is_user = data.is_user;
18                 self.$target.find('.js_mg_email').attr('href', 'mailto:' + data.alias_id[1]);
19                 self.$target.find('.js_mg_link').attr('href', '/groups/' + data.id);
20                 self.toggle_subscription(data.is_follower);
21                 self.$target.find('input.js_follow_email')
22                     .val(data.email ? data.email : "")
23                     .attr("disabled", data.is_follower || (data.email.length && self.is_user) ? "disabled" : false);
24                 self.$target.removeClass("hidden");
25             });
26
27             // not if editable mode to allow designer to edit alert field
28             if (!editable_mode) {
29                 $('.js_follow > .alert').addClass("hidden");
30                 $('.js_follow > .input-group-btn.hidden').removeClass("hidden");
31                 this.$target.find('.js_follow_btn, .js_unfollow_btn').on('click', function (event) {
32                     event.preventDefault();
33                     self.on_click();
34                 });
35             }
36             return;
37         },
38         on_click: function () {
39             var self = this;
40             var $email = this.$target.find(".js_follow_email");
41
42             if ($email.length && !$email.val().match(/.+@.+/)) {
43                 this.$target.addClass('has-error');
44                 return false;
45             }
46             this.$target.removeClass('has-error');
47
48             openerp.jsonRpc('/website_mail/follow', 'call', {
49                 'id': +this.$target.data('id'),
50                 'object': this.$target.data('object'),
51                 'message_is_follower': this.$target.attr("data-follow") || "off",
52                 'email': $email.length ? $email.val() : false,
53             }).then(function (follow) {
54                 self.toggle_subscription(follow);
55             });
56         },
57         toggle_subscription: function(follow) {
58             if (follow) {
59                 this.$target.find(".js_mg_follow_form").addClass("hidden");
60                 this.$target.find(".js_mg_details").removeClass("hidden");
61             }
62             else {
63                 this.$target.find(".js_mg_follow_form").removeClass("hidden");
64                 this.$target.find(".js_mg_details").addClass("hidden");
65             }
66             this.$target.find('input.js_follow_email').attr("disabled", follow || this.is_user ? "disabled" : false);
67             this.$target.attr("data-follow", follow ? 'on' : 'off');
68         },
69     });
70
71     $(document).ready(function () {
72         $('.js_follow_btn').on('click', function (ev) {
73             var email = $(ev.currentTarget).parents('.js_mg_follow_form').first().find('.js_follow_email').val();
74             $(document).find('.js_follow_email').val(email);
75         });
76     });
77 })();