Add batch approval/rejection
This commit is contained in:
parent
bfd8796f2b
commit
9bb74a84df
|
@ -36,8 +36,12 @@
|
|||
<div class="card-body">
|
||||
<div class="items-selected">
|
||||
<p><span>0</span> items selected</p>
|
||||
<button>approve</button>
|
||||
<button>reject</button>
|
||||
<button class="approve">approve</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>
|
||||
{% if transactions %}
|
||||
<div class="table-responsive">
|
||||
|
@ -171,6 +175,45 @@
|
|||
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() {
|
||||
// Refresh button functionality
|
||||
const refreshBtn = document.getElementById('refreshBtn');
|
||||
|
|
Loading…
Reference in New Issue