Nimesh Contractor(Open ERP) has proposed merging 
lp:~openerp-dev/openobject-addons/trunk-open-chatter-part-4-atp-add_mail_vote-nco
 into lp:~openerp-dev/openobject-addons/trunk-open-chatter-part-4-atp.

Requested reviews:
  Atul Patel(OpenERP) (atp-openerp)

For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-open-chatter-part-4-atp-add_mail_vote-nco/+merge/114420

Hello sir,

          I have added vote functionality in mail module.

Thanks,
 NCO.
-- 
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-open-chatter-part-4-atp-add_mail_vote-nco/+merge/114420
Your team OpenERP R&D Team is subscribed to branch 
lp:~openerp-dev/openobject-addons/trunk-open-chatter-part-4-atp.
=== modified file 'mail/__init__.py'
--- mail/__init__.py	2012-06-08 13:23:12 +0000
+++ mail/__init__.py	2012-07-11 13:30:40 +0000
@@ -21,6 +21,7 @@
 
 import mail_message
 import mail_thread
+import mail_vote
 import mail_group
 import mail_subscription
 import ir_needaction

=== modified file 'mail/mail_thread.py'
--- mail/mail_thread.py	2012-07-03 01:47:57 +0000
+++ mail/mail_thread.py	2012-07-11 13:30:40 +0000
@@ -64,12 +64,19 @@
 
     def _get_message_ids(self, cr, uid, ids, name, args, context=None):
         res = {}
+        msg_obj = self.pool.get('mail.message')
+        img_vote = "<img  height='12px' width='16px' src='/mail_extra/static/src/img/vote.gif'/>"
         for id in ids:
+            vote_list = []
             message_ids = self.message_load_ids(cr, uid, [id], context=context)
             subscriber_ids = self.message_get_subscribers(cr, uid, [id], context=context)
+            for msg_id in message_ids:
+                msg = msg_obj.browse(cr, uid, msg_id, context=context)
+                if msg.vote_ids:
+                    vote_list.append(msg.vote_ids) 
             res[id] = {
                 'message_ids': message_ids,
-                'message_summary': "<span>Msg: %d</span> . <span>Fol: %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
 

=== renamed file 'mail_extra/mail_vote.py' => 'mail/mail_vote.py'
=== modified file 'mail/security/ir.model.access.csv'
--- mail/security/ir.model.access.csv	2012-06-22 11:55:12 +0000
+++ mail/security/ir.model.access.csv	2012-07-11 13:30:40 +0000
@@ -5,3 +5,4 @@
 access_mail_subscription,mail.subscription,model_mail_subscription,,1,1,1,1
 access_mail_notification,mail.notification,model_mail_notification,,1,1,1,1
 access_mail_group,mail.group,model_mail_group,base.group_user,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-07-04 10:01:31 +0000
+++ mail/static/src/css/mail.css	2012-07-11 13:30:40 +0000
@@ -368,6 +368,28 @@
     content: "";
 }
 
+/*vote*/
+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;
+}
+
+
 /* Attachments list */
 .openerp ul.oe_mail_msg_attachments {
     display: none;

=== renamed file 'mail_extra/static/src/img/vote.gif' => 'mail/static/src/img/vote.gif'
=== modified file 'mail/static/src/js/mail.js'
--- mail/static/src/js/mail.js	2012-07-10 07:11:38 +0000
+++ mail/static/src/js/mail.js	2012-07-11 13:30:40 +0000
@@ -214,7 +214,47 @@
                 return false;
             });
         },
