implemented toasts in several areas
This commit is contained in:
parent
87c4adac83
commit
ecb75cfcc7
@ -137,6 +137,7 @@
|
||||
<label for="editSubChannels">Channels</label>
|
||||
<select name="editSubChannels" id="editSubChannels" class="border-3 bd select-2" data-dropdownparent="#subEditModal" required multiple>
|
||||
</select>
|
||||
<div class="invalid-feedback">Please Select one or more Channels.</div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="navExtrasPanel" class="tab-pane fade" role="tabpanel" aria-labelledby="navExtrasTab" tabindex="0">
|
||||
@ -240,7 +241,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="peer">
|
||||
<button type="button" class="btn bg-body-tertiary waves-effect bd rounded-3 border-0" onclick="showToast('warning', 'Warning', 'not implemented');">
|
||||
<button type="button" class="btn bg-body-tertiary waves-effect bd rounded-3 border-0" onclick="showToast('warning', 'Warning', 'Activity History not implemented yet');">
|
||||
<i class="bi bi-clock-history"></i>
|
||||
</button>
|
||||
</div>
|
||||
@ -298,11 +299,14 @@
|
||||
// Make the switch toggle the active flag
|
||||
template.find(".sub-active").prop("checked", data.active).change(function() {
|
||||
|
||||
var isChecked = $(this).prop("checked");
|
||||
var activeText = isChecked === true ? "active" : "inactive";
|
||||
|
||||
var formData = new FormData();
|
||||
formData.append("active", $(this).prop("checked"));
|
||||
formData.append("active", isChecked);
|
||||
|
||||
patchSubscription(data.uuid, formData).then(function(resp) {
|
||||
console.debug("active flag changed successfully");
|
||||
showToast("success", "Subscription Modified", `<b>${data.name}</b> is now <b>${activeText}</b>.`);
|
||||
})
|
||||
});
|
||||
|
||||
@ -332,11 +336,38 @@
|
||||
}
|
||||
},
|
||||
error: function(response) {
|
||||
alert(JSON.stringify(response, null, 4));
|
||||
console.error(JSON.stringify(response, null, 4));
|
||||
showToast("danger", `Error Loading Guilds`, "Couldn't load user guilds. Try refreshing the page.", 15000);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function processChannelsResponseError(response) {
|
||||
switch (response.code) {
|
||||
|
||||
// 50001:
|
||||
// Forbidden response
|
||||
case 50001:
|
||||
showToast(
|
||||
"danger",
|
||||
`Discord API Error: ${response.code}`,
|
||||
`PYRSS Bot is lacking forbidden from fetching channels for this server.
|
||||
Ensure that at least one condition is true:
|
||||
<ul>
|
||||
<li>The server is a community server.</li>
|
||||
<li>PYRSS Bot is a member of the server.</li>
|
||||
</ul>
|
||||
`,
|
||||
10000
|
||||
);
|
||||
break;
|
||||
|
||||
default:
|
||||
showToast("danger", `Discord API Error: ${response.code}`, response.message, 10000);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
function loadChannels(guildID) {
|
||||
$("#editSubChannels").empty();
|
||||
$("#editSubChannels").val(null);
|
||||
@ -344,6 +375,23 @@
|
||||
url: `/channels?guild=${guildID}`,
|
||||
type: "GET",
|
||||
success: function(response) {
|
||||
|
||||
// Validate the response, if property "code" exists, there is an error.
|
||||
// A valid response only returns a list.
|
||||
if (response.hasOwnProperty("code")) {
|
||||
processChannelsResponseError(response);
|
||||
return;
|
||||
}
|
||||
|
||||
if (response.hasOwnProperty("code") && response.code === 50001) {
|
||||
showToast(
|
||||
"danger", "Unable to fetch channels",
|
||||
"PYRSS Bot is lacking permissions to fetch the channels from this server, ensure one of two conditions is met: <br><ul><li>The server is a community server</li><li>PYRSS Bot is a member of the server</li></ul>",
|
||||
10000
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = 1; i < response.length; i++) {
|
||||
var channel = response[i];
|
||||
|
||||
@ -368,8 +416,8 @@
|
||||
}
|
||||
},
|
||||
error: function(response) {
|
||||
console.error(JSON.stringify(response, null, 4));
|
||||
|
||||
alert(JSON.stringify(response, null, 4));
|
||||
// showToast("danger", `Error Loading Guilds`, "Couldn't load user guilds. Try refreshing the page.", 15000);
|
||||
if (response.code == "50001") {
|
||||
alert("PYRSS Bot is Missing Access to this Server");
|
||||
}
|
||||
@ -409,11 +457,17 @@
|
||||
function unsubscribe(uuid) {
|
||||
var subElem = $(`#subscriptionContainer .sub-item[data-uuid="${uuid}"]`);
|
||||
subElem.find("button").prop("disabled", true);
|
||||
var subName = subElem.find(".sub-name").text();
|
||||
|
||||
deleteSubscription(uuid).then(resp => {
|
||||
subElem.parent().remove();
|
||||
updateSubscriptionCount(-1);
|
||||
$("#subDeleteModal").modal("hide");
|
||||
showToast(
|
||||
"success",
|
||||
"Deleted Subscription",
|
||||
`Successfully deleted <b>${subName}</b>.`
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@ -466,6 +520,7 @@
|
||||
formData.append("rss_url", $("#editSubURL").val());
|
||||
formData.append("server", $("#editSubServer").val());
|
||||
formData.append("extra_notes", $("#editSubNotes").val());
|
||||
formData.append("active", true);
|
||||
|
||||
var selectedTargets = $("#editSubChannels option:selected").toArray().map(item => item.value).join(';');
|
||||
formData.append("targets", selectedTargets);
|
||||
@ -479,14 +534,14 @@
|
||||
newSubscription(formData).then(resp => {
|
||||
loadSubscriptions();
|
||||
$("#subEditModal").modal("hide");
|
||||
showToast("success", "Subscription Created", `<b>${subName}</b> successfully created.`);
|
||||
})
|
||||
showToast("success", "Subscription Created", `${subName} successfully created.`);
|
||||
}
|
||||
else {
|
||||
editSubscription(uuid, formData).then(resp => {
|
||||
loadSubscriptions();
|
||||
$("#subEditModal").modal("hide");
|
||||
showToast("success", "Subscription Modified", `${subName} successfully modified.`);
|
||||
showToast("success", "Subscription Modified", `<b>${subName}</b> successfully modified.`);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user