mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-01 07:02:48 +08:00
Create the JS to handle clear db functionality
This commit is contained in:
parent
990799d20b
commit
374ce5d5f9
1 changed files with 45 additions and 0 deletions
45
modules/ppcp-uninstall/resources/js/ppcp-clear-db.js
Normal file
45
modules/ppcp-uninstall/resources/js/ppcp-clear-db.js
Normal file
|
@ -0,0 +1,45 @@
|
|||
document.addEventListener(
|
||||
'DOMContentLoaded',
|
||||
() => {
|
||||
const config = PayPalCommerceGatewayClearDb;
|
||||
if (!typeof (config)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const clearDbConfig = config.clearDb;
|
||||
|
||||
jQuery(document).on('click', clearDbConfig.button, function () {
|
||||
const isConfirmed = confirm(clearDbConfig.ConfirmationMessage);
|
||||
if (!isConfirmed) {
|
||||
return;
|
||||
}
|
||||
|
||||
const clearButton = document.querySelector(clearDbConfig.button);
|
||||
|
||||
clearButton.setAttribute('disabled', 'disabled');
|
||||
fetch(clearDbConfig.endpoint, {
|
||||
method: 'POST',
|
||||
credentials: 'same-origin',
|
||||
body: JSON.stringify({
|
||||
nonce: clearDbConfig.nonce,
|
||||
})
|
||||
}).then(function (res) {
|
||||
return res.json();
|
||||
}).then(function (data) {
|
||||
const resultMessage = document.querySelector(clearDbConfig.messageSelector);
|
||||
|
||||
if (!data.success) {
|
||||
clearDbConfig.failureMessage.insertAfter(clearButton);
|
||||
setTimeout(()=> resultMessage.remove(),3000);
|
||||
clearButton.removeAttribute('disabled');
|
||||
console.error(data);
|
||||
throw Error(data.data.message);
|
||||
}
|
||||
|
||||
clearDbConfig.successMessage.insertAfter(clearButton);
|
||||
setTimeout(()=> resultMessage.remove(),3000);
|
||||
clearButton.removeAttribute('disabled');
|
||||
});
|
||||
})
|
||||
},
|
||||
);
|
Loading…
Add table
Add a link
Reference in a new issue