mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 09:08:09 +08:00
Refactor paylater and buttons filters for simplicity
Add show / hide messages functionality on the frontend
This commit is contained in:
parent
9434a84301
commit
9cdd11b3b3
6 changed files with 104 additions and 103 deletions
|
@ -49,8 +49,9 @@ class CartBootstrap {
|
|||
}
|
||||
|
||||
// handle button status
|
||||
if (result.data.button) {
|
||||
if (result.data.button || result.data.messages) {
|
||||
this.gateway.button = result.data.button;
|
||||
this.gateway.messages = result.data.messages;
|
||||
this.handleButtonStatus();
|
||||
}
|
||||
|
||||
|
|
|
@ -202,6 +202,9 @@ class SingleProductBootstap {
|
|||
if (typeof data.button.is_disabled === 'boolean') {
|
||||
this.gateway.button.is_disabled = data.button.is_disabled;
|
||||
}
|
||||
if (typeof data.messages.is_hidden === 'boolean') {
|
||||
this.gateway.messages.is_hidden = data.messages.is_hidden;
|
||||
}
|
||||
|
||||
this.handleButtonStatus(false);
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import {disable, enable} from "./ButtonDisabler";
|
||||
import {hide, show} from "./Hiding";
|
||||
|
||||
/**
|
||||
* Common Bootstrap methods to avoid code repetition.
|
||||
|
@ -11,20 +12,28 @@ export default class BootstrapHelper {
|
|||
options.messagesWrapper = options.messagesWrapper || bs.gateway.messages.wrapper;
|
||||
options.skipMessages = options.skipMessages || false;
|
||||
|
||||
if (!bs.shouldEnable()) {
|
||||
// Handle messages hide / show
|
||||
if (this.shouldShowMessages(bs, options)) {
|
||||
show(options.messagesWrapper);
|
||||
} else {
|
||||
hide(options.messagesWrapper);
|
||||
}
|
||||
|
||||
// Handle enable / disable
|
||||
if (bs.shouldEnable()) {
|
||||
bs.renderer.enableSmartButtons(options.wrapper);
|
||||
enable(options.wrapper);
|
||||
|
||||
if (!options.skipMessages) {
|
||||
enable(options.messagesWrapper);
|
||||
}
|
||||
} else {
|
||||
bs.renderer.disableSmartButtons(options.wrapper);
|
||||
disable(options.wrapper, options.formSelector || null);
|
||||
|
||||
if (!options.skipMessages) {
|
||||
disable(options.messagesWrapper);
|
||||
}
|
||||
return;
|
||||
}
|
||||
bs.renderer.enableSmartButtons(options.wrapper);
|
||||
enable(options.wrapper);
|
||||
|
||||
if (!options.skipMessages) {
|
||||
enable(options.messagesWrapper);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -37,4 +46,13 @@ export default class BootstrapHelper {
|
|||
return bs.shouldRender()
|
||||
&& options.isDisabled !== true;
|
||||
}
|
||||
|
||||
static shouldShowMessages(bs, options) {
|
||||
options = options || {};
|
||||
if (typeof options.isMessagesHidden === 'undefined') {
|
||||
options.isMessagesHidden = bs.gateway.messages.is_hidden;
|
||||
}
|
||||
|
||||
return options.isMessagesHidden !== true;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue