[imp]:improve user chose correct answer

bzr revid: sunilsharma.sharma07@gmail.com-20140312120544-t3j2o5hrb226axfu
This commit is contained in:
Sunil Sharma (OpenERP) 2014-03-12 17:35:44 +05:30
parent 009364277d
commit 12a070dbbe
5 changed files with 39 additions and 3 deletions

View File

@ -383,3 +383,14 @@ class website_forum(http.Controller):
}
return request.website.render("website_forum.edit_answer", values)
@http.route('/forum/correct_answer/', type='json', auth="user", multilang=True, methods=['POST'], website=True)
def correct_answer(self, **kwarg):
cr, uid, context = request.cr, request.uid, request.context
Post = request.registry['website.forum.post']
post = Post.browse(cr, uid, int(kwarg.get('post_id')), context=context)
if post.create_uid.id == uid:
correct = False if post.correct else True
Post.write( cr, uid, [int(kwarg.get('post_id'))], {
'correct': correct,
}, context=context)
return correct

View File

@ -139,6 +139,7 @@ class Post(osv.Model):
'website.forum.post.vote': (_get_vote, [], 10),
}
),
'correct': fields.boolean('Correct Answer'),
}
_defaults = {
'state': 'active',

View File

@ -36,3 +36,11 @@
.badge-bronze {
color: #eea91e;
}
.oe_answer_true {
color: #428bca;
}
.oe_answer_false {
color: #999
}

View File

@ -59,7 +59,6 @@ $(document).ready(function () {
$('.delete').on('click', function (ev) {
ev.preventDefault();
var $link = $(ev.currentTarget);
var value = $link.attr("value")
openerp.jsonRpc("/forum/post_delete/", 'call', {
'post_id': $link.attr("id")})
.then(function (data) {
@ -67,5 +66,21 @@ $(document).ready(function () {
});
return false;
});
$('.fa-check').on('click', function (ev) {
ev.preventDefault();
var $link = $(ev.currentTarget);
openerp.jsonRpc("/forum/correct_answer/", 'call', {
'post_id': $link.attr("id")})
.then(function (data) {
if (data) {
$link.removeClass("oe_answer_false").addClass('oe_answer_true');
}
else {
$link.removeClass("oe_answer_true").addClass('oe_answer_false');
}
});
return false;
});
});

View File

@ -370,8 +370,9 @@
votes
</div>
</div>
<div class="text-muted">
<a href="#" class="fa fa-2x fa-check"/>
<div class="text-muted" id="correct">
<a t-attf-id="#{answer.id}" t-if="answer.correct" class="fa fa-2x fa-check oe_answer_true"/>
<a t-attf-id="#{answer.id}" t-if="not answer.correct" class="fa fa-2x fa-check oe_answer_false"/>
</div>
</div>
<div style="margin-left: 95px;" class="clearfix">