diff --git a/addons/website_forum/controllers/main.py b/addons/website_forum/controllers/main.py index 8194c9cdbbb..cf8c3ee1b8f 100644 --- a/addons/website_forum/controllers/main.py +++ b/addons/website_forum/controllers/main.py @@ -313,10 +313,11 @@ class website_forum(http.Controller): return request.website.render("website_forum.users", values) - @http.route('/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 diff --git a/addons/website_forum/static/src/js/website_forum.editor.js b/addons/website_forum/static/src/js/website_forum.editor.js index 4c4887f6b38..3d2ac577725 100644 --- a/addons/website_forum/static/src/js/website_forum.editor.js +++ b/addons/website_forum/static/src/js/website_forum.editor.js @@ -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; + }); +}); \ No newline at end of file diff --git a/addons/website_forum/views/website_forum.xml b/addons/website_forum/views/website_forum.xml index a8e3c8d37b1..8c2ef220c66 100644 --- a/addons/website_forum/views/website_forum.xml +++ b/addons/website_forum/views/website_forum.xml @@ -284,37 +284,15 @@