mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-08-31 06:52:50 +08:00
allow to enable either vault or pay later message
This commit is contained in:
parent
092a808066
commit
77efce52db
6 changed files with 144 additions and 4 deletions
34
modules/ppcp-wc-gateway/resources/js/gateway-settings.js
Normal file
34
modules/ppcp-wc-gateway/resources/js/gateway-settings.js
Normal file
|
@ -0,0 +1,34 @@
|
|||
;document.addEventListener(
|
||||
'DOMContentLoaded',
|
||||
() => {
|
||||
const payLaterMessagingCheckboxes = document.querySelectorAll(
|
||||
"#ppcp-message_enabled, #ppcp-message_cart_enabled, #ppcp-message_product_enabled"
|
||||
)
|
||||
|
||||
const vaultingCheckboxes = document.querySelectorAll(
|
||||
"#ppcp-vault_enabled, #ppcp-dcc_vault_enabled"
|
||||
)
|
||||
|
||||
function atLeastOneChecked(checkboxesNodeList) {
|
||||
return Array.prototype.slice.call(checkboxesNodeList).filter(node => !node.disabled && node.checked).length > 0
|
||||
}
|
||||
|
||||
function disableAll(nodeList){
|
||||
nodeList.forEach(node => node.setAttribute('disabled', 'true'))
|
||||
}
|
||||
|
||||
function enableAll(nodeList){
|
||||
nodeList.forEach(node => node.removeAttribute('disabled'))
|
||||
}
|
||||
|
||||
function updateCheckboxes() {
|
||||
atLeastOneChecked(payLaterMessagingCheckboxes) ? disableAll(vaultingCheckboxes) : enableAll(vaultingCheckboxes)
|
||||
atLeastOneChecked(vaultingCheckboxes) ? disableAll(payLaterMessagingCheckboxes) : enableAll(payLaterMessagingCheckboxes)
|
||||
}
|
||||
|
||||
updateCheckboxes()
|
||||
|
||||
payLaterMessagingCheckboxes.forEach(node => node.addEventListener('change', updateCheckboxes))
|
||||
vaultingCheckboxes.forEach(node => node.addEventListener('change', updateCheckboxes));
|
||||
}
|
||||
);
|
Loading…
Add table
Add a link
Reference in a new issue