24 lines
790 B
JavaScript
24 lines
790 B
JavaScript
const newTrackBtn = document.getElementById("create-track");
|
|
if (newTrackBtn) newTrackBtn.addEventListener("click", event => {
|
|
event.preventDefault();
|
|
const title = prompt("Enter an title for this track:");
|
|
if (title == null || title == "") return;
|
|
|
|
fetch("/api/v1/track", {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify({title})
|
|
}).then(res => {
|
|
res.text().then(text => {
|
|
if (res.ok) {
|
|
location = "/admin/tracks/" + text;
|
|
} else {
|
|
alert(text);
|
|
console.error(text);
|
|
}
|
|
})
|
|
}).catch(err => {
|
|
alert("Failed to create track. Check the console for details.");
|
|
console.error(err);
|
|
});
|
|
});
|