[IMP] website_form: add a spinner and error message for file upload

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) <jke@openerp.com>
Co-authored-by: Romain Derie <rde@odoo.com>
Co-authored-by: Arthur Detroux <ard@odoo.com>
This commit is contained in:
Romain Derie
2021-05-18 11:18:22 +00:00
co-authored by Arthur Detroux
parent 3615a5974a
commit db12ed7cb1
@@ -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