-        
+        /* add 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);
+            });
+        },
         destroy: function () {
             this._super.apply(this, arguments);
         },
@@ -255,7 +295,10 @@
         
         display_comments: function (records) {
             var self = this;
-            
+            //tg.render_vote(records.id);
+            _.each(records, function(record){
+                self.render_vote(record.id);
+            });
             //build attachments download urls and compute time-relative from dates
             for (var k in records) {
                 records[k].timerelative = $.timeago(records[k].date);

=== modified file 'mail/static/src/xml/mail.xml'
--- mail/static/src/xml/mail.xml	2012-07-10 07:11:38 +0000
+++ mail/static/src/xml/mail.xml	2012-07-11 13:30:40 +0000
@@ -78,7 +78,23 @@
             <button class="oe_mail_button_more" type="button">Load more messages</button>
         </div>
     </div>
-
+    <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 -->
     <div t-name="mail.Thread.message" class="oe_mail oe_mail_thread_msg">
         <div t-attf-class="oe_mail_msg_#{record.type}">
@@ -107,11 +123,9 @@
                         <t t-raw="record.body"/>
                     </div>
                     <ul class="oe_mail_msg_footer">
-                      <li class="oe_comment_time_info"><span t-att-title="record.date"><t t-raw="record.timerelative"/></span></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">Attachment</t>

=== modified file 'mail_extra/__init__.py'
--- mail_extra/__init__.py	2012-07-11 10:08:31 +0000
+++ mail_extra/__init__.py	2012-07-11 13:30:40 +0000
@@ -19,7 +19,6 @@
 #
 ##############################################################################
 
-import mail_vote
 import mail_checklist
 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
 

=== modified file 'mail_extra/mail_checklist.py'
--- mail_extra/mail_checklist.py	2012-07-11 10:25:47 +0000
+++ mail_extra/mail_checklist.py	2012-07-11 13:30:40 +0000
@@ -89,7 +89,6 @@
         res = super(mail_thread, self)._get_message_ids(cr, uid, ids, name, args, context=context)
         msg_obj = self.pool.get('mail.message')
         for key in res.keys():
-            vote_list = []
             total_items = 0
             total_done_items = 0
             for msg_id in res[key]['message_ids']:
@@ -99,18 +98,14 @@
                     for item in filter(lambda x:x.done == True , msg.checklist_item_ids):
                         total_done_items += 1
                     total_items += len(msg.checklist_item_ids)
-                # Count the number of votes.
-                if msg.vote_ids:
-                    vote_list.append(msg.vote_ids)
-            img_vote = "<img  height='12px' width='16px' src='/mail_extra/static/src/img/vote.gif'/>"
             img_checklist = "<img  height='12px' width='16px' src='/mail_extra/static/src/img/checklist.png'/>"
-            res[key]['message_summary'] +=  " <span> %s  %d</span> . <span> %s %d/%d</span>"% (img_vote,len(vote_list),img_checklist,total_done_items,total_items)
+            res[key]['message_summary'] +=  " . <span> %s %d/%d</span>"% (img_checklist,total_done_items,total_items)
         return res
     
     _columns = {
         'message_summary': fields.function(_get_message_ids, method=True,
             type='text', string='Summary', multi="_get_message_ids",
-            help="Holds the Chatter summary (number of messages, items, votes...). "\
+            help="Holds the Chatter summary (number of messages, items). "\
                  "This summary is directly in html format in order to "\
                  "be inserted in kanban views."),
     }

=== modified file 'mail_extra/security/ir.model.access.csv'
--- mail_extra/security/ir.model.access.csv	2012-06-12 10:19:02 +0000
+++ mail_extra/security/ir.model.access.csv	2012-07-11 13:30:40 +0000
@@ -1,3 +1,2 @@
 id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
-access_mail_vote,mail.vote,model_mail_vote,base.group_user,1,1,1,1
 access_mail_checklist_item,mail.checklist.item,model_mail_checklist_item,base.group_user,1,1,1,0

=== modified file 'mail_extra/static/src/css/mail_extra.css'
--- mail_extra/static/src/css/mail_extra.css	2012-07-09 06:51:32 +0000
+++ mail_extra/static/src/css/mail_extra.css	2012-07-11 13:30:40 +0000
@@ -47,22 +47,3 @@
     height:4px;
 }
 
-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;
-}

=== modified file 'mail_extra/static/src/js/mail_extra.js'
--- mail_extra/static/src/js/mail_extra.js	2012-07-11 10:25:47 +0000
+++ mail_extra/static/src/js/mail_extra.js	2012-07-11 13:30:40 +0000
@@ -109,36 +109,6 @@
                 $('.oe_checklist_item').css({'display':'block'})
             });
         },
-        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
-        },
-        
-        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 = 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);
-            });
-        },
 
         display_comments: function(records){
             res = this._super(records);
@@ -147,7 +117,6 @@
             var chklst_item = new session.mail_extra.CheckListItem();
             // set focus on  checklist item 
             _.each(records, function(record){
-                self.render_vote(record.id);
                 self.render_checklist_items(record.id);
             });
         },

=== modified file 'mail_extra/static/src/xml/mail_extra.xml'
--- mail_extra/static/src/xml/mail_extra.xml	2012-07-03 11:45:33 +0000
+++ mail_extra/static/src/xml/mail_extra.xml	2012-07-11 13:30:40 +0000
@@ -38,35 +38,12 @@
     </t>
     
     <t t-extend="mail.Thread.message">
-        <t t-jquery=".oe_comment_time_info" t-operation="after">
-            <t t-if="record.type == 'comment'">
-                <span t-att-data-id="record.id" class="oe_mail_msg_vote"></span>
-            </t>
-        </t>
         <t t-jquery=".oe_mail_msg_body" t-operation="append">
             <div t-att-data-id="record.id" class="oe_mail_msg_checklist">
             </div>
         </t>
     </t>
     
-    <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>
-    
     <div t-name = "AddChecklist" class="oe_mail_msg_checklist_new">
         <input type="checkbox" class="oe_mail_msg_checklist_item"/>
         <input type="text" id = "txt_name" size = "20" placeholder="todo item.."></input>

_______________________________________________
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

Reply via email to