Atul Patel(OpenERP) has proposed merging
lp:~openerp-dev/openobject-addons/trunk-openchatter-mail_vote-part-4-atp into
lp:openobject-addons.
Requested reviews:
Thibault Delavallée (OpenERP) (tde-openerp)
For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-openchatter-mail_vote-part-4-atp/+merge/124010
Hello,
Add vote system (Like or unlike document comments)
Thanks
--
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-openchatter-mail_vote-part-4-atp/+merge/124010
Your team OpenERP R&D Team is subscribed to branch
lp:~openerp-dev/openobject-addons/trunk-openchatter-mail_vote-part-4-atp.
=== modified file 'mail/__init__.py'
--- mail/__init__.py 2012-08-17 11:19:36 +0000
+++ mail/__init__.py 2012-09-12 17:01:39 +0000
@@ -25,6 +25,7 @@
import mail_mail
import mail_thread
import mail_group
+import mail_vote
import res_partner
import res_users
import report
=== modified file 'mail/mail_message.py'
--- mail/mail_message.py 2012-09-07 11:54:22 +0000
+++ mail/mail_message.py 2012-09-12 17:01:39 +0000
@@ -124,6 +124,8 @@
'unread': fields.function(_get_unread, fnct_search=_search_unread,
type='boolean', string='Unread',
help='Functional field to search for unread messages linked to uid'),
+ 'vote_user_ids': fields.many2many('res.users', 'mail_vote', 'message_id', 'user_id', 'Votes'),
+
}
def _needaction_domain_get(self, cr, uid, context=None):
@@ -140,6 +142,24 @@
'author_id': lambda self, cr, uid, ctx={}: self._get_default_author(cr, uid, ctx),
'body': '',
}
+
+ #---------------------------------------------------
+ #Mail Vote system (Like or Unlike comments
+ #-----------------------------------------------------
+ def vote_toggle(self, cr, uid, ids, user_ids=None, context=None):
+ '''
+ Toggles when Comment is liked or unlike.
+ create vote entries if current user like comment..
+ '''
+ vote_pool = self.pool.get('mail.vote')
+ if not user_ids: user_ids = [uid]
+ for message in self.browse(cr, uid, ids, context):
+ voters_ids = [user.id for user in message.vote_user_ids if user.id == uid]
+ if not voters_ids:
+ self.write(cr, uid, ids, {'vote_user_ids': [(4, user_id) for user_id in user_ids]}, context=context)
+ else:
+ self.write(cr, uid, ids, {'vote_user_ids': [(3, user_id) for user_id in user_ids]}, context=context)
+ return True
#------------------------------------------------------
# Message loading for web interface
@@ -147,7 +167,18 @@
def _message_dict_get(self, cr, uid, msg, context=None):
""" Return a dict representation of the message browse record. """
+<<<<<<< TREE
attachment_ids = [{'id': attach[0], 'name': attach[1]} for attach in self.pool.get('ir.attachment').name_get(cr, uid, [x.id for x in msg.attachment_ids], context=context)]
+=======
+ vote_pool = self.pool.get('mail.vote')
+ has_voted = False;
+ vote_ids = []
+ attachment_ids = self.pool.get('ir.attachment').name_get(cr, uid, [x.id for x in msg.attachment_ids], context=context)
+ vote_ids = vote_pool.name_get(cr, uid, [user.id for user in msg.vote_user_ids], context=context)
+ for user_id in msg.vote_user_ids:
+ if (user_id.id == uid):
+ has_voted = True;
+>>>>>>> MERGE-SOURCE
author_id = self.pool.get('res.partner').name_get(cr, uid, [msg.author_id.id], context=context)[0]
author_user_id = self.pool.get('res.users').name_get(cr, uid, [msg.author_id.user_ids[0].id], context=context)[0]
partner_ids = self.pool.get('res.partner').name_get(cr, uid, [x.id for x in msg.partner_ids], context=context)
@@ -165,6 +196,8 @@
'author_user_id': author_user_id,
'partner_ids': partner_ids,
'child_ids': [],
+ 'vote_user_ids': vote_ids,
+ 'has_voted': has_voted
}
def message_read_tree_flatten(self, cr, uid, messages, current_level, level, context=None):
=== modified file 'mail/mail_thread.py'
--- mail/mail_thread.py 2012-09-05 16:01:45 +0000
+++ mail/mail_thread.py 2012-09-12 17:01:39 +0000
@@ -176,7 +176,7 @@
#------------------------------------------------------
# Automatic subscription when creating
#------------------------------------------------------
-
+
def create(self, cr, uid, vals, context=None):
""" Override to subscribe the current user. """
thread_id = super(mail_thread, self).create(cr, uid, vals, context=context)
=== added file 'mail/mail_vote.py'
--- mail/mail_vote.py 1970-01-01 00:00:00 +0000
+++ mail/mail_vote.py 2012-09-12 17:01:39 +0000
@@ -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 = {
+ 'message_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:
\ No newline at end of file
=== modified file 'mail/security/ir.model.access.csv'
--- mail/security/ir.model.access.csv 2012-08-13 19:38:41 +0000
+++ mail/security/ir.model.access.csv 2012-09-12 17:01:39 +0000
@@ -7,3 +7,4 @@
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
=== modified file 'mail/static/src/css/mail.css'
--- mail/static/src/css/mail.css 2012-09-12 14:02:24 +0000
+++ mail/static/src/css/mail.css 2012-09-12 17:01:39 +0000
@@ -264,6 +264,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
/* ------------------------------------------------------------ */
=== added file 'mail/static/src/img/vote.gif'
Binary files mail/static/src/img/vote.gif 1970-01-01 00:00:00 +0000 and mail/static/src/img/vote.gif 2012-09-12 17:01:39 +0000 differ
=== modified file 'mail/static/src/js/mail.js'
--- mail/static/src/js/mail.js 2012-09-12 11:28:32 +0000
+++ mail/static/src/js/mail.js 2012-09-12 17:01:39 +0000
@@ -309,6 +309,56 @@
return display_done && compose_done;
},
+ //Mail vote Functionality...
+ add_vote_event: function(element){
+ self = this;
+ vote_button = element.find('.oe_mail_msg_vote_like');
+ if (vote_button)
+ vote_button.click(function(){
+ self.subscribe_vote($(this).attr('data-id'));
+ });
+ return
+ },
+
+ // Fetch Records using updated message_id
+
+ fetch_voters: function (message_id) {
+ var self= this
+ this.ds_message.call('message_read', [[parseInt(message_id)]]).then(function(results){
+ _.each(results, function(result){
+ self.render_vote(result);
+ });
+ });
+ },
+ // Like and unlike..
+ subscribe_vote: function(message_id){
+ var self = this;
+ return this.ds_message.call('vote_toggle', [[parseInt(message_id)]]).then(function(result){
+ self.fetch_voters(message_id);
+ });
+ },
+ // Find parent element using current message id.
+
+ find_parent_element: function(elements, message_id){
+ parent_element = false;
+ _.each($(elements), function(element){
+ if ($(element).attr("data-id") == message_id){
+ parent_element = element;
+ }
+ });
+ return parent_element;
+ },
+
+ // Render vote Display template.
+ render_vote: function(record){
+ var self = this;
+ vote_element = session.web.qweb.render('VoteDisplay', {});
+ // Get all element from record..
+ vote_element = session.web.qweb.render('VoteDisplay', {'message_id': record.id, 'vote_count': record.vote_user_ids.length, 'has_voted': record.has_voted});
+ parent_element = self.find_parent_element(".oe_mail_msg_vote", record.id);
+ $(parent_element).html(vote_element).appendTo(this.add_vote_event($(parent_element)));
+ },
+
/** Customize the display
* - show_header_compose: show the composition form in the header */
do_customize_display: function() {
@@ -503,6 +553,9 @@
moreClass: 'oe_mail_expand',
lessClass: 'oe_mail_reduce',
});
+
+ //Render Votes.
+ this.render_vote(record);
},
/** Display 'show more' button */
=== modified file 'mail/static/src/xml/mail.xml'
--- mail/static/src/xml/mail.xml 2012-09-12 10:22:17 +0000
+++ mail/static/src/xml/mail.xml 2012-09-12 17:01:39 +0000
@@ -106,6 +106,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="!has_voted">
+ <button class="oe_mail_msg_vote_like" t-att-data-id="message_id" title="Click to Vote.">
+ <span>+1</span>
+ </button>
+ </t>
+ <t t-if="has_voted">
+ <button class="oe_mail_msg_vote_like" t-att-data-id="message_id" title="Click to Unvote." style="background:#DC5F59; padding:1px">
+ <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} oe_semantic_html_override">
@@ -137,6 +156,7 @@
</div>
<div class="oe_clear"/>
<ul class="oe_mail_msg_footer">
+<<<<<<< TREE
<li t-if="options.show_record_name & record.subject & options.thread_level > 0">
<a t-attf-href="#model=#{record.model}&id=#{record.res_id}"><t t-raw="record.record_name"/></a>
</li>
@@ -153,6 +173,22 @@
<t t-if="record.attachment_ids.length > 1"><t t-raw="record.attachment_ids.length"/> Attachments</t>
</a>
</li>
+=======
+ <li t-if="record.subject & params.thread_level > 0"><a t-attf-href="#model=#{record.model}&id=#{record.res_id}"><t t-raw="record.record_name"/></a></li>
+ <li><a t-attf-href="#model=res.partner&id=#{record.author_id[0]}"><t t-raw="record.author_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>
+ -->
+ <li t-if="record.attachment_ids.length > 0">
+ <a href="#" class="oe_mail_msg_view_attachments">
+ <t t-if="record.attachment_ids.length == 1">1 Attachment</t>
+ <t t-if="record.attachment_ids.length > 1"><t t-raw="record.attachment_ids.length"/> Attachments</t>
+ </a>
+ </li>
+>>>>>>> MERGE-SOURCE
</ul>
<t t-if="record.attachment_ids.length > 0">
<div class="oe_clear"></div>
_______________________________________________
Mailing list: https://launchpad.net/~openerp-dev-gtk
Post to : [email protected]
Unsubscribe : https://launchpad.net/~openerp-dev-gtk
More help : https://help.launchpad.net/ListHelp