fix active toggle switch
All checks were successful
Build and Push Docker Image / build (push) Successful in 15s
All checks were successful
Build and Push Docker Image / build (push) Successful in 15s
This commit is contained in:
parent
5d893fed37
commit
a06b9d0f9d
@ -117,6 +117,31 @@ async function initSubscriptionTable() {
|
||||
bindTableCheckboxes("#subTable", subTable, "#subscriptionsTabPane .table-del-btn");
|
||||
}
|
||||
|
||||
async function updateSubFromObject(sub, handleErrorMsg=true) {
|
||||
let data = {
|
||||
"name": sub.name,
|
||||
"url": sub.url,
|
||||
"guild_id": sub.guild_id,
|
||||
"extra_notes": sub.extra_notes,
|
||||
"embed_colour": sub.embed_colour,
|
||||
"article_fetch_image": sub.article_fetch_image,
|
||||
"published_threshold": sub.published_threshold,
|
||||
"active": sub.active
|
||||
};
|
||||
|
||||
let formData = new FormData();
|
||||
|
||||
for (key in data) {
|
||||
formData.append(key, data[key]);
|
||||
}
|
||||
|
||||
sub.article_title_mutators.forEach(mutator => formData.append("article_title_mutators", mutator.id));
|
||||
sub.article_desc_mutators.forEach(mutator => formData.append("article_desc_mutators", mutator.id));
|
||||
sub.filters.forEach(filter => formData.append("filters", filter));
|
||||
|
||||
return await saveSubscription(sub.id, formData, handleErrorMsg=handleErrorMsg);
|
||||
}
|
||||
|
||||
$("#subscriptionsTabPane").on("change", ".sub-toggle-active", async function () {
|
||||
|
||||
/*
|
||||
@ -135,30 +160,16 @@ $("#subscriptionsTabPane").on("change", ".sub-toggle-active", async function ()
|
||||
subTable.data(sub).draw();
|
||||
|
||||
// Update the database
|
||||
const subPrimaryKey = await saveSubscription(
|
||||
sub.id,
|
||||
sub.name,
|
||||
sub.url,
|
||||
sub.guild_id,
|
||||
sub.extra_notes,
|
||||
sub.filters,
|
||||
{
|
||||
title: sub.article_title_mutators.map(mutator => mutator.id),
|
||||
desc: sub.article_desc_mutators.map(mutator => mutator.id)
|
||||
},
|
||||
sub.embed_colour,
|
||||
sub.article_fetch_image,
|
||||
sub.published_threshold,
|
||||
active,
|
||||
handleErrorMsg=false
|
||||
);
|
||||
if (!subPrimaryKey)
|
||||
const subId = await updateSubFromObject(sub, handleErrorMsg=false);
|
||||
|
||||
if (!subId) {
|
||||
throw Error("This subscription no longer exists.");
|
||||
}
|
||||
|
||||
showToast(
|
||||
active ? "success" : "danger",
|
||||
"Subscription " + (active ? "Activated" : "Deactivated"),
|
||||
"Subscription ID: " + subPrimaryKey
|
||||
"Subscription ID: " + subId
|
||||
);
|
||||
}
|
||||
catch (error) {
|
||||
@ -171,7 +182,10 @@ $("#subscriptionsTabPane").on("change", ".sub-toggle-active", async function ()
|
||||
}
|
||||
finally {
|
||||
// Re-enable toggles after 500ms
|
||||
setTimeout(() => { $(".sub-toggle-active").prop("disabled", false); }, 500)
|
||||
setTimeout(() => {
|
||||
$(".sub-toggle-active").prop("disabled", false); },
|
||||
500
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
@ -246,7 +260,6 @@ function getValueFromField(elem) {
|
||||
default:
|
||||
return $elem.val();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$("#subForm").on("submit", async function(event) {
|
||||
@ -284,6 +297,7 @@ $("#subForm").on("submit", async function(event) {
|
||||
// This field is constructed differently, so needs to be specifically added
|
||||
formData.append("embed_colour", getColourInputVal("subEmbedColour", false));
|
||||
|
||||
|
||||
subId = await saveSubscription(subId, formData);
|
||||
|
||||
if (subId) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user