[IMP] instead of reloading question for vote used json request.
bzr revid: tpa@tinyerp.com-20140310132430-mg939k8wetff5pwj
This commit is contained in:
parent
1264c7f233
commit
2ea764affa
|
@ -313,10 +313,11 @@ class website_forum(http.Controller):
|
|||
|
||||
return request.website.render("website_forum.users", values)
|
||||
|
||||
@http.route('/forum/<model("website.forum"):forum>/post_vote/', type='http', auth="user", multilang=True, methods=['POST'], website=True)
|
||||
def post_vote(self, forum, **post):
|
||||
@http.route('/forum/post_vote/', type='json', auth="user", multilang=True, methods=['POST'], website=True)
|
||||
def post_vote(self, **post):
|
||||
cr, uid, context, post_id = request.cr, request.uid, request.context, int(post.get('post_id'))
|
||||
Vote = request.registry['website.forum.post.vote']
|
||||
Post = request.registry['website.forum.post']
|
||||
vote_ids = Vote.search(cr, uid, [('post_id', '=', post_id)], context=context)
|
||||
|
||||
if vote_ids:
|
||||
|
@ -327,5 +328,6 @@ class website_forum(http.Controller):
|
|||
'user_id': uid,
|
||||
'vote': post.get('vote'),
|
||||
}, context=context)
|
||||
record = Post.browse(cr, uid, post_id, context=context)
|
||||
|
||||
return werkzeug.utils.redirect("/forum/%s/question/%s" % (slug(forum),post.get('question_id')))
|
||||
return record.vote_count
|
||||
|
|
|
@ -29,3 +29,22 @@
|
|||
}),
|
||||
});
|
||||
})();
|
||||
|
||||
|
||||
$(document).ready(function () {
|
||||
|
||||
$('.fa-thumbs-up ,.fa-thumbs-down').on('click', function (ev) {
|
||||
ev.preventDefault();
|
||||
var $link = $(ev.currentTarget);
|
||||
var value = $link.attr("value")
|
||||
openerp.jsonRpc("/forum/post_vote/", 'call', {
|
||||
'post_id': $link.attr("id"),
|
||||
'vote': value})
|
||||
.then(function (data) {
|
||||
$link.parent().find("#vote_count").html(data);
|
||||
//TODO: set proper class
|
||||
$link.addClass("text-success");
|
||||
});
|
||||
return false;
|
||||
});
|
||||
});
|
|
@ -284,37 +284,15 @@
|
|||
|
||||
<template id="post_description_full" name="Question Navigation">
|
||||
<t t-call="website_forum.header">
|
||||
<form t-attf-action="/forum/#{ slug(forum) }/post_vote/" enctype="multipart/form-data" method="post" id="post_vote" role="form">
|
||||
<input name="question_id" t-att-value="question.id" type="hidden"/>
|
||||
<script type="text/javascript">
|
||||
{
|
||||
function getsupport (post_value, up_down)
|
||||
{
|
||||
var f=document.getElementById("post_vote")
|
||||
var input = document.createElement("input");
|
||||
input.name= "post_id";
|
||||
input.type = "hidden";
|
||||
input.value = post_value;
|
||||
var vote = document.createElement("input");
|
||||
vote.name= "vote";
|
||||
vote.type = "hidden";
|
||||
vote.value = up_down;
|
||||
f.appendChild(input);
|
||||
f.appendChild(vote);
|
||||
document.getElementById('post_vote').submit();
|
||||
}
|
||||
}
|
||||
</script>
|
||||
</form>
|
||||
|
||||
<div class="question">
|
||||
<div class="text-center pull-left">
|
||||
<div t-attf-class="box oe_grey">
|
||||
<a t-attf-class="fa fa-thumbs-up #{question.user_vote == 1 and 'text-success' or ''}"
|
||||
t-attf-href="javascript:getsupport(#{ question.id },#{ 1 });"/>
|
||||
<span t-esc="question.vote_count"/>
|
||||
t-attf-id="#{question.id}" t-attf-value="1"/>
|
||||
<span id="vote_count" t-esc="question.vote_count"/>
|
||||
<a t-attf-class="fa fa-thumbs-down #{question.user_vote == -1 and 'text-warning' or ''}"
|
||||
t-attf-href="javascript:getsupport(#{ question.id },#{ -1 });"/>
|
||||
t-attf-id="#{question.id}" t-attf-value="-1"/>
|
||||
<div>
|
||||
votes
|
||||
</div>
|
||||
|
@ -364,10 +342,10 @@
|
|||
<div class="text-center pull-left">
|
||||
<div t-attf-class="box oe_grey">
|
||||
<a t-attf-class="fa fa-thumbs-up #{answer.user_vote == 1 and 'text-success' or ''}"
|
||||
t-attf-href="javascript:getsupport(#{ answer.id },#{ 1 });"/>
|
||||
<span t-esc="answer.vote_count"/>
|
||||
t-attf-id="#{answer.id}" t-attf-value="1"/>
|
||||
<span id="vote_count" t-esc="answer.vote_count"/>
|
||||
<a t-attf-class="fa fa-thumbs-down #{answer.user_vote == -1 and 'text-warning' or ''}"
|
||||
t-attf-href="javascript:getsupport(#{ answer.id },#{ -1 });"/>
|
||||
t-attf-id="#{answer.id}" t-attf-value="-1"/>
|
||||
<div>
|
||||
votes
|
||||
</div>
|
||||
|
|
Loading…
Reference in New Issue