Add ability to remove packages from collection page

This commit is contained in:
rubenwardy
2023-08-19 01:25:13 +01:00
parent 8d97c6b38e
commit 57ba3e8700
3 changed files with 42 additions and 2 deletions

View File

@@ -0,0 +1,26 @@
// @author rubenwardy
// @license magnet:?xt=urn:btih:1f739d935676111cfff4b4693e3816e664797050&dn=gpl-3.0.txt GPL-v3-or-Later
function handleRemovePackage(card) {
if (!confirm(card.getAttribute("data-delete-confirm"))) {
return;
}
card.querySelector("input[name^=package_removed]").value = "1";
card.classList.add("d-none");
}
window.onload = () => {
console.log("Loaded");
document.querySelectorAll(".remove-package").forEach(button => {
const card = button.parentNode.parentNode;
const field = card.querySelector("input[name^=package_removed]");
// Reloading/validation errors will cause this to be 1 at load
if (field && field.value === "1") {
card.classList.add("d-none");
} else {
button.addEventListener("click", () => handleRemovePackage(card));
}
});
};