[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
|
if email and email != u'false': # post contains stringified booleans
|
||||||
partner_ids = partner_obj.search(request.cr, SUPERUSER_ID, [("email", "=", email)], context=request.context)
|
partner_ids = partner_obj.search(request.cr, SUPERUSER_ID, [("email", "=", email)], context=request.context)
|
||||||
if not partner_ids:
|
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:
|
else:
|
||||||
partner_ids = [user_obj.browse(request.cr, request.uid, request.uid, request.context).partner_id.id]
|
partner_ids = [user_obj.browse(request.cr, request.uid, request.uid, request.context).partner_id.id]
|
||||||
return partner_ids
|
return partner_ids
|
||||||
|
@ -54,5 +54,6 @@ class WebsiteMail(http.Controller):
|
||||||
_object.check_access_rule(request.cr, request.uid, [_id], 'read', request.context)
|
_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)
|
_object.message_subscribe(request.cr, SUPERUSER_ID, [_id], partner_ids, context=request.context)
|
||||||
obj = _object.browse(request.cr, request.uid, _id)
|
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).ready(function () {
|
||||||
|
|
||||||
$(document).on('click', '.js_follow_btn', function (ev) {
|
$(document).on('click', '.js_follow_btn, .js_unfollow_btn', function (ev) {
|
||||||
ev.preventDefault();
|
ev.preventDefault();
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
var $data = $(this).parents("div.js_follow");
|
var $data = $(this).parents("div.js_follow");
|
||||||
var $email = $(".js_follow_email", $data);
|
var $email = $data.find(".js_follow_email");
|
||||||
var message_is_follower = $data.attr("data-follow");
|
var message_is_follower = $data.attr("data-follow") || "off";
|
||||||
$data.attr("data-follow", message_is_follower == 'off' ? 'on' : 'off');
|
$data.attr("data-follow", message_is_follower == 'off' ? 'on' : 'off');
|
||||||
|
|
||||||
openerp.jsonRpc('/website_mail/follow', 'call', {
|
openerp.jsonRpc('/website_mail/follow', 'call', {
|
||||||
|
@ -15,12 +15,10 @@ $(document).ready(function () {
|
||||||
'message_is_follower': message_is_follower,
|
'message_is_follower': message_is_follower,
|
||||||
'email': $email && $email.val() || false,
|
'email': $email && $email.val() || false,
|
||||||
}).then(function (result) {
|
}).then(function (result) {
|
||||||
if (result) {
|
if (result) {
|
||||||
$data.html('<div class="alert alert-success mb0">Thanks for your subscription!</div>')
|
$data.find(" > *").toggleClass("hidden");
|
||||||
} else {
|
}
|
||||||
$data.attr("data-follow", + result ? 'on' : 'off');
|
$data.attr("data-follow", result ? 'on' : 'off');
|
||||||
$(self).text('Subscribe')
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -12,18 +12,17 @@
|
||||||
t-att-value="email or ''"
|
t-att-value="email or ''"
|
||||||
placeholder="your email..."/>
|
placeholder="your email..."/>
|
||||||
<span class="input-group-btn">
|
<span class="input-group-btn">
|
||||||
<button href="#"
|
<button href="#" t-attf-class="btn btn-default js_unfollow_btn">Unsubscribe</button>
|
||||||
t-attf-class="btn btn-#{object.message_is_follower and 'default' or 'primary'} js_follow_btn">
|
<button href="#" t-attf-class="btn btn-primary js_follow_btn">Subscribe</button>
|
||||||
<t t-if="object.message_is_follower">Unsubscribe</t>
|
|
||||||
<t t-if="not object.message_is_follower">Subscribe</t>
|
|
||||||
</button>
|
|
||||||
</span>
|
</span>
|
||||||
|
<div class="alert alert-success hidden">Thanks for your subscription!</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<template id="head" inherit_id="website.layout" name="Mail customization">
|
<template id="head" inherit_id="website.layout" name="Mail customization">
|
||||||
<xpath expr="//head" position="inside">
|
<xpath expr="//head" position="inside">
|
||||||
<script type="text/javascript" src="/website_mail/static/src/js/website_mail.js"></script>
|
<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>
|
</xpath>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue