From 3298164393aec91c060e0fcd3238c46a331891f1 Mon Sep 17 00:00:00 2001 From: "Nasreddin Boulif (bon)" Date: Thu, 23 Dec 2021 16:22:48 +0000 Subject: [PATCH] [FIX] website_sale,payment[adyen,authorize]: Block UI only on click pay Step to reproduce: - Install website_sale module - Go to the shop - Add a product to the cart and proceed to checkout - Click on Customize and activate `Accept Terms & Conditions` - Deactivate the `Accept Terms & Conditions` or click on a payment method. Issue: UI freeze. Solution: Freeze ui only when clicking on pay button. Unfreeze only if payment process fails (or when displaying an error). Revert of https://github.com/odoo/odoo/commit/41b91e12eb80cee08e3a25bcc6546ef34937d8cf and adapt it correctly opw-2702798 closes odoo/odoo#83155 X-original-commit: b6ae8a0a91c58ce503c98ca2a66a4d125907dac1 Related: odoo/enterprise#23639 Signed-off-by: Nasreddin Boulif (bon) --- addons/payment/static/src/js/checkout_form.js | 4 ++++ addons/payment/static/src/js/manage_form.js | 4 ++++ .../static/src/js/payment_form_mixin.js | 1 + .../static/src/js/payment_form.js | 4 ++-- .../static/src/js/payment_form.js | 1 + .../static/src/js/website_sale_payment.js | 20 ------------------- 6 files changed, 12 insertions(+), 22 deletions(-) diff --git a/addons/payment/static/src/js/checkout_form.js b/addons/payment/static/src/js/checkout_form.js index aa321e6561c..29c787bd253 100644 --- a/addons/payment/static/src/js/checkout_form.js +++ b/addons/payment/static/src/js/checkout_form.js @@ -74,6 +74,10 @@ odoo.define('payment.checkout_form', require => { // Make the payment this._hideError(); // Don't keep the error displayed if the user is going through 3DS2 this._disableButton(true); // Disable until it is needed again + $('body').block({ + message: false, + overlayCSS: {backgroundColor: "#000", opacity: 0, zIndex: 1050}, + }); this._processPayment(provider, paymentOptionId, flow); }, diff --git a/addons/payment/static/src/js/manage_form.js b/addons/payment/static/src/js/manage_form.js index a8c153816f7..e6a4e840ffa 100644 --- a/addons/payment/static/src/js/manage_form.js +++ b/addons/payment/static/src/js/manage_form.js @@ -206,6 +206,10 @@ odoo.define('payment.manage_form', require => { // Save the payment method this._hideError(); // Don't keep the error displayed if the user is going through 3DS2 this._disableButton(true); // Disable until it is needed again + $('body').block({ + message: false, + overlayCSS: {backgroundColor: "#000", opacity: 0, zIndex: 1050}, + }); if (flow !== 'token') { // Creation of a new token this.txContext.tokenizationRequested = true; this.txContext.isValidation = true; diff --git a/addons/payment/static/src/js/payment_form_mixin.js b/addons/payment/static/src/js/payment_form_mixin.js index 36ba8911c57..890f2b08ef2 100644 --- a/addons/payment/static/src/js/payment_form_mixin.js +++ b/addons/payment/static/src/js/payment_form_mixin.js @@ -104,6 +104,7 @@ odoo.define('payment.payment_form_mixin', require => { .scrollIntoView({behavior: 'smooth', block: 'center'}); } this._enableButton(); // Enable button back after it was disabled before processing + $('body').unblock(); // The page is blocked at this point, unblock it }, /** diff --git a/addons/payment_adyen/static/src/js/payment_form.js b/addons/payment_adyen/static/src/js/payment_form.js index 0a91c61ba1e..d0221ef4794 100644 --- a/addons/payment_adyen/static/src/js/payment_form.js +++ b/addons/payment_adyen/static/src/js/payment_form.js @@ -196,7 +196,7 @@ odoo.define('payment_adyen.payment_form', require => { * @param {string} flow - The online payment flow of the transaction * @return {Promise} */ - _processPayment: function (provider, paymentOptionId, flow) { + async _processPayment(provider, paymentOptionId, flow) { if (provider !== 'adyen' || flow === 'token') { return this._super(...arguments); // Tokens are handled by the generic flow } @@ -205,7 +205,7 @@ odoo.define('payment_adyen.payment_form', require => { _t("Server Error"), _t("We are not able to process your payment.") ); } else { - return this.adyenDropin.submit(); + return await this.adyenDropin.submit(); } }, diff --git a/addons/payment_authorize/static/src/js/payment_form.js b/addons/payment_authorize/static/src/js/payment_form.js index 722a22b596f..61b39bb3dff 100644 --- a/addons/payment_authorize/static/src/js/payment_form.js +++ b/addons/payment_authorize/static/src/js/payment_form.js @@ -130,6 +130,7 @@ odoo.define('payment_authorize.payment_form', require => { if (!this._validateFormInputs(paymentOptionId)) { this._enableButton(); // The submit button is disabled at this point, enable it + $('body').unblock(); // The page is blocked at this point, unblock it return Promise.resolve(); } diff --git a/addons/website_sale/static/src/js/website_sale_payment.js b/addons/website_sale/static/src/js/website_sale_payment.js index 93109926fd1..3420d1b8a0f 100644 --- a/addons/website_sale/static/src/js/website_sale_payment.js +++ b/addons/website_sale/static/src/js/website_sale_payment.js @@ -53,26 +53,6 @@ odoo.define('website_sale.payment', require => { // Private //---------------------------------------------------------------------- - /** - * @override - */ - _disableButton(showLoadingAnimation = true) { - $("body").block({ - message: false, - overlayCSS: {backgroundColor: "#000", opacity: 0, zIndex: 1050}, - }); - this._super(...arguments); - }, - /** - * @override - */ - _enableButton() { - const res = this._super(...arguments); - if (res) { - $('body').unblock(); - } - return res; - }, /** * Verify that the Terms and Condition checkbox is checked. *