From db12ed7cb1714bbaf8efaa099ee5de9b74ebfe2d Mon Sep 17 00:00:00 2001 From: Romain Derie Date: Tue, 18 May 2021 10:37:44 +0000 Subject: [PATCH] [IMP] website_form: add a spinner and error message for file upload MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If a visitor tries to send a file too large, they will get a message after a while that an error occurred. The message isn't specific enough. With this commit: - when a visitor sends a form, a spinner will appear indicating that the file is being uploaded. - if the upload fails because the file is too large, the user will be notified. task-2234699 closes odoo/odoo#70301 Signed-off-by: Jérémy Kersten (jke) Co-authored-by: Romain Derie Co-authored-by: Arthur Detroux --- .../static/src/snippets/s_website_form/000.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/addons/website_form/static/src/snippets/s_website_form/000.js b/addons/website_form/static/src/snippets/s_website_form/000.js index 48e5768d534..5314e74d789 100644 --- a/addons/website_form/static/src/snippets/s_website_form/000.js +++ b/addons/website_form/static/src/snippets/s_website_form/000.js @@ -148,9 +148,10 @@ odoo.define('website_form.s_website_form', function (require) { send: async function (e) { e.preventDefault(); // Prevent the default submit behavior // Prevent users from crazy clicking - this.$target.find('.s_website_form_send, .o_website_form_send') - .addClass('disabled') // !compatibility - .attr('disabled', 'disabled'); + const $button = this.$target.find('.s_website_form_send, .o_website_form_send'); + $button.addClass('disabled') // !compatibility + .attr('disabled', 'disabled'); + this.restoreBtnLoading = dom.addButtonLoadingEffect($button[0]); var self = this; @@ -262,8 +263,11 @@ odoo.define('website_form.s_website_form', function (require) { self.$target[0].reset(); } }) - .guardedCatch(function () { - self.update_status('error'); + .guardedCatch(error => { + this.update_status( + 'error', + error.status && error.status === 413 ? _t("Uploaded file is too large.") : "", + ); }); }, @@ -362,6 +366,7 @@ odoo.define('website_form.s_website_form', function (require) { this.$target.find('.s_website_form_send, .o_website_form_send') .removeAttr('disabled') .removeClass('disabled'); // !compatibility + this.restoreBtnLoading(); } var $result = this.$('#s_website_form_result, #o_website_form_result'); // !compatibility