tracks can be edited! + major template overhaul
This commit is contained in:
parent
99b6a21179
commit
63122eb428
21 changed files with 674 additions and 221 deletions
58
admin/static/edit-track.js
Normal file
58
admin/static/edit-track.js
Normal file
|
@ -0,0 +1,58 @@
|
|||
const trackID = document.getElementById("track").dataset.id;
|
||||
const titleInput = document.getElementById("title");
|
||||
const descInput = document.getElementById("description");
|
||||
const lyricsInput = document.getElementById("lyrics");
|
||||
const saveBtn = document.getElementById("save");
|
||||
const deleteBtn = document.getElementById("delete");
|
||||
|
||||
saveBtn.addEventListener("click", () => {
|
||||
fetch("/api/v1/track/" + trackID, {
|
||||
method: "PUT",
|
||||
body: JSON.stringify({
|
||||
title: titleInput.value,
|
||||
description: descInput.value,
|
||||
lyrics: lyricsInput.value,
|
||||
}),
|
||||
headers: { "Content-Type": "application/json" }
|
||||
}).then(res => {
|
||||
if (!res.ok) {
|
||||
res.text().then(error => {
|
||||
console.error(error);
|
||||
alert("Failed to update track: " + error);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
location = location;
|
||||
});
|
||||
});
|
||||
|
||||
deleteBtn.addEventListener("click", () => {
|
||||
if (!confirm(
|
||||
"You are about to permanently delete \"" + titleInput.value + "\".\n" +
|
||||
"This action is irreversible. Do you wish to continue?")) return;
|
||||
|
||||
fetch("/api/v1/track/" + trackID, {
|
||||
method: "DELETE",
|
||||
}).then(res => {
|
||||
if (!res.ok) {
|
||||
res.text().then(error => {
|
||||
console.error(error);
|
||||
alert("Failed to delete track: " + error);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
location = "/admin";
|
||||
});
|
||||
});
|
||||
|
||||
[titleInput, descInput, lyricsInput].forEach(input => {
|
||||
input.addEventListener("change", () => {
|
||||
saveBtn.disabled = false;
|
||||
});
|
||||
input.addEventListener("keypress", () => {
|
||||
saveBtn.disabled = false;
|
||||
});
|
||||
});
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue