home to your local SPACEGIRL 馃挮 arimelody.space
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at main 58 lines 1.7 kB view raw
1const trackID = document.getElementById("track").dataset.id; 2const titleInput = document.getElementById("title"); 3const descInput = document.getElementById("description"); 4const lyricsInput = document.getElementById("lyrics"); 5const saveBtn = document.getElementById("save"); 6const deleteBtn = document.getElementById("delete"); 7 8saveBtn.addEventListener("click", () => { 9 fetch("/api/v1/track/" + trackID, { 10 method: "PUT", 11 body: JSON.stringify({ 12 title: titleInput.value, 13 description: descInput.value, 14 lyrics: lyricsInput.value, 15 }), 16 headers: { "Content-Type": "application/json" } 17 }).then(res => { 18 if (!res.ok) { 19 res.text().then(error => { 20 console.error(error); 21 alert("Failed to update track: " + error); 22 }); 23 return; 24 } 25 26 location = location; 27 }); 28}); 29 30deleteBtn.addEventListener("click", () => { 31 if (!confirm( 32 "You are about to permanently delete \"" + titleInput.value + "\".\n" + 33 "This action is irreversible. Do you wish to continue?")) return; 34 35 fetch("/api/v1/track/" + trackID, { 36 method: "DELETE", 37 }).then(res => { 38 if (!res.ok) { 39 res.text().then(error => { 40 console.error(error); 41 alert("Failed to delete track: " + error); 42 }); 43 return; 44 } 45 46 location = "/admin"; 47 }); 48}); 49 50[titleInput, descInput, lyricsInput].forEach(input => { 51 input.addEventListener("change", () => { 52 saveBtn.disabled = false; 53 }); 54 input.addEventListener("keypress", () => { 55 saveBtn.disabled = false; 56 }); 57}); 58