[FIX] website_forum: fixed toggle_correct for setting answers as correct

bzr revid: tde@openerp.com-20140411155622-18bdyddcs6hdln77
This commit is contained in:
Thibault Delavallée 2014-04-11 17:56:22 +02:00
parent 5a402ce73a
commit 133038c722
3 changed files with 9 additions and 15 deletions

View File

@ -297,20 +297,18 @@ class WebsiteForum(http.Controller):
return werkzeug.utils.redirect("/forum/%s/question/%s" % (slug(forum), slug(post)))
@http.route('/forum/<model("forum.forum"):forum>/post/<model("forum.post"):post>/toggle_correct', type='json', auth="public", website=True)
def post_toggle_correct(self, form, post, **kwargs):
def post_toggle_correct(self, forum, post, **kwargs):
cr, uid, context = request.cr, request.uid, request.context
if not request.session.uid:
return {'error': 'anonymous_user'}
# user = request.registry['res.users'].browse(cr, uid, uid, context=None)
# # if user have not access to accept answer then reise warning
# if not (post.parent_id.create_uid.id == uid or user.karma >= 500):
# return {'error': 'user'}
if post.parent_id is False or post.parent_id.create_uid.id != uid:
return {'error': 'user'}
# set all answers to False, only one can be accepted
request.registry['forum.post'].write(cr, uid, [c.id for c in post.parent_id.child_ids], {'is_correct': False}, context=context)
request.registry['forum.post'].write(cr, uid, [post.id, post.parent_id.id], {'is_correct': not post.correct}, context=context)
return not post.correct
request.registry['forum.post'].write(cr, uid, [post.id, post.parent_id.id], {'is_correct': not post.is_correct}, context=context)
return not post.is_correct
@http.route('/forum/<model("forum.forum"):forum>/post/<model("forum.post"):post>/delete', type='http', auth="user", multilang=True, website=True)
def post_delete(self, forum, post, **kwargs):

View File

@ -52,9 +52,7 @@ $(document).ready(function () {
$('.accept_answer').on('click', function (ev) {
ev.preventDefault();
var $link = $(ev.currentTarget);
var forum_id = $link.data('forum-id');
var post_id = $link.data('post-id');
openerp.jsonRpc("/forum/" + forum_id + "/post/" + post_id + "/toggle_correct", 'call', {}).then(function (data) {
openerp.jsonRpc($link.attr('href'), 'call', {}).then(function (data) {
if (data['error']) {
if (data['error'] == 'anonymous_user'){
var $warning = $('<div class="alert alert-danger alert-dismissable" id="correct_answer_alert" style="position:absolute; margin-top: -30px; margin-left: 90px;">'+
@ -76,8 +74,7 @@ $(document).ready(function () {
$link.parents().find(".answer_correct").removeClass("answer_correct alert alert-info")
if (data) {
$link.removeClass("oe_answer_false").addClass('oe_answer_true');
$("div#answer_" + $link.attr('id')).addClass("answer_correct alert alert-info");
console.log("aaaaa",$("div#answer_" + $link.attr('id')))
$link.parents('.forum_answer').first().addClass("answer_correct alert alert-info");
}
}
});

View File

@ -482,15 +482,14 @@
<div t-foreach="question.child_ids" t-as="answer" class="mt16 mb32">
<a t-attf-id="answer-#{str(answer.id)}"/>
<div t-attf-class="#{answer.is_correct and 'alert alert-info answer_correct' or ''}" t-attf-id="answer_#{answer.id}" >
<div t-attf-class="forum_answer #{answer.is_correct and 'alert alert-info answer_correct' or ''}" t-attf-id="answer_#{answer.id}" >
<div class="text-center pull-left">
<t t-call="website_forum.vote">
<t t-set="post" t-value="answer"/>
</t>
<div class="text-muted">
<a t-attf-class="accept_answer fa fa-2x fa-check-circle no-decoration oe_answer_true #{answer.is_correct and 'oe_answer_true' or 'oe_answer_false'}"
t-attf-data-forum-id="#{question.forum_id.id}" t-attf-data-post-id="#{answer.id}"
t-attf-data-accept="#{answer.is_correct}"/>
t-attf-href="/forum/#{slug(question.forum_id)}/post/#{slug(answer)}/toggle_correct"/>
</div>
</div>
<div style="margin-left: 95px;" class="clearfix">