Bharat Devnani (Open ERP) has proposed merging 
lp:~openerp-dev/openobject-addons/trunk-open-chatter-part-4-atp-vote-system-bde 
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-vote-system-bde/+merge/104905

Hello Sir,

I have improved the functionality of voting and  defined functions in .py 
instead of .js

Thanks & Regards,
Devnani Bharat R.


-- 
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-open-chatter-part-4-atp-vote-system-bde/+merge/104905
Your team OpenERP R&D Team is subscribed to branch 
lp:~openerp-dev/openobject-addons/trunk-open-chatter-part-4-atp.
=== modified file 'mail/mail_message.py'
--- mail/mail_message.py	2012-04-06 12:37:32 +0000
+++ mail/mail_message.py	2012-05-07 13:19:19 +0000
@@ -599,5 +599,5 @@
     def cancel(self, cr, uid, ids, context=None):
         self.write(cr, uid, ids, {'state':'cancel'}, context=context)
         return True
-
+    
 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

=== modified file 'mail/mail_thread.py'
--- mail/mail_thread.py	2012-04-06 12:37:32 +0000
+++ mail/mail_thread.py	2012-05-07 13:19:19 +0000
@@ -788,5 +788,44 @@
             notif_msg_ids = msg_ids
         to_del_notif_ids = notif_obj.search(cr, uid, ['&', ('user_id', '=', uid), ('message_id', 'in', notif_msg_ids)], context=context)
         return notif_obj.unlink(cr, uid, to_del_notif_ids, context=context)
+    
+class mail_vote(osv.osv):
+    _name = 'mail.vote'
+    _description = 'Mail Vote'
+    
+    def message_get_vote_number(self, cr, uid, ids, model, context=None):
+        vote_obj = self.pool.get('mail.vote')
+        voters_ids = vote_obj.search(cr, uid, ['&', ('res_model_id', '=', model), ('res_id', '=', ids[0])], context=context)
+        subs = vote_obj.read(cr, uid, voters_ids, context=context)
+        return len(subs)
+    
+    def vote_subscribe(self, cr, uid, ids, model, user_ids = None, context=None):
+        vote_obj = self.pool.get('mail.vote')
+        voters_ids = vote_obj.search(cr, uid, ['&', ('res_model_id', '=', model), ('res_id', '=', ids[0]), ('user_id', '=', uid)], context=context)
+        if not voters_ids:
+            create_record = vote_obj.create(cr, uid, {'res_model_id': model[0], 'res_id': ids[0], 'user_id': uid}, context=context)
+            return create_record
+        else:
+            return False
+        
+    def check_user_model_resource(self, cr, uid, ids, model, context=None):
+        vote_obj = self.pool.get('mail.vote')
+        voters_id = vote_obj.search(cr, uid, ['&', ('res_model_id', '=', model), ('res_id', '=', ids[0]), ('user_id', '=', uid)], context=context)
+        return voters_id
+        
+    def vote_unsubscribe(self, cr, uid, ids, model, context=None):
+        vote_obj = self.pool.get('mail.vote')
+        voters_id = self.check_user_model_resource(cr, uid, ids, model, context=None)
+        vote_obj.unlink(cr, uid, voters_id, context=context)
+        return True
+    
+    _columns = {
+            'res_model_id': fields.char('Related Document Model', size=64),
+            'res_id': fields.char('Related Document ID', size=32),
+            'user_id': fields.many2one('res.users', 'User'),
+#            'vote_summary': fields.function(_get_votes, string='Vote Summary'),
+        }
+    
+mail_vote()
 
 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

=== modified file 'mail/static/src/js/mail.js'
--- mail/static/src/js/mail.js	2012-04-19 08:58:38 +0000
+++ mail/static/src/js/mail.js	2012-05-07 13:19:19 +0000
@@ -480,14 +480,17 @@
             this._super.apply(this, arguments);
             this.see_subscribers = true;
             this.thread = null;
+            
             // datasets
             this.ds = new session.web.DataSet(this, this.view.model);
             this.ds_users = new session.web.DataSet(this, 'res.users');
