[FIX] website_mail: restored follow JS code that was wrongly merged with the mail group follow snippet. Now both widget animation exists, the second being more complex and therefore requiring a different animation.

This commit is contained in:
Thibault Delavallée 2014-06-19 09:33:36 +02:00
parent 8d282f3b4f
commit b07b8a5b1f
5 changed files with 76 additions and 8 deletions

View File

@ -94,9 +94,8 @@ class WebsiteMail(http.Controller):
values['is_follower'] = len(
request.registry['mail.followers'].search(
cr, SUPERUSER_ID, [
('res_model', '=', 'mail.group'),
('res_model', '=', model),
('res_id', '=', obj_ids[0]),
('partner_id', '=', partner_id.id)
], context=context)) == 1
return values

View File

@ -0,0 +1,68 @@
(function () {
'use strict';
var website = openerp.website;
website.snippet.animationRegistry.follow = website.snippet.Animation.extend({
selector: ".js_follow",
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'),
}).always(function (data) {
self.is_user = data.is_user;
self.email = data.email;
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 > .alert').addClass("hidden");
$('.js_follow > .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');
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) {
console.log(follow, email);
if (follow) {
this.$target.find(".js_follow_btn").addClass("hidden");
this.$target.find(".js_unfollow_btn").removeClass("hidden");
}
else {
this.$target.find(".js_follow_btn").removeClass("hidden");
this.$target.find(".js_unfollow_btn").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');
},
});
})();

View File

@ -21,6 +21,7 @@
<template id="head" inherit_id="website.layout" name="Mail customization">
<xpath expr="//head" position="inside">
<script type="text/javascript" src="/website_mail/static/src/js/follow.js"></script>
<link rel='stylesheet' href='/website_mail/static/src/css/website_mail.css'/>
</xpath>
</template>

View File

@ -3,8 +3,8 @@
var website = openerp.website;
website.snippet.animationRegistry.follow = website.snippet.Animation.extend({
selector: ".js_follow",
website.snippet.animationRegistry.follow_alias = website.snippet.Animation.extend({
selector: ".js_follow_alias",
start: function (editable_mode) {
var self = this;
this.is_user = false;
@ -23,8 +23,8 @@
// not if editable mode to allow designer to edit alert field
if (!editable_mode) {
$('.js_follow > .alert').addClass("hidden");
$('.js_follow > .input-group-btn.hidden').removeClass("hidden");
$('.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();

View File

@ -11,7 +11,7 @@
<span class="oe_snippet_thumbnail_title">Discussion Group</span>
</div>
<div class="oe_snippet_body js_follow"
<div class="oe_snippet_body js_follow_alias"
data-id="0"
data-object="mail.group"
data-follow="off">
@ -38,7 +38,7 @@
<xpath expr="//div[@id='snippet_options']" position="inside">
<div data-snippet-option-id='subscribe'
data-selector=".js_follow"
data-selector=".js_follow_alias"
data-selector-siblings="p, h1, h2, h3, blockquote, .well, .panel"
>
<li>