diff options
Diffstat (limited to 'webmentions_ssg/static/js/received-bulk-actions.js')
| -rw-r--r-- | webmentions_ssg/static/js/received-bulk-actions.js | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/webmentions_ssg/static/js/received-bulk-actions.js b/webmentions_ssg/static/js/received-bulk-actions.js new file mode 100644 index 0000000..c4ac31b --- /dev/null +++ b/webmentions_ssg/static/js/received-bulk-actions.js @@ -0,0 +1,68 @@ +// SPDX-FileCopyrightText: 2026 Dennis Fink <me+coding@dennisfink.me> +// +// SPDX-License-Identifier: BSD-3-Clause + +document.addEventListener("DOMContentLoaded", () => { + const checkboxes = Array.from(document.querySelectorAll(".received-select")); + const selectAll = document.getElementById("received-select-all"); + const bulkButtons = document.querySelectorAll("[data-received-bulk-action]"); + const count = document.getElementById("received-selected-count"); + const modal = document.getElementById("confirmation-modal"); + + const selected = () => checkboxes.filter((checkbox) => checkbox.checked); + + const updateSelection = () => { + const selectedCount = selected().length; + if (count !== null) { + count.textContent = `${selectedCount} selected`; + } + bulkButtons.forEach((button) => { + button.disabled = selectedCount === 0; + }); + if (selectAll !== null) { + selectAll.checked = selectedCount === checkboxes.length; + selectAll.indeterminate = + selectedCount > 0 && selectedCount < checkboxes.length; + } + }; + + selectAll?.addEventListener("change", () => { + checkboxes.forEach((checkbox) => { + checkbox.checked = selectAll.checked; + }); + updateSelection(); + }); + checkboxes.forEach((checkbox) => { + checkbox.addEventListener("change", updateSelection); + }); + + modal?.addEventListener("show.bs.modal", (event) => { + const form = modal.querySelector("#confirmation-modal-form"); + // Never carry a previous bulk selection into an unrelated confirmation. + form.querySelectorAll('input[name="webmention_uuids"]').forEach((input) => { + input.remove(); + }); + + if (!event.relatedTarget?.dataset.receivedBulkAction) { + return; + } + + const selection = selected(); + const message = modal.querySelector("#confirmation-modal-message"); + if (event.relatedTarget.dataset.receivedBulkAction === "delete") { + message.textContent = `This permanently deletes ${selection.length} selected webmentions and cannot be undone.`; + } else { + message.textContent = `${selection.length} selected webmentions will be fetched and verified again.`; + } + + selection.forEach((checkbox) => { + const input = document.createElement("input"); + input.type = "hidden"; + input.name = "webmention_uuids"; + input.value = checkbox.value; + form.appendChild(input); + }); + }); + + updateSelection(); +}); |
