[FIX] website_mail: follow/subscribe button
bzr revid: chm@openerp.com-20140113110542-jkb13xfiy3tno50n
This commit is contained in:
parent
2d2d047a61
commit
f927506bfc
|
@ -35,7 +35,7 @@ class WebsiteMail(http.Controller):
|
|||
if email and email != u'false': # post contains stringified booleans
|
||||
partner_ids = partner_obj.search(request.cr, SUPERUSER_ID, [("email", "=", email)], context=request.context)
|
||||
if not partner_ids:
|
||||
partner_ids = [partner_obj.name_create(request.cr, SUPERUSER_ID, email, request.context)]
|
||||
partner_ids = [partner_obj.name_create(request.cr, SUPERUSER_ID, email, request.context)[0]]
|
||||
else:
|
||||
partner_ids = [user_obj.browse(request.cr, request.uid, request.uid, request.context).partner_id.id]
|
||||
return partner_ids
|
||||
|
@ -54,5 +54,6 @@ class WebsiteMail(http.Controller):
|
|||
_object.check_access_rule(request.cr, request.uid, [_id], 'read', request.context)
|
||||
_object.message_subscribe(request.cr, SUPERUSER_ID, [_id], partner_ids, context=request.context)
|
||||
obj = _object.browse(request.cr, request.uid, _id)
|
||||
follower_ids = [p.id for p in obj.message_follower_ids]
|
||||
|
||||
return obj.message_is_follower and 1 or 0
|
||||
return partner_ids[0] in follower_ids and 1 or 0
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
$(document).ready(function () {
|
||||
|
||||
$(document).on('click', '.js_follow_btn', function (ev) {
|
||||
$(document).on('click', '.js_follow_btn, .js_unfollow_btn', function (ev) {
|
||||
ev.preventDefault();
|
||||
|
||||
var self = this;
|
||||
var self = this;
|
||||
var $data = $(this).parents("div.js_follow");
|
||||
var $email = $(".js_follow_email", $data);
|
||||
var message_is_follower = $data.attr("data-follow");
|
||||
var $email = $data.find(".js_follow_email");
|
||||
var message_is_follower = $data.attr("data-follow") || "off";
|
||||
$data.attr("data-follow", message_is_follower == 'off' ? 'on' : 'off');
|
||||
|
||||
openerp.jsonRpc('/website_mail/follow', 'call', {
|
||||
|
@ -15,12 +15,10 @@ $(document).ready(function () {
|
|||
'message_is_follower': message_is_follower,
|
||||
'email': $email && $email.val() || false,
|
||||
}).then(function (result) {
|
||||
if (result) {
|
||||
$data.html('<div class="alert alert-success mb0">Thanks for your subscription!</div>')
|
||||
} else {
|
||||
$data.attr("data-follow", + result ? 'on' : 'off');
|
||||
$(self).text('Subscribe')
|
||||
}
|
||||
if (result) {
|
||||
$data.find(" > *").toggleClass("hidden");
|
||||
}
|
||||
$data.attr("data-follow", result ? 'on' : 'off');
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -12,18 +12,17 @@
|
|||
t-att-value="email or ''"
|
||||
placeholder="your email..."/>
|
||||
<span class="input-group-btn">
|
||||
<button href="#"
|
||||
t-attf-class="btn btn-#{object.message_is_follower and 'default' or 'primary'} js_follow_btn">
|
||||
<t t-if="object.message_is_follower">Unsubscribe</t>
|
||||
<t t-if="not object.message_is_follower">Subscribe</t>
|
||||
</button>
|
||||
<button href="#" t-attf-class="btn btn-default js_unfollow_btn">Unsubscribe</button>
|
||||
<button href="#" t-attf-class="btn btn-primary js_follow_btn">Subscribe</button>
|
||||
</span>
|
||||
<div class="alert alert-success hidden">Thanks for your subscription!</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<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/website_mail.js"></script>
|
||||
<link rel='stylesheet' href='/website_mail/static/src/css/website_mail.css'/>
|
||||
</xpath>
|
||||
</template>
|
||||
|
||||
|
|
Loading…
Reference in New Issue