deletion modal implementation
This commit is contained in:
parent
0d702d0990
commit
5bae461211
@ -146,24 +146,35 @@ async function goToSubscription(subId) {
|
||||
await showEditSubModal(subId);
|
||||
}
|
||||
|
||||
|
||||
// #region Delete Content
|
||||
|
||||
async function deleteSelectedContent() {
|
||||
const rows = contentTable.rows(".selected").data().toArray();
|
||||
const names = rows.map(row => { return row.title });
|
||||
const namesString = arrayToHtmlList(names, true).prop("outerHTML");
|
||||
const multiple = names.length > 1;
|
||||
|
||||
var rows = contentTable.rows(".selected").data();
|
||||
$.each(rows, async function() {
|
||||
await deleteTrackedContent(this.id);
|
||||
showToast(
|
||||
"success",
|
||||
"Deletion Successful",
|
||||
`This content may appear again under the <b>${this.subscription.name}</b> Subscription:<br><br>${this.guid}`,
|
||||
10000
|
||||
);
|
||||
});
|
||||
await confirmDeleteModal(
|
||||
`Confirm ${multiple ? "Multiple Deletions" : "Deletion"}`,
|
||||
`Do you wish to permanently delete ${multiple ? "these" : "this"} <b>${names.length}</b> content${multiple ? "s" : ""}?<br><br>${namesString}`,
|
||||
async () => {
|
||||
rows.forEach(async row => { await deleteTrackedContent(row.id) });
|
||||
|
||||
setTimeout(async () => {
|
||||
await loadContent(getCurrentlyActiveServer().guild_id);
|
||||
}, 600)
|
||||
showToast(
|
||||
"danger",
|
||||
`Deleted ${names.length} Content${multiple ? "s" : ""}`,
|
||||
`${arrayToHtmlList(names, false).prop("outerHTML")}`,
|
||||
12000
|
||||
);
|
||||
},
|
||||
null
|
||||
);
|
||||
}
|
||||
|
||||
// #endregion
|
||||
|
||||
|
||||
function clearExistingContentRows() {
|
||||
$("#contentTable thead .table-select-all").prop("checked", false).prop("indeterminate", false);
|
||||
contentTable.clear().draw(false);
|
||||
|
@ -247,36 +247,57 @@ $(document).on("selectedServerChange", async function() {
|
||||
await loadFilters(activeServer.guild_id);
|
||||
});
|
||||
|
||||
async function deleteSelectedFilters() {
|
||||
var rows = filtersTable.rows(".selected").data();
|
||||
$.each(rows, async function() {
|
||||
await deleteFilter(this.id);
|
||||
showToast(
|
||||
"success",
|
||||
"Deletion Successful",
|
||||
`Content Filter <b>${this.name}</b> has been erased.`,
|
||||
10000
|
||||
);
|
||||
})
|
||||
|
||||
setTimeout(async () => {
|
||||
const guildId = getCurrentlyActiveServer().guild_id;
|
||||
await loadFilters(guildId);
|
||||
loadFilterOptions(guildId);
|
||||
}, 500)
|
||||
}
|
||||
// #region Delete Filters
|
||||
|
||||
$("#deleteEditFilter").on("click", async function() {
|
||||
const filterId = $("#filterId").val();
|
||||
const row = filtersTable.row(function(index, row) {row.id == id}).data();
|
||||
alert(filterId + JSON.stringify(row, null, 4))
|
||||
await deleteFilter(filterId);
|
||||
await loadFilters(getCurrentlyActiveServer().guild_id);
|
||||
const filterId = parseInt($("#filterId").val());
|
||||
const filter = filtersTable.row(function(idx, row) { return row.id === filterId }).data();
|
||||
|
||||
$("#filterFormModal").modal("hide");
|
||||
showToast(
|
||||
"success",
|
||||
"Deletion Successful",
|
||||
`Content Filter <b>${row.name}</b> has been erased.`,
|
||||
10000
|
||||
|
||||
await confirmDeleteModal(
|
||||
"Confirm Deletion",
|
||||
`Do you wish to permanently delete <b>${filter.name}</b>?`,
|
||||
async () => {
|
||||
await deleteFilter(filterId);
|
||||
await loadFilters(getCurrentlyActiveServer().guild_id);
|
||||
|
||||
showToast(
|
||||
"danger",
|
||||
"Deleted a Filter",
|
||||
filter.name,
|
||||
12000
|
||||
);
|
||||
},
|
||||
async () => {
|
||||
$("#filterFormModal").modal("show");
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
async function deleteSelectedFilters() {
|
||||
const rows = filtersTable.rows(".selected").data().toArray();
|
||||
const names = rows.map(row => row.name);
|
||||
const namesString = arrayToHtmlList(names, true).prop("outerHTML");
|
||||
const multiple = names.length > 1;
|
||||
|
||||
await confirmDeleteModal(
|
||||
`Confirm ${multiple ? "Multiple Deletions" : "Deletion"}`,
|
||||
`Do you wish to permanently delete ${multiple ? "these" : "this"} <b>${names.length}</b> filter${multiple ? "s" : ""}?<br><br>${namesString}`,
|
||||
async () => {
|
||||
rows.forEach(async row => { await deleteFilter(row.id) });
|
||||
|
||||
showToast(
|
||||
"danger",
|
||||
`Delete ${names.length} Subscription${multiple ? "s" : ""}`,
|
||||
`${arrayToHtmlList(names, false).prop("outerHTML")}`,
|
||||
12000
|
||||
);
|
||||
|
||||
await loadFilters(getCurrentlyActiveServer().guild_id);
|
||||
},
|
||||
null
|
||||
);
|
||||
}
|
||||
|
||||
// #endregion
|
||||
|
@ -157,4 +157,15 @@ async function confirmDeleteModal(title, description, acceptFunc, declineFunc) {
|
||||
$modal.modal("hide");
|
||||
});
|
||||
$modal.modal("show");
|
||||
}
|
||||
|
||||
function arrayToHtmlList(array, bold=false) {
|
||||
$ul = $("<ul>");
|
||||
|
||||
array.forEach(item => {
|
||||
let $li = $("<li>");
|
||||
$ul.append(bold ? $li.append($("<b>").text(item)) : $li.text(item));
|
||||
});
|
||||
|
||||
return $ul;
|
||||
}
|
@ -390,12 +390,12 @@ $(document).on("selectedServerChange", async function() {
|
||||
// #endregion
|
||||
|
||||
|
||||
// #region Delete Subscription Buttons
|
||||
// #region Delete Subscriptions
|
||||
|
||||
// Delete button on the 'edit subscription' modal
|
||||
$("#deleteEditSub").on("click", async function() {
|
||||
const subId = parseInt($("#subId").val());
|
||||
const sub = subTable.row(function(idx, data, node) { return data.id === subId }).data();
|
||||
const sub = subTable.row(function(idx, row) { return row.id === subId }).data();
|
||||
|
||||
$("#subFormModal").modal("hide");
|
||||
|
||||
@ -419,32 +419,21 @@ $("#deleteEditSub").on("click", async function() {
|
||||
);
|
||||
});
|
||||
|
||||
function arrayToHtmlList(array, bold=false) {
|
||||
$ul = $("<ul>");
|
||||
|
||||
array.forEach(item => {
|
||||
let $li = $("<li>");
|
||||
$ul.append(bold ? $li.append($("<b>").text(item)) : $li.text(item));
|
||||
});
|
||||
|
||||
return $ul;
|
||||
}
|
||||
|
||||
|
||||
async function deleteSelectedSubscriptions() {
|
||||
const rows = subTable.rows(".selected").data().toArray();
|
||||
const names = rows.map(row => row.name);
|
||||
const names = rows.map(row => row.name);
|
||||
const namesString = arrayToHtmlList(names, true).prop("outerHTML");
|
||||
const multiple = names.length > 1;
|
||||
|
||||
await confirmDeleteModal(
|
||||
`Confirm ${names.length > 1 ? "Multiple Deletions" : "Deletion"}`,
|
||||
`Do you wish to permanently delete ${names.length > 1 ? "these" : "this"} <b>${names.length}</b> subscription${names.length > 1 ? "s" : ""}?<br><br>${namesString}`,
|
||||
`Confirm ${multiple ? "Multiple Deletions" : "Deletion"}`,
|
||||
`Do you wish to permanently delete ${multiple ? "these" : "this"} <b>${names.length}</b> subscription${multiple ? "s" : ""}?<br><br>${namesString}`,
|
||||
async () => {
|
||||
rows.forEach(async row => { await deleteSubscription(row.id) });
|
||||
|
||||
showToast(
|
||||
"danger",
|
||||
`Deleted ${names.length} Subscription${names.length > 1 ? "s" : ""}`,
|
||||
`Deleted ${names.length} Subscription${multiple ? "s" : ""}`,
|
||||
`${arrayToHtmlList(names, false).prop("outerHTML")}`,
|
||||
12000
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user