From 52f8ea85c8d0f33004bf74b54a9f1c723a581204 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Tue, 9 Oct 2012 10:44:36 +0200 Subject: [PATCH] [IMP] mail: get free user attachment bzr revid: chm@openerp.com-20121009084436-13r1hz3movoupvmh --- addons/mail/mail_message.py | 10 ++++++++++ addons/mail/mail_thread.py | 3 +-- addons/mail/static/src/js/mail.js | 20 ++++++++++++++++---- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/addons/mail/mail_message.py b/addons/mail/mail_message.py index 53811385052..89981b99389 100644 --- a/addons/mail/mail_message.py +++ b/addons/mail/mail_message.py @@ -343,6 +343,16 @@ class mail_message(osv.Model): return result + def user_free_attachment(self, cr, uid, context=None): + attachment_list = [] + + attachment = self.pool.get('ir.attachment') + attachment_ids = attachment.search(cr, uid, [('res_model','=',''),('create_uid','=',uid)]) + if len(attachment_ids): + attachment_list = [{'id': attach[0], 'name': attach[1]} for attach in attachment.name_get(cr, uid, attachment_ids, context=context)] + + return attachment_list + #------------------------------------------------------ # Email api #------------------------------------------------------ diff --git a/addons/mail/mail_thread.py b/addons/mail/mail_thread.py index 4e8d036d68a..a4a6f7af2fa 100644 --- a/addons/mail/mail_thread.py +++ b/addons/mail/mail_thread.py @@ -711,8 +711,7 @@ class mail_thread(osv.AbstractModel): if attachment_ids: self.pool.get('ir.attachment').write(cr, 1, attachment_ids, { 'res_model': self._name, 'res_id': thread_id }, context=context) self.pool.get('mail.message').write(cr, 1, [added_message_id], {'attachment_ids': [(6, 0, [pid for pid in attachment_ids])]} ) - - + added_message = self.pool.get('mail.message').message_read(cr, uid, [added_message_id]) return added_message diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index 8fab771fcc0..7fe3cee8a82 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -164,6 +164,7 @@ openerp.mail = function(session) { session.web.blockUI(); var form = self.$('form.oe_form_binary_form'); form.submit(); + $target.after($target.clone(true)).remove(); } }, on_attachment_loaded: function (event, result) { @@ -185,17 +186,27 @@ openerp.mail = function(session) { if (attachment_id) { var attachments=[]; for(var i in this.attachment_ids){ - if(attachment_id!=this.attachment_ids[i].id) + if(attachment_id!=this.attachment_ids[i].id){ attachments.push(this.attachment_ids[i]); + } + else { + var ds_attachment = new session.web.DataSetSearch(this, 'ir.attachment'); + ds_attachment.unlink([attachment_id]); + } } this.attachment_ids = attachments; this.display_attachments(); - - var ds_attachment = new session.web.DataSetSearch(this, 'ir.attachment'); - ds_attachment.unlink([attachment_id]); } }, + set_free_attachments: function(){ + var self=this; + this.parent_thread.ds_message.call('user_free_attachment').then(function(attachments){ + self.attachment_ids=attachments; + self.display_attachments(); + }); + }, + bind_events: function() { var self = this; @@ -764,6 +775,7 @@ openerp.mail = function(session) { if(this.options.thread.show_header_compose){ this.ComposeMessage.$el.show(); + this.ComposeMessage.set_free_attachments(); } var button_flesh = $('