active switch toggle
This commit is contained in:
parent
1ded4d318d
commit
40bca25732
@ -230,29 +230,43 @@
|
||||
<script type="text/javascript">
|
||||
function createSubscriptionItem(data) {
|
||||
var template = $($("#subItemTemplate").html());
|
||||
|
||||
// Store the uuid for later reference
|
||||
template.find(".sub-item").attr("data-uuid", data.uuid);
|
||||
|
||||
// Display data
|
||||
template.find(".sub-name").text(data.name);
|
||||
template.find(".sub-uuid").text(data.uuid);
|
||||
template.find(".sub-rss").text(data.rss_url).attr("href", data.rss_url);
|
||||
template.find(".sub-img").attr("src", data.image);
|
||||
template.find(".sub-desc").text(data.extra_notes);
|
||||
template.find(".sub-edit").attr("onclick", `subEditModal("${data.uuid}");`);
|
||||
template.find(".sub-delete").attr("onclick", `unsubscribe("${data.uuid}");`);
|
||||
template.find('[data-bs-toggle="tooltip"]').tooltip();
|
||||
|
||||
|
||||
// Display Sub Description
|
||||
if (!data.extra_notes) {
|
||||
template.find(".sub-desc").hide();
|
||||
} else {
|
||||
template.find(".sub-desc").text(data.extra_notes);
|
||||
}
|
||||
|
||||
// Display formatted datetime
|
||||
var displayDate = new Date(data.creation_datetime).toISOString().slice(0, 10);
|
||||
template.find(".sub-datetime").text(displayDate);
|
||||
|
||||
if (!data.extra_notes) {
|
||||
template.find(".sub-desc").hide();
|
||||
}
|
||||
|
||||
// Provide button functionality
|
||||
template.find(".sub-edit").attr("onclick", `subEditModal("${data.uuid}");`);
|
||||
template.find(".sub-delete").attr("onclick", `unsubscribe("${data.uuid}");`);
|
||||
|
||||
// Enable tooltips
|
||||
template.find('[data-bs-toggle="tooltip"]').tooltip();
|
||||
|
||||
// Make the switch toggle the active flag
|
||||
template.find(".sub-active").prop("checked", data.active).change(function() {
|
||||
alert(JSON.stringify(data, null, 4));
|
||||
getSubscription(data.uuid).then(function(resp) {
|
||||
resp.active = $().prop("checked")
|
||||
editSubscription(resp.uuid, resp)
|
||||
});
|
||||
|
||||
var formData = new FormData();
|
||||
formData.append("active", $(this).prop("checked"));
|
||||
|
||||
patchSubscription(data.uuid, formData).then(function(resp) {
|
||||
console.debug("active flag changed successfully")
|
||||
})
|
||||
});
|
||||
|
||||
return template
|
||||
|
Loading…
x
Reference in New Issue
Block a user