[IMP] Improved code and passed the data according to the format as suggest (partner_i...
authorParamjit Singh Sahota <psa@tinyerp.com>
Mon, 15 Jul 2013 08:01:06 +0000 (13:31 +0530)
committerParamjit Singh Sahota <psa@tinyerp.com>
Mon, 15 Jul 2013 08:01:06 +0000 (13:31 +0530)
bzr revid: psa@tinyerp.com-20130715080106-63dbeh3mhgiqppzv

addons/mail/mail_thread.py
addons/mail/static/src/js/mail_followers.js
addons/mail/static/src/xml/mail_followers.xml

index ebd143e..949ed60 100644 (file)
@@ -156,21 +156,20 @@ class mail_thread(osv.AbstractModel):
                 res[id]['message_summary'] = "<span class='oe_kanban_mail_new' title='%s'><span class='oe_e'>9</span> %d %s</span>" % (title, res[id].pop('message_unread_count'), _("New"))
         return res
 
-    def read_followers_data(self, cr, uid, ids, context=None):
-        data = self.pool.get('res.partner').read(cr, uid, ids, ['name', 'user_ids'], context=context)
-
-        grp_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'base', 'group_no_one')
-        tech_user = self.pool.get('res.groups').read(cr, uid, grp_id[1], ['users'], context=context)['users']
-        user_pid = self.pool.get('res.users').read(cr, uid, uid, ['partner_id'], context=context)['partner_id'][0]
-
-        if uid in tech_user:
-            for dict in data:
-                if dict['id'] in [user_pid]:
-                    dict.update({'is_editable': True})
-                if uid in dict['user_ids']:
-                    dict.update({'is_uid': True})
-
-        return data
+    def read_followers_data(self, cr, uid, follower_ids, context=None):
+        datas = []
+        partner_pool = self.pool.get('res.partner')
+        technical_group = self.pool.get('ir.model.data').get_object(cr, uid, 'base', 'group_no_one')
+        for follower in partner_pool.browse(cr, uid, follower_ids, context=context):
+            is_editable = uid in map(lambda x:x.id, technical_group.users)
+            is_uid = uid in map(lambda x:x.id, follower.user_ids)
+            data = (
+                     follower.id,
+                     follower.name,
+                     {'is_editable': is_editable, 'is_uid': is_uid},
+            )
+            datas.append(data)
+        return datas
 
     def _get_subscription_data(self, cr, uid, ids, name, args, user_pid=None, context=None):
         """ Computes:
index 99c2a62..4fec4ff 100644 (file)
@@ -35,8 +35,6 @@ openerp_mail_followers = function(session, mail) {
             this.followers = [];
             
             this.view_is_editable = this.__parentedParent.is_action_enabled('edit');
-            this.check_access = false;
-            this.is_follower = false;
         },
 
         start: function() {
@@ -196,22 +194,17 @@ openerp_mail_followers = function(session, mail) {
         display_followers: function (records) {
             var self = this;
             this.followers = records || this.followers;
-            _.each(this.result, function (record) {
-                if (self.session.uid == record.user_ids[0]) {
-                    if (record.is_editable == true) { self.check_access = true; }
-                }
-            });
-            this.message_is_follower = this.set_is_follower(this.followers); // self.is_follower
             // clean and display title
             var node_user_list = this.$('.oe_follower_list').empty();
             this.$('.oe_follower_title').html(this._format_followers(this.followers.length));
             // truncate number of displayed followers
             var truncated = this.followers.slice(0, this.displayed_nb);
             _(truncated).each(function (record) {
-                record.avatar_url = mail.ChatterUtils.get_image(self.session, 'res.partner', 'image_small', record.id);
+                self.message_is_follower = record[2].is_uid;
+                record[2].avatar_url = mail.ChatterUtils.get_image(self.session, 'res.partner', 'image_small', record[0]);
                 $(session.web.qweb.render('mail.followers.partner', {'record': record, 'widget': self})).appendTo(node_user_list);
                 // On mouse-enter it will show the edit_subtype pencil.
-                if (self.check_access == true) {
+                if (record[2].is_editable == true) {
                     self.$el.on('mouseenter', 'div.oe_follower_list', function() {
                         $("img.oe_edit_subtype").removeClass("hidden");
                         $('div.oe_follower_list').find('.oe_partner').addClass('oe_partner_name');
@@ -227,12 +220,6 @@ openerp_mail_followers = function(session, mail) {
             }
         },
 
-        /** Computes whether the current user is in the followers */
-        set_is_follower: function (records) {
-            var user_ids = _.pluck(_.pluck(records, 'user_ids'), 0);
-            return _.indexOf(user_ids, this.session.uid) != -1;
-        },
-
         display_buttons: function () {
             if (this.message_is_follower) {
                 this.$('button.oe_follower').removeClass('oe_notfollow').addClass('oe_following');
index db58abb..d231540 100644 (file)
         Template used to display a partner following the record
         -->
     <div t-name="mail.followers.partner" class='oe_partner'>
-        <img class="oe_mail_thumbnail oe_mail_frame" t-attf-src="{record.avatar_url}"/>
-        <a t-attf-href="#model=res.partner&amp;id=#{record.id}" t-att-title="record.name"><t t-esc="record.name"/></a>
-        <img t-if="widget.check_access and (widget.records_length &gt; 1)" class="oe_edit_subtype hidden" t-att-src='_s + "/mail/static/src/img/icon-edit.gif"' title="Edit Subtype" t-att-data-id="record.id"/>
-        <span t-if="widget.view_is_editable" class="oe_remove_follower oe_e" title="Remove this follower" t-att-data-id="record.id">X</span>
+        <img class="oe_mail_thumbnail oe_mail_frame" t-attf-src="{record[2].avatar_url}"/>
+        <a t-attf-href="#model=res.partner&amp;id=#{record[0]}" t-att-title="record[1]"><t t-esc="record[1]"/></a>
+        <img t-if="record[2].is_editable" class="oe_edit_subtype hidden" t-att-src='_s + "/mail/static/src/img/icon-edit.gif"' title="Edit Subtype" t-att-data-id="record[0]"/>
+        <span t-if="widget.view_is_editable" class="oe_remove_follower oe_e" title="Remove this follower" t-att-data-id="record[0]">X</span>
     </div>
     
     <!--