From aff45f9ac523c80f5ae63b2870267ebc16d0d252 Mon Sep 17 00:00:00 2001 From: Corban-Lee Jones Date: Fri, 11 Oct 2024 13:30:24 +0100 Subject: [PATCH] add missing delete function for filters table & modal --- apps/home/static/home/js/tabs/filters.js | 56 ++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/apps/home/static/home/js/tabs/filters.js b/apps/home/static/home/js/tabs/filters.js index 553f3e0..166f131 100644 --- a/apps/home/static/home/js/tabs/filters.js +++ b/apps/home/static/home/js/tabs/filters.js @@ -69,6 +69,62 @@ async function loadFilterData() { await loadTableData(filterTableId, "/api/filters/", "GET"); } +// Table Delete Btns + +$(filterModalId).find(".modal-del-btn").on("click", async function() { + $(filterModalId).modal("hide"); + + const id = parseInt($(filterModalId).data("primary-key")); + const filter = $(filterTableId).DataTable().row((idx, row) => { return row.id === id }).data(); + const name = sanitise(filter.name); + + await confirmationModal( + `Delete a Content Filter`, + `Do you wish to permanently delete ${name}?`, + "danger", + "bi-trash3", + async () => { + await ajaxRequest(`/api/filters/${filter.id}/`, "DELETE"); + setTimeout(async () => { + $(filterTableId).trigger("doDataLoad"); + await loadSubModalOptions( + $(subModalId).find('[data-field="filters"]'), + `/api/filters/?server=${selectedServer.id}` + ); + }, 600); + }, + () => { $(filterModalId).modal("show") } + ); +}) + +getTableFiltersComponent(filterTableId).find(".table-del-btn").on("click", async function() { + const rows = getSelectedTableRows(filterTableId); + const isMany = rows.length > 1; + const names = rows.map(row => row.name); + const namesString = arrayToHtmlList(names, true).prop("outerHTML"); + + await confirmationModal( + `Delete ${isMany ? "Many Content Filters" : "a Content Filter"}`, + `Do you wish to permanently delete ${isMany ? "these" : "this"} ${names.length} content filter${isMany ? "s" : ""}?

${namesString}`, + "danger", + "bi-trash3", + async () => { + rows.forEach(async row => { + await ajaxRequest(`/api/filters/${row.id}/`, "DELETE"); + }); + + setTimeout(async () => { + $(filterTableId).trigger("doDataLoad"); + await loadSubModalOptions( + $(subModalId).find('[data-field="filters"]'), + `/api/filters/?server=${selectedServer.id}` + ); + }, 600); + }, + null + ) +}); + // region New/Edit Modal