[ADD]: Add vote system in openchatter
bzr revid: atp@tinyerp.com-20120809095341-xn70i8beof20b07h
This commit is contained in:
parent
13ea34a3dd
commit
c92422b2ac
|
@ -24,6 +24,7 @@ import mail_message
|
|||
import mail_thread
|
||||
import mail_group
|
||||
import mail_subscription
|
||||
import mail_vote
|
||||
import ir_needaction
|
||||
import res_users
|
||||
import res_partner
|
||||
|
|
|
@ -230,6 +230,7 @@ class mail_message(osv.Model):
|
|||
select=True, ondelete='set null',
|
||||
help="Parent message, used for displaying as threads with hierarchy"),
|
||||
'child_ids': fields.one2many('mail.message', 'parent_id', 'Child Messages'),
|
||||
'vote_ids': fields.one2many('mail.vote', 'msg_id', 'Votes'),
|
||||
}
|
||||
|
||||
_defaults = {
|
||||
|
@ -237,6 +238,46 @@ class mail_message(osv.Model):
|
|||
'state': 'received',
|
||||
}
|
||||
|
||||
|
||||
#---------------------------------------------------
|
||||
#Mail Vote system (Like or Unlike comments
|
||||
#-----------------------------------------------------
|
||||
|
||||
def get_vote_summary(self, cr, uid, ids, context=None):
|
||||
'''
|
||||
Return message ,count vote of message id given by .particular user with True or False.
|
||||
'''
|
||||
for message in self.browse(cr, uid, ids, context):
|
||||
is_vote_liked = False
|
||||
vote_count = len(message.vote_ids)
|
||||
for vote in message.vote_ids:
|
||||
if vote.user_id.id == uid:
|
||||
is_vote_liked = True
|
||||
break
|
||||
res = {
|
||||
'msg_id': message.id,
|
||||
'vote_count': vote_count,
|
||||
'is_vote_liked': is_vote_liked
|
||||
}
|
||||
return res
|
||||
|
||||
def vote_toggle(self, cr, uid, ids, context=None):
|
||||
'''
|
||||
Toggles when Comment is liked or unlike.
|
||||
Return the number of votes of particular message.
|
||||
'''
|
||||
vote_pool = self.pool.get('mail.vote')
|
||||
vote_count = 0
|
||||
for message in self.browse(cr, uid, ids, context):
|
||||
voters_id = vote_pool.search(cr, uid, [('msg_id', '=', message.id), ('user_id', '=', uid)], context=context)
|
||||
if not voters_id:
|
||||
new_vote_id = vote_pool.create(cr, uid, {'msg_id': message.id, 'user_id': uid}, context=context)
|
||||
else:
|
||||
vote_pool.unlink(cr, uid, voters_id, context=context)
|
||||
if message.vote_ids:
|
||||
vote_count = len(message.vote_ids)
|
||||
return vote_count
|
||||
|
||||
#------------------------------------------------------
|
||||
# Email api
|
||||
#------------------------------------------------------
|
||||
|
|
|
@ -64,12 +64,14 @@ class mail_thread(osv.Model):
|
|||
|
||||
def _get_message_ids(self, cr, uid, ids, name, args, context=None):
|
||||
res = {}
|
||||
img_vote = "<img class='oe_mail_vote_image' src='/mail/static/src/img/vote.gif'/>"
|
||||
for id in ids:
|
||||
message_ids = self.message_search(cr, uid, [id], context=context)
|
||||
subscriber_ids = self.message_get_subscribers(cr, uid, [id], context=context)
|
||||
vote_list = self.message_vote_ids(cr, uid, ids, context=context)
|
||||
res[id] = {
|
||||
'message_ids': message_ids,
|
||||
'message_summary': "<span><span class='oe_e'>9</span> %d</span> <span><span class='oe_e'>+</span> %d</span>" % (len(message_ids), len(subscriber_ids)),
|
||||
'message_summary': "<span>Msg: %d</span> . <span>Fol: %d</span> . <span> %s %d</span>" % (len(message_ids), len(subscriber_ids), img_vote, len(vote_list)),
|
||||
}
|
||||
return res
|
||||
|
||||
|
@ -100,7 +102,15 @@ class mail_thread(osv.Model):
|
|||
#------------------------------------------------------
|
||||
# Automatic subscription when creating/reading
|
||||
#------------------------------------------------------
|
||||
|
||||
def message_vote_ids(self, cr, uid, ids, context=None):
|
||||
message_pool = self.pool.get('mail.message')
|
||||
vote_list = []
|
||||
message_ids = self.message_search(cr, uid, [id], context=context)
|
||||
for message in message_pool.browse(cr, uid, message_ids, context=context):
|
||||
if message.vote_ids:
|
||||
vote_list.append(message.vote_ids)
|
||||
return vote_list
|
||||
|
||||
def create(self, cr, uid, vals, context=None):
|
||||
"""Automatically subscribe the creator """
|
||||
thread_id = super(mail_thread, self).create(cr, uid, vals, context=context)
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2012-Today OpenERP SA (<http://www.openerp.com>).
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
from osv import osv, fields
|
||||
from tools.translate import _
|
||||
|
||||
class mail_vote(osv.Model):
|
||||
'''
|
||||
Mail vote feature allow users to like and unlike particular message or Document's message comment.
|
||||
It counts the number of votes per document.
|
||||
'''
|
||||
_name = 'mail.vote'
|
||||
_description = 'Mail Vote'
|
||||
_columns = {
|
||||
'msg_id': fields.many2one('mail.message', 'Message', required=True),
|
||||
'user_id': fields.many2one('res.users', 'User', required=True),
|
||||
}
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
|
@ -7,3 +7,4 @@ access_mail_notification_all,mail.notification.all,model_mail_notification,,1,1,
|
|||
access_mail_group,mail.group,model_mail_group,base.group_user,1,1,1,1
|
||||
access_mail_alias_user,mail.alias,model_mail_alias,base.group_user,1,1,1,0
|
||||
access_mail_alias_system,mail.alias,model_mail_alias,base.group_system,1,1,1,1
|
||||
access_mail_vote,mail.vote,model_mail_vote,base.group_user,1,1,1,1
|
||||
|
|
|
|
@ -275,6 +275,35 @@
|
|||
display: none;
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------*/
|
||||
/* Mail Vote System (Like or Unlike Comment)
|
||||
/*--------------------------------------------------------------*/
|
||||
|
||||
.oe_mail_vote_image{
|
||||
height='12px';
|
||||
width='16px';
|
||||
}
|
||||
|
||||
button.oe_mail_msg_vote_like{
|
||||
height:21px;
|
||||
width: 30px;
|
||||
padding: 1px;
|
||||
background: #8A89BA;
|
||||
margin-top: -4px;
|
||||
}
|
||||
|
||||
button.oe_mail_msg_vote_like:hover{
|
||||
background: #8A89BA;
|
||||
}
|
||||
|
||||
button.oe_mail_msg_vote_like span {
|
||||
color: white;
|
||||
}
|
||||
|
||||
span.oe_mail_vote_string{
|
||||
color: #807FB4;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/* mail.compose.message form view & OpenERP hacks
|
||||
/* ------------------------------------------------------------ */
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 892 B |
|
@ -559,6 +559,48 @@ openerp.mail = function(session) {
|
|||
return display_done && compose_done;
|
||||
},
|
||||
|
||||
//Mail vote Functionality...
|
||||
add_vote_event: function(element){
|
||||
vote_img = element.find('.oe_mail_msg_vote_like');
|
||||
self = this;
|
||||
if (vote_img)
|
||||
vote_img.click(function(){
|
||||
self.subscribe_vote($(this).attr('data-id'));
|
||||
});
|
||||
return
|
||||
},
|
||||
|
||||
find_parent_element: function(name, message_id){
|
||||
parent_element = false;
|
||||
_.each($(name), function(element){
|
||||
if ($(element).attr("data-id") == message_id){
|
||||
parent_element = element;
|
||||
}
|
||||
});
|
||||
return parent_element;
|
||||
},
|
||||
|
||||
render_vote: function(message_id){
|
||||
var self = this;
|
||||
this.mail_message = new session.web.DataSet(this, 'mail.message');
|
||||
this.mail_message.call('get_vote_summary',[[parseInt(message_id)]]).then(function(result){
|
||||
if (result){
|
||||
parent_element = self.find_parent_element(".oe_mail_msg_vote", message_id);
|
||||
vote_element = session.web.qweb.render('VoteDisplay', result);
|
||||
$(parent_element).html(vote_element);
|
||||
self.add_vote_event($(parent_element));
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
subscribe_vote: function(message_id){
|
||||
var self = this;
|
||||
this.mail_message = new session.web.DataSet(this, 'mail.message');
|
||||
return this.mail_message.call('vote_toggle', [[parseInt(message_id)]]).then(function(result){
|
||||
self.render_vote(message_id);
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Override-hack of do_action: automatically reload the chatter.
|
||||
* Normally it should be called only when clicking on 'Post/Send'
|
||||
|
@ -697,6 +739,10 @@ openerp.mail = function(session) {
|
|||
|
||||
display_comments: function (records) {
|
||||
var self = this;
|
||||
//Render Vote.
|
||||
_.each(records, function(record){
|
||||
self.render_vote(record.id);
|
||||
});
|
||||
// sort the records
|
||||
mail.ChatterUtils.records_struct_add_records(this.comments_structure, records, this.params.parent_id);
|
||||
//build attachments download urls and compute time-relative from dates
|
||||
|
@ -1119,7 +1165,7 @@ openerp.mail = function(session) {
|
|||
var records = self.comments_structure.tree_struct[root_id]['for_thread_msgs'];
|
||||
var model_name = self.comments_structure.msgs[root_id]['model'];
|
||||
var res_id = self.comments_structure.msgs[root_id]['res_id'];
|
||||
var render_res = session.web.qweb.render('mail.wall_thread_container', {});
|
||||
var render_res = session.web.qweb.render('mail.Wall_thread_container', {});
|
||||
$('<li class="oe_mail_wall_thread">').html(render_res).appendTo(self.$element.find('ul.oe_mail_wall_threads'));
|
||||
var thread = new mail.Thread(self, {
|
||||
'res_model': model_name, 'res_id': res_id, 'uid': self.session.uid, 'records': records,
|
||||
|
|
|
@ -45,7 +45,7 @@
|
|||
wall_thread_container template for the wall
|
||||
Each discussion thread is contained inside this template
|
||||
-->
|
||||
<t t-name="mail.wall_thread_container">
|
||||
<t t-name="mail.Wall_thread_container">
|
||||
</t>
|
||||
|
||||
<!--
|
||||
|
@ -118,6 +118,25 @@
|
|||
</div>
|
||||
</ul>
|
||||
|
||||
<!-- Vote system (Like or Unlike -->
|
||||
<t t-name="VoteDisplay">
|
||||
<t t-if='vote_count'>
|
||||
<span class="oe_left oe_mail_vote_string">Votes :<t t-esc="vote_count"/></span>
|
||||
</t>
|
||||
<li>
|
||||
<t t-if="!is_vote_liked">
|
||||
<button class="oe_mail_msg_vote_like" t-att-data-id="msg_id" title="Click to Vote.">
|
||||
<span>+1</span>
|
||||
</button>
|
||||
</t>
|
||||
<t t-if="is_vote_liked">
|
||||
<button class="oe_mail_msg_vote_like" t-att-data-id="msg_id" title="Click to Unvote." style="background:#DC5F59; padding:2px">
|
||||
<span>-1</span>
|
||||
</button>
|
||||
</t>
|
||||
</li>
|
||||
</t>
|
||||
|
||||
<!-- default layout -->
|
||||
<li t-name="mail.thread.message" class="oe_mail oe_mail_thread_msg">
|
||||
<div t-attf-class="oe_mail_msg_#{record.type}">
|
||||
|
@ -155,6 +174,7 @@
|
|||
<li t-if="record.subject & params.thread_level > 0"><a t-attf-href="#model=#{params.res_model}&id=#{params.res_id}"><t t-raw="record.record_name"/></a></li>
|
||||
<li><a t-attf-href="#model=res.users&id=#{record.user_id[0]}"><t t-raw="record.user_id[1]"/></a></li>
|
||||
<li><span t-att-title="record.date"><t t-raw="record.timerelative"/></span></li>
|
||||
<li> <span t-att-data-id="record.id" class="oe_mail_msg_vote"></span> </li>
|
||||
<li t-if="display['show_reply']"><a href="#" class="oe_mail_msg_reply">Reply</a></li>
|
||||
<!-- uncomment when merging vote
|
||||
<li><a href="#">Like</a></li>
|
||||
|
|
Loading…
Reference in New Issue