+            this.mail_vote = new session.web.DataSetSearch(this, 'mail.vote', null, null);
         },
 
         start: function() {
             this._super.apply(this, arguments);
             var self = this;
+            
             // bind buttons
             this.$element.find('button.oe_mail_button_followers').click(function () { self.do_toggle_followers(); }).hide();
             this.$element.find('button.oe_mail_button_follow').click(function () { self.do_follow(); })
@@ -496,18 +499,63 @@
             this.$element.find('button.oe_mail_button_unfollow').click(function () { self.do_unfollow(); })
                 .mouseover(function () { $(this).html('Unfollow').removeClass('oe_mail_button_mouseout').addClass('oe_mail_button_mouseover'); })
                 .mouseleave(function () { $(this).html('Following').removeClass('oe_mail_button_mouseover').addClass('oe_mail_button_mouseout'); });
+            this.$element.find('button.oe_mail_button_like').click(function () { self.create_entry(); });
+            this.$element.find('button.oe_mail_button_unlike').click(function () { self.delete_entry(); }).hide();
             this.reinit();
         },
-
+        
+        create_entry: function () {
+            this.$element.find('button.oe_mail_button_like').hide();
+            this.$element.find('button.oe_mail_button_unlike').show();
+            return this.mail_vote.call('vote_subscribe', [[this.view.datarecord.id],[this.view.model]]).pipe(this.proxy('fetch_vote_subscribers'));
+        },
+        
+        delete_entry: function () {
+            this.$element.find('button.oe_mail_button_like').show();
+            this.$element.find('button.oe_mail_button_unlike').hide();
+            return this.mail_vote.call('vote_unsubscribe', [[this.view.datarecord.id],[this.view.model]]).pipe(this.proxy('fetch_vote_subscribers'));
+        },
+        
+        fetch_vote_subscribers: function () {
+            return this.mail_vote.call('message_get_vote_number', [[this.view.datarecord.id],[this.view.model]]).then(this.proxy('display_votes'));
+        },
+            
+        display_votes: function(records){
+            var sub_node = this.$element.find('div.oe_votes')
+            sub_node.empty();
+            this.$element.find('div.oe_votes').show();
+            
+            if (! records){
+                $('<h4/>').html('Likes (' + (0) + ')').appendTo(sub_node);
+            }
+            else 
+            {
+                $('<h4/>').html('Likes (' + (records) + ')').appendTo(sub_node);
+            }
+        },
+        
         destroy: function () {
             this._super.apply(this, arguments);
         },
         
         reinit: function() {
+            var self = this;
             this.see_subscribers = true;
             this.$element.find('button.oe_mail_button_followers').html('Hide followers')
             this.$element.find('button.oe_mail_button_follow').hide();
             this.$element.find('button.oe_mail_button_unfollow').hide();
+            this.fetch_vote_subscribers();
+            self.mail_vote.call('check_user_model_resource', [[this.view.datarecord.id],[this.view.model]]).then(function (record) {
+                var vote_count = record.length;
+                if (vote_count == 0){
+                    self.$element.find('button.oe_mail_button_like').show();
+                }
+                else
+                {
+                    self.$element.find('button.oe_mail_button_like').hide();
+                    self.$element.find('button.oe_mail_button_unlike').show();
+                }
+            })
         },
         
         set_value: function() {
@@ -553,6 +601,7 @@
                 self.$element.find('button.oe_mail_button_unfollow').hide(); }
         },
         
+        
         do_follow: function () {
             return this.ds.call('message_subscribe', [[this.view.datarecord.id]]).pipe(this.proxy('fetch_subscribers'));
         },

=== modified file 'mail/static/src/xml/mail.xml'
--- mail/static/src/xml/mail.xml	2012-04-18 11:32:17 +0000
+++ mail/static/src/xml/mail.xml	2012-05-07 13:19:19 +0000
@@ -33,8 +33,14 @@
             <div class="oe_mail_recthread_actions">
                 <button type="button" class="oe_mail_button_follow oe_mail_button_mouseout">Not following</button>
                 <button type="button" class="oe_mail_button_unfollow oe_mail_button_mouseout">Following</button>
+                <button type="button" class="oe_mail_button_like oe_mail_button_mouseout">Like</button>
+                <button type="button" class="oe_mail_button_unlike oe_mail_button_mouseout">Unlike</button>
+                <br/>
                 <button type="button" class="oe_mail_button_followers">Display followers</button>
             </div>
+            <div class="oe_votes">
+                <h4>Likes</h4>
+            </div>
             <div class="oe_mail_recthread_followers">
                 <h4>Followers</h4>
                 <div class="oe_mail_followers_display">

_______________________________________________
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