From 48c6ea72ff94a156995aeb08089dab9bfec4e11c Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Fri, 30 Nov 2012 10:06:55 +0100 Subject: [PATCH] [FIX] web form : catch and display error when there are an error in an attachment upload bzr revid: chm@openerp.com-20121130090655-gmymwe1z1ofl7wn9 --- addons/mail/static/src/js/mail.js | 56 ++++++++++++++++++++----------- 1 file changed, 36 insertions(+), 20 deletions(-) diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index a5beaac229f..e08f828d272 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -422,15 +422,25 @@ openerp.mail = function (session) { /* when the file is uploaded */ on_attachment_loaded: function (event, result) { - for (var i in this.attachment_ids) { - if (this.attachment_ids[i].filename == result.filename && this.attachment_ids[i].upload) { - this.attachment_ids[i]={ - 'id': result.id, - 'name': result.name, - 'filename': result.filename, - 'url': mail.ChatterUtils.get_attachment_url(this.session, result) - }; + + if (result.erorr || !result.id ) { + + this.do_warn(result.title, result.erorr); + this.attachment_ids = _.filter(this.attachment_ids, function (val) { return !val.upload; }); + + } else { + + for (var i in this.attachment_ids) { + if (this.attachment_ids[i].filename == result.filename && this.attachment_ids[i].upload) { + this.attachment_ids[i]={ + 'id': result.id, + 'name': result.name, + 'filename': result.filename, + 'url': mail.ChatterUtils.get_attachment_url(this.session, result) + }; + } } + } this.display_attachments(); @@ -486,6 +496,11 @@ openerp.mail = function (session) { }, on_compose_fullmail: function (default_composition_mode) { + + if(!this.do_check_attachment_upload()) { + return false; + } + if (default_composition_mode == 'reply') { var context = { 'default_composition_mode': default_composition_mode, @@ -536,31 +551,32 @@ openerp.mail = function (session) { this.reinit(); }, + /* return true if all file are complete else return false and make an alert */ + do_check_attachment_upload: function () { + if (_.find(this.attachment_ids, function (file) {return file.upload;})) { + this.do_warn(session.web._t('Attachment error :'), session.web._t('Please, wait while the file is uploading.')); + return false; + } else { + return true; + } + }, + /*post a message and fetch the message*/ on_message_post: function (event) { var self = this; var comment_node = this.$('textarea'); var body = comment_node.val(); - comment_node.val(''); - var attachments=[]; - for (var i in this.attachment_ids) { - if (this.attachment_ids[i].upload) { - session.web.dialog($('
' + session.web.qweb.render('CrashManager.warning', {message: 'Please, wait while the file is uploading.'}) + '
')); - return false; - } - attachments.push(this.attachment_ids[i].id); - } - - if (body.match(/\S+/)) { + if (this.do_check_attachment_upload() && (this.attachment_ids.length || body.match(/\S+/))) { + comment_node.val(''); //session.web.blockUI(); this.parent_thread.ds_thread.call('message_post_user_api', [ this.context.default_res_id, body, false, this.context.default_parent_id, - attachments, + _.map(this.attachment_ids, function (file) {return file.id;}), this.parent_thread.context ]).done(function (record) { var thread = self.parent_thread;