Add batch approval/rejection
This commit is contained in:
parent
bfd8796f2b
commit
9bb74a84df
|
@ -36,8 +36,12 @@
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<div class="items-selected">
|
<div class="items-selected">
|
||||||
<p><span>0</span> items selected</p>
|
<p><span>0</span> items selected</p>
|
||||||
<button>approve</button>
|
<button class="approve">approve</button>
|
||||||
<button>reject</button>
|
<button class="reject">reject</button>
|
||||||
|
<dialog class="reject">
|
||||||
|
<p>reject records? this will delete them from the database permanently.</p>
|
||||||
|
<button>delete permanently</button>
|
||||||
|
</dialog>
|
||||||
</div>
|
</div>
|
||||||
{% if transactions %}
|
{% if transactions %}
|
||||||
<div class="table-responsive">
|
<div class="table-responsive">
|
||||||
|
@ -171,6 +175,45 @@
|
||||||
counter.textContent = checkedTransactions.length;
|
counter.textContent = checkedTransactions.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const approveButton = document.querySelector(".items-selected button.approve");
|
||||||
|
const rejectButton = document.querySelector(".items-selected button.reject");
|
||||||
|
const rejectDialog = document.querySelector(".items-selected dialog.reject");
|
||||||
|
const rejectDialogButton = document.querySelector(".items-selected dialog.reject button");
|
||||||
|
|
||||||
|
approveButton.addEventListener("click", async () => {
|
||||||
|
const promises = checkedTransactions.map(async id=>{
|
||||||
|
await fetch(
|
||||||
|
`/api/transaction/${id}/approve`,
|
||||||
|
{
|
||||||
|
method: "POST",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
});
|
||||||
|
|
||||||
|
await Promise.all(promises);
|
||||||
|
location.reload();
|
||||||
|
});
|
||||||
|
|
||||||
|
rejectButton.addEventListener("click", () => rejectDialog.showModal());
|
||||||
|
|
||||||
|
rejectDialog.addEventListener("click", e => {
|
||||||
|
if (e.target === rejectDialog) rejectDialog.close();
|
||||||
|
});
|
||||||
|
|
||||||
|
rejectDialogButton.addEventListener("click", async () => {
|
||||||
|
const promises = checkedTransactions.map(async id=>{
|
||||||
|
await fetch(
|
||||||
|
`/api/transaction/${id}`,
|
||||||
|
{
|
||||||
|
method: "DELETE",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
});
|
||||||
|
|
||||||
|
await Promise.all(promises);
|
||||||
|
location.reload();
|
||||||
|
});
|
||||||
|
|
||||||
document.addEventListener('DOMContentLoaded', function() {
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
// Refresh button functionality
|
// Refresh button functionality
|
||||||
const refreshBtn = document.getElementById('refreshBtn');
|
const refreshBtn = document.getElementById('refreshBtn');
|
||||||
|
|
Loading…
Reference in New Issue