From f98b0e446b41325c494bd97900b7bbf730a7d67e Mon Sep 17 00:00:00 2001 From: Dennis Fink Date: Mon, 16 Nov 2026 22:59:36 +0100 Subject: feat(receiver): add bulk received Webmention actions Allow admins to select received Webmentions for bulk reverification or deletion and provide a separate action to delete all declined entries. Validate selections strictly, preserve active list filters across redirects, and reuse the shared confirmation modal with CSRF protection. --- webmentions_ssg/static/js/received-bulk-actions.js | 68 ++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 webmentions_ssg/static/js/received-bulk-actions.js (limited to 'webmentions_ssg/static/js') 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 +// +// 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(); +}); -- cgit v1.3.1