[IMP] improvedd code to set proper colour on voted thumb and accepted answer.
bzr revid: tpa@tinyerp.com-20140404092212-7ey70f7dywtox0zc
This commit is contained in:
@@ -72,7 +72,7 @@ class Post(osv.Model):
|
||||
_inherit = ['mail.thread', 'website.seo.metadata']
|
||||
|
||||
def _get_votes(self, cr, uid, ids, field_name, arg, context):
|
||||
res = dict.fromkeys(ids, False)
|
||||
res = dict.fromkeys(ids, 0)
|
||||
# Note: read_group is not returning all fields which we passed in list.when it will work uncomment this code and remove remaining code
|
||||
#Vote = self.pool['website.forum.post.vote']
|
||||
#data = Vote.read_group(cr, uid, [('post_id','in', ids), ('user_id', '=', uid)], [ "post_id", "vote"], groupby=["post_id"], context=context)
|
||||
@@ -84,7 +84,7 @@ class Post(osv.Model):
|
||||
if vote.user_id.id == uid:
|
||||
if vote.vote == '1':
|
||||
res[post.id] = 1
|
||||
else:
|
||||
elif vote.vote == '-1':
|
||||
res[post.id] = -1
|
||||
return res
|
||||
|
||||
@@ -177,7 +177,7 @@ class Post(osv.Model):
|
||||
help="Comments on forum post",
|
||||
),
|
||||
|
||||
'user_vote':fields.function(_get_votes, string="My Vote", type='boolean',
|
||||
'user_vote':fields.function(_get_votes, string="My Vote", type='integer',
|
||||
store={
|
||||
'website.forum.post': (lambda self, cr, uid, ids, c={}: ids, ['vote_ids'], 10),
|
||||
'website.forum.post.vote': (_get_vote, [], 10),
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
$(document).ready(function () {
|
||||
|
||||
$('.fa-thumbs-up ,.fa-thumbs-down').on('click', function (ev) {
|
||||
$('.vote_up ,.vote_down').on('click', function (ev) {
|
||||
ev.preventDefault();
|
||||
var $link = $(ev.currentTarget);
|
||||
var value = $link.attr("value")
|
||||
@@ -34,7 +34,7 @@ $(document).ready(function () {
|
||||
}
|
||||
} else {
|
||||
$link.parent().find("#vote_count").html(data['vote_count']);
|
||||
if (data == 0) {
|
||||
if (data['vote_count'] == 0) {
|
||||
$link.parent().find(".text-success").removeClass("text-success");
|
||||
$link.parent().find(".text-warning").removeClass("text-warning");
|
||||
} else {
|
||||
@@ -60,7 +60,7 @@ $(document).ready(function () {
|
||||
return false;
|
||||
});
|
||||
|
||||
$('.fa-check-circle').on('click', function (ev) {
|
||||
$('.accept_answer').on('click', function (ev) {
|
||||
ev.preventDefault();
|
||||
var $link = $(ev.currentTarget);
|
||||
openerp.jsonRpc("/forum/correct_answer", 'call', {
|
||||
@@ -83,8 +83,11 @@ $(document).ready(function () {
|
||||
$link.parent().append($warning);
|
||||
}
|
||||
} else {
|
||||
$link.parents().find(".oe_answer_true").removeClass("oe_answer_true").addClass('oe_answer_false');
|
||||
$link.removeClass("oe_answer_false").addClass('oe_answer_true');
|
||||
if (data) {
|
||||
$link.parents().find(".oe_answer_false").removeClass("oe_answer_false").addClass('oe_answer_true');
|
||||
} else {
|
||||
$link.parents().find(".oe_answer_true").removeClass("oe_answer_true").addClass('oe_answer_false');
|
||||
}
|
||||
}
|
||||
});
|
||||
return true;
|
||||
|
||||
@@ -376,10 +376,10 @@
|
||||
|
||||
<template id="vote">
|
||||
<div t-attf-class="box oe_grey">
|
||||
<a t-attf-class="fa fa-thumbs-up #{post.user_vote == 1 and 'text-success' or ''}"
|
||||
<a t-attf-class="vote_up fa fa-thumbs-up #{post.user_vote == 1 and 'text-success' or ''}"
|
||||
t-attf-id="#{post.id}" t-attf-value="1"/>
|
||||
<span id="vote_count" t-esc="post.vote_count"/>
|
||||
<a t-attf-class="fa fa-thumbs-down #{post.user_vote == -1 and 'text-warning' or ''}"
|
||||
<a t-attf-class="vote_down fa fa-thumbs-down #{post.user_vote == -1 and 'text-warning' or ''}"
|
||||
t-attf-id="#{post.id}" t-attf-value="-1"/>
|
||||
<div>
|
||||
votes
|
||||
@@ -467,8 +467,8 @@
|
||||
<t t-set="post" t-value="answer"/>
|
||||
</t>
|
||||
<div class="text-muted">
|
||||
<a t-attf-id="#{answer.id}" t-if="answer.correct" class="fa fa-2x fa-check-circle oe_answer_true"/>
|
||||
<a t-attf-id="#{answer.id}" t-if="not answer.correct" class="fa fa-2x fa-check-circle oe_answer_false"/>
|
||||
<a t-attf-id="#{answer.id}" t-if="answer.correct" class="accept_answer fa fa-2x fa-check-circle oe_answer_true"/>
|
||||
<a t-attf-id="#{answer.id}" t-if="not answer.correct" class="accept_answer fa fa-2x fa-check-circle oe_answer_false"/>
|
||||
</div>
|
||||
</div>
|
||||
<div style="margin-left: 95px;" class="clearfix">
|
||||
@@ -726,7 +726,6 @@
|
||||
<td>
|
||||
<span class="fa fa-thumbs-up"/>
|
||||
<span t-esc="up_votes"/>
|
||||
|
||||
<span class="fa fa-thumbs-down "/>
|
||||
<span t-esc="down_votes"/>
|
||||
</td>
|
||||
|
||||
Reference in New Issue
Block a user