aboutsummaryrefslogtreecommitdiff
path: root/webmentions_ssg/static/js/received-bulk-actions.js
diff options
context:
space:
mode:
authorDennis Fink2026-11-16 22:59:36 +0100
committerDennis Fink2026-11-16 22:59:36 +0100
commitf98b0e446b41325c494bd97900b7bbf730a7d67e (patch)
treea2a3c1e8779877d420d1685862f40b93d647c8f8 /webmentions_ssg/static/js/received-bulk-actions.js
parent354a5b449077478b141683bafbab47c9dc169d21 (diff)
downloadwebmentions-ssg-f98b0e446b41325c494bd97900b7bbf730a7d67e.tar.gz
webmentions-ssg-f98b0e446b41325c494bd97900b7bbf730a7d67e.zip
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.
Diffstat (limited to '')
-rw-r--r--webmentions_ssg/static/js/received-bulk-actions.js68
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();
+});