From 31dec273d6321b39bf14b9c0953ba51892a5404e Mon Sep 17 00:00:00 2001 From: Corban-Lee Date: Tue, 23 Jul 2024 11:28:43 +0100 Subject: [PATCH] add and delete buttons for tables --- apps/static/js/home/content.js | 10 +++---- apps/static/js/home/filters.js | 11 ++++---- apps/static/js/home/subscriptions.js | 14 ++++------ apps/static/js/table.js | 42 ++++++++++++++++++++-------- apps/templates/home/index.html | 15 ---------- 5 files changed, 46 insertions(+), 46 deletions(-) diff --git a/apps/static/js/home/content.js b/apps/static/js/home/content.js index 0ada406..cde9716 100644 --- a/apps/static/js/home/content.js +++ b/apps/static/js/home/content.js @@ -3,7 +3,7 @@ var contentTable; async function initContentTable() { contentOptions = await getTrackedContentOptions(); - await initTable("#contentTabPane", "contentTable", loadContent, contentOptions); + await initTable("#contentTabPane", "contentTable", loadContent, null, deleteSelectedContent, contentOptions); contentTable = $("#contentTable").DataTable({ info: false, @@ -100,7 +100,7 @@ async function initContentTable() { ] }); - bindTableCheckboxes("#contentTable", contentTable, "#deleteSelectedContentBtn"); + bindTableCheckboxes("#contentTable", contentTable, "#contentTabPane .table-del-btn"); } function handleDiscordChannelNames() { @@ -147,7 +147,7 @@ async function goToSubscription(subId) { await showEditSubModal(subId); } -$("#deleteSelectedContentBtn").on("click", async function() { +async function deleteSelectedContent() { var rows = contentTable.rows(".selected").data(); $.each(rows, async function() { @@ -158,7 +158,7 @@ $("#deleteSelectedContentBtn").on("click", async function() { setTimeout(async () => { await loadContent(getCurrentlyActiveServer().guild_id); }, 600) -}); +} function clearExistingContentRows() { $("#contentTable thead .table-select-all").prop("checked", false).prop("indeterminate", false); @@ -180,7 +180,7 @@ async function loadContent(guildId, page=1, pageSize=null, search=null) { if (!search) search = $("#contentTabPane .table-searchbar").val(); - $("#deleteSelectedContentBtn").prop("disabled", true); + $("#contentTabPane .table-del-btn").prop("disabled", true); clearExistingContentRows(); try { diff --git a/apps/static/js/home/filters.js b/apps/static/js/home/filters.js index a12b187..07c1bd8 100644 --- a/apps/static/js/home/filters.js +++ b/apps/static/js/home/filters.js @@ -4,7 +4,7 @@ var filtersTable; // Create filters table async function initFiltersTable() { filterOptions = await getFilterOptions(); - await initTable("#filtersTabPane", "filtersTable", loadFilters, filterOptions); + await initTable("#filtersTabPane", "filtersTable", loadFilters, showEditFilterModal, deleteSelectedFilters, filterOptions); filtersTable = $("#filtersTable").DataTable({ info: false, @@ -79,7 +79,7 @@ async function initFiltersTable() { ] }); - bindTableCheckboxes("#filtersTable", filtersTable, "#deleteSelectedFiltersBtn"); + bindTableCheckboxes("#filtersTable", filtersTable, "#filtersTabPane .table-del-btn"); } $("#addFilterBtn").on("click", async function() { @@ -183,7 +183,7 @@ async function loadFilters(guildId, page=1, pageSize=null, search=null) { if (!search) search = $("#filtersTabPane .table-searchbar").val(); - $("#deleteSelectedFiltersBtn").prop("disabled", true); + $("#filtersTabPane .table-del-btn").prop("disabled", true); clearExistingFilterRows(); try { @@ -242,8 +242,7 @@ $(document).on("selectedServerChange", async function() { await loadFilters(activeServer.guild_id); }); -$("#deleteSelectedFiltersBtn").on("click", async function() { - +async function deleteSelectedFilters() { var rows = filtersTable.rows(".selected").data(); $.each(rows, async function() { await deleteFilter(this.id); @@ -255,7 +254,7 @@ $("#deleteSelectedFiltersBtn").on("click", async function() { await loadFilters(guildId); loadFilterOptions(guildId); }, 500) -}) +} $("#deleteEditFilter").on("click", async function() { const filterId = $("#filterId").val(); diff --git a/apps/static/js/home/subscriptions.js b/apps/static/js/home/subscriptions.js index eec90bc..aef3463 100644 --- a/apps/static/js/home/subscriptions.js +++ b/apps/static/js/home/subscriptions.js @@ -6,7 +6,7 @@ var subTable = null; // Create subscription table async function initSubscriptionTable() { subOptions = await getSubscriptionOptions(); - await initTable("#subscriptionsTabPane", "subTable", loadSubscriptions, subOptions); + await initTable("#subscriptionsTabPane", "subTable", loadSubscriptions, showEditSubModal, deleteSelectedSubscriptions, subOptions); subTable = $("#subTable").DataTable({ info: false, @@ -121,7 +121,7 @@ async function initSubscriptionTable() { ] }); - bindTableCheckboxes("#subTable", subTable, "#deleteSelectedSubscriptionsBtn"); + bindTableCheckboxes("#subTable", subTable, "#subscriptionsTabPane .table-del-btn"); } $("#subscriptionsTabPane").on("change", ".sub-toggle-active", async function () { @@ -352,7 +352,7 @@ async function loadSubscriptions(guildId, page=1, pageSize=null, search=null) { if (!search) search = $("#subscriptionsTabPane .table-searchbar").val(); - $("#deleteSelectedSubscriptionsBtn").prop("disabled", true); + $("#subscriptionsTabPane .table-del-btn").prop("disabled", true); clearExistingSubRows(); try { @@ -446,18 +446,14 @@ $("#deleteEditSub").on("click", async function() { showToast("danger", "Deleted Subscription", "Subscription ID: " + subId); }); -$("#deleteSelectedSubscriptionsBtn").on("click", async function() { - // showToast("danger", "Not Implemented", "This feature isn't implemented"); - +async function deleteSelectedSubscriptions() { var rows = subTable.rows(".selected").data(); $.each(rows, async function() { - // alert(JSON.stringify(this, null, 4)); await deleteSubscription(this.id); showToast("danger", "Deleted Subscription", "Subscription ID: " + this.id); }); - await loadSubscriptions(getCurrentlyActiveServer().guild_id); -}) +} // #endregion diff --git a/apps/static/js/table.js b/apps/static/js/table.js index 094db12..b900993 100644 --- a/apps/static/js/table.js +++ b/apps/static/js/table.js @@ -1,12 +1,12 @@ var timeouts = {}; -async function initTable(containingSelector, tableId, loadDataFunc, options=null) { +async function initTable(containingSelector, tableId, loadDataFunc, newRowFunc, deleteSelectedFunc, options=null) { let pageSizeId = tableId + "PageSize"; searchId = tableId + "SearchBar"; sortDropdownId = tableId + "SortDropdown"; filterDropdownId = tableId + "FilterDropdown"; - createSearchRow(containingSelector, searchId, sortDropdownId, filterDropdownId, options); + createSearchRow(containingSelector, searchId, sortDropdownId, filterDropdownId, options, newRowFunc, deleteSelectedFunc); createTable(containingSelector, tableId); createTableControls(containingSelector, pageSizeId); @@ -15,7 +15,7 @@ async function initTable(containingSelector, tableId, loadDataFunc, options=null await bindTablePaginationResizer(`${containingSelector} .table-page-sizer`, loadDataFunc); } -function createSearchRow(containingSelector, searchId, sortDropdownId, filterDropdownId, options) { +function createSearchRow(containingSelector, searchId, sortDropdownId, filterDropdownId, options, newRowFunc, deleteSelectedFunc) { $(containingSelector).append(`
@@ -26,17 +26,26 @@ function createSearchRow(containingSelector, searchId, sortDropdownId, filterDro
-
+
+
+ +
+
`); - $(`${containingSelector} .table-search-row .table-search-buttons`).append(` -
- -
- `); + if (newRowFunc) { + $(`${containingSelector} .table-search-row .table-search-buttons`).prepend(` +
+ +
+ `) + $(`${containingSelector} .table-search-row .table-search-buttons .table-new-btn`).on("click", async () => {await newRowFunc(-1)}); + } if (options.sort) { $(`${containingSelector} .table-search-row .table-search-buttons`).append(` @@ -69,6 +78,17 @@ function createSearchRow(containingSelector, searchId, sortDropdownId, filterDro `); populateFilterDropdown(); } + + if (deleteSelectedFunc) { + $(`${containingSelector} .table-search-row .table-search-buttons`).append(` +
+ +
+ `) + $(`${containingSelector} .table-search-row .table-search-buttons .table-del-btn`).on("click", async () => {await deleteSelectedFunc()}); + } } function populateSortDropdown(sortDropdownId, sortOptions) { diff --git a/apps/templates/home/index.html b/apps/templates/home/index.html index eb59e60..790a39f 100644 --- a/apps/templates/home/index.html +++ b/apps/templates/home/index.html @@ -71,25 +71,10 @@
- -
- -
-