_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)
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
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),
$(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")
}
} 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 {
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', {
$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;
<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
<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">
<td>
<span class="fa fa-thumbs-up"/>
<span t-esc="up_votes"/>
-
<span class="fa fa-thumbs-down "/>
<span t-esc="down_votes"/>
</td>