[IMP]Changed the position of methods and improved code.
authorParamjit Singh Sahota <psa@tinyerp.com>
Tue, 19 Mar 2013 07:33:19 +0000 (13:03 +0530)
committerParamjit Singh Sahota <psa@tinyerp.com>
Tue, 19 Mar 2013 07:33:19 +0000 (13:03 +0530)
bzr revid: psa@tinyerp.com-20130319073319-8myj2hx5iaqmi5xj

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

index 6ead2c9..ddbbf8a 100644 (file)
@@ -140,40 +140,6 @@ class mail_thread(osv.AbstractModel):
             res[fol.res_id]['message_subtype_data'] = thread_subtype_dict
         return res
 
-    def edit_followers_subtype(self, cr, uid, ids, partner_id, context=None):
-        res = dict((id, dict(message_subtype_data='')) for id in ids)
-
-        subtype_obj = self.pool.get('mail.message.subtype')
-        subtype_ids = subtype_obj.search(cr, uid, ['|', ('res_model', '=', self._name), ('res_model', '=', False)], context=context)
-        subtype_dict = dict((subtype.name, dict(default=subtype.default, followed=False, id=subtype.id)) for subtype in subtype_obj.browse(cr, uid, subtype_ids, context=context))
-        for id in ids:
-            res[id]['message_subtype_data'] = subtype_dict.copy()
-
-        fol_obj = self.pool.get('mail.followers')
-        fol_ids = fol_obj.search(cr, uid, [
-            ('partner_id', '=', partner_id),
-            ('res_id', 'in', ids),
-            ('res_model', '=', self._name),
-        ], context=context)
-        for fol in fol_obj.browse(cr, uid, fol_ids, context=context):
-            thread_subtype_dict = res[fol.res_id]['message_subtype_data']
-            for subtype in fol.subtype_ids:
-                thread_subtype_dict[subtype.name]['followed'] = True
-            res[fol.res_id]['message_subtype_data'] = thread_subtype_dict
-        return res
-
-    def apply_edited_subtypes(self, cr, uid, ids, partner_id, check_list, context=None):
-        """ Apply the edited subtypes
-                  of the user."""
-        fol_obj = self.pool.get('mail.followers')
-        fol_ids = fol_obj.search(cr, uid, [
-            ('partner_id', '=', partner_id),
-            ('res_id', 'in', ids),
-            ('res_model', '=', self._name),
-        ], context=context)
-        fol_obj.write(cr, uid, fol_ids, {'subtype_ids': [(6,0, check_list)]}, context=context)
-        return True
-
     def _search_message_unread(self, cr, uid, obj=None, name=None, domain=None, context=None):
         return [('message_ids.to_read', '=', True)]
 
@@ -324,6 +290,43 @@ class mail_thread(osv.AbstractModel):
         return super(mail_thread, self).copy(cr, uid, id, default=default, context=context)
 
     #------------------------------------------------------
+    # Edit and apply followers subtypes.
+    #------------------------------------------------------
+    def edit_followers_subtype(self, cr, uid, ids, partner_id, context=None):
+        res = dict((id, dict(message_subtype_data='')) for id in ids)
+
+        subtype_obj = self.pool.get('mail.message.subtype')
+        subtype_ids = subtype_obj.search(cr, uid, ['|', ('res_model', '=', self._name), ('res_model', '=', False)], context=context)
+        subtype_dict = dict((subtype.name, dict(default=subtype.default, followed=False, id=subtype.id)) for subtype in subtype_obj.browse(cr, uid, subtype_ids, context=context))
+        for id in ids:
+            res[id]['message_subtype_data'] = subtype_dict.copy()
+
+        fol_obj = self.pool.get('mail.followers')
+        fol_ids = fol_obj.search(cr, uid, [
+            ('partner_id', '=', partner_id),
+            ('res_id', 'in', ids),
+            ('res_model', '=', self._name),
+        ], context=context)
+        for fol in fol_obj.browse(cr, uid, fol_ids, context=context):
+            thread_subtype_dict = res[fol.res_id]['message_subtype_data']
+            for subtype in fol.subtype_ids:
+                thread_subtype_dict[subtype.name]['followed'] = True
+            res[fol.res_id]['message_subtype_data'] = thread_subtype_dict
+        return res
+
+    def apply_edited_subtypes(self, cr, uid, ids, partner_id, check_list, context=None):
+        """ Apply the edited subtypes
+                  of the user."""
+        fol_obj = self.pool.get('mail.followers')
+        fol_ids = fol_obj.search(cr, uid, [
+            ('partner_id', '=', partner_id),
+            ('res_id', 'in', ids),
+            ('res_model', '=', self._name),
+        ], context=context)
+        fol_obj.write(cr, uid, fol_ids, {'subtype_ids': [(6,0, check_list)]}, context=context)
+        return True
+
+    #------------------------------------------------------
     # Automatically log tracked fields
     #------------------------------------------------------
 
index 9a9f5f2..1ca6508 100644 (file)
@@ -92,9 +92,9 @@ openerp_mail_followers = function(session, mail) {
                             buttons: [
                                     { text: _t("Apply"), click: function() { 
                                         self.on_apply_subtype(id, partner_id);
-                                        $dialog.remove();
+                                        $(this).remove();
                                     }},
-                                    { text: _t("Cancel"), click: function() { $dialog.remove(); }}
+                                    { text: _t("Cancel"), click: function() { $(this).remove(); }}
                                 ],
                     });
             this.ds_model.call('edit_followers_subtype', [[id], partner_id, new session.web.CompoundContext(this.build_context(), {})])
index 4a492ce..ea11c26 100644 (file)
         </table>
     </t>
 
+    <!--
+        followers.edit.subtype template
+        Template used to edit the display message subtypes of a follower subscription
+    -->
     <t t-name="mail.followers.edit.subtype">
         <table class='oe_subtype'>
             <tr>