[IMP] Threzad widget: added unlink mechanism. Still WIP tough.
authorThibault Delavallée <tde@openerp.com>
Tue, 13 Mar 2012 17:41:05 +0000 (18:41 +0100)
committerThibault Delavallée <tde@openerp.com>
Tue, 13 Mar 2012 17:41:05 +0000 (18:41 +0100)
bzr revid: tde@openerp.com-20120313174105-ffncns931oa0ry4o

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

index a999c6d..93785c8 100644 (file)
@@ -647,7 +647,7 @@ class mail_thread(osv.osv):
     
     def message_append_note(self, cr, uid, ids, subject, body, parent_id=False, type='notification', context=None):
         return self.message_append(cr, uid, ids, subject, body_text=body, parent_id=parent_id, type=type, context=context)
-            
+    
     #------------------------------------------------------
     # Subscription mechanism
     #------------------------------------------------------
index 9d11756..cffce1b 100644 (file)
@@ -50,6 +50,7 @@ openerp.mail = function(session) {
             /* DataSets and internal vars */
             this.ds = new session.web.DataSet(this, this.params.res_model);
             this.ds_users = new session.web.DataSet(this, 'res.users');
+            this.ds_msg = new session.web.DataSet(this, 'mail.message');
             this.name = 'Unknown record'
             this.sorted_comments = {'root_ids': [], 'root_id_msg_list': {}};
             /* Display vars */
@@ -76,10 +77,10 @@ openerp.mail = function(session) {
                 if (event.shiftKey && charCode == 13) { this.value = this.value+"\n"; }
                 else if (charCode == 13) { self.do_comment(); }
             });
-            this.$element.find('div.oe_mail_thread_display').delegate('a.oe_mail_msg_reply', 'click', function (event) {
-               var act_dom = $(this).parents('div.oe_mail_thread_display').find('div.oe_mail_thread_act:first');
-               act_dom.toggle();
-            });
+            
+            // add event
+            this.add_events();
+            
             this.$element.find('div.oe_mail_thread_display').delegate('a.intlink', 'click', function (event) {
                 // lazy implementation: fetch data and try to redirect
                 if (! event.srcElement.dataset.resModel) return false;
@@ -109,6 +110,23 @@ openerp.mail = function(session) {
             return display_done
         },
         
+        add_events: function() {
+            var self = this;
+            // event: click on 'reply'
+            this.$element.find('div.oe_mail_thread_display').delegate('a.oe_mail_msg_reply', 'click', function (event) {
+               var act_dom = $(this).parents('div.oe_mail_thread_display').find('div.oe_mail_thread_act:first');
+               act_dom.toggle();
+            });
+            // event: click on 'delete'
+            this.$element.find('div.oe_mail_thread_display').delegate('a.oe_mail_msg_delete', 'click', function (event) {
+               console.log('deleting');
+               var msg_id = event.srcElement.dataset.id;
+               if (! msg_id) return false;
+               self.ds_msg.unlink([parseInt(msg_id)]).then();
+               return false;
+            });
+        },
+        
         stop: function () {
             //this._super.apply(this, arguments);
         },
index c2eef54..c9ab259 100644 (file)
@@ -77,8 +77,8 @@
                 on <t t-raw="record.date"/>
             </span>
             <t t-if="display.show_reply"><span class="oe_mail_oe_space"><a href="#" class="oe_mail_msg_reply">Reply</a></span></t>
-            <t t-if="display.show_delete"><span class="oe_mail_oe_space"><a href="#" class="oe_mail_msg_delete">Delete</a></span></t>
-            <t t-if="display.show_hide"><span class="oe_mail_oe_space"><a href="#" class="oe_mail_msg_hide">Hide</a></span></t>
+            <t t-if="display.show_delete"><span class="oe_mail_oe_space"><a href="#" t-attf-data-id='{record.id}' class="oe_mail_msg_delete">Delete</a></span></t>
+            <t t-if="display.show_hide"><span class="oe_mail_oe_space"><a href="#" t-attf-data-id='{record.id}' class="oe_mail_msg_hide">Hide</a></span></t>
         </p>
     </t>