2024-08-23 22:08:28 +00:00
|
|
|
<dialog id="editcredits">
|
|
|
|
<header>
|
|
|
|
<h2>Editing: Credits</h2>
|
|
|
|
<a id="add-credit"
|
|
|
|
class="button new"
|
|
|
|
href="/admin/release/{{.ID}}/addcredit"
|
|
|
|
hx-get="/admin/release/{{.ID}}/addcredit"
|
|
|
|
hx-target="body"
|
|
|
|
hx-swap="beforeend"
|
|
|
|
>Add</a>
|
|
|
|
</header>
|
|
|
|
|
|
|
|
<form action="/api/v1/music/{{.ID}}/credits">
|
|
|
|
<ul>
|
|
|
|
{{range .Credits}}
|
|
|
|
<li class="credit" data-artist="{{.Artist.ID}}">
|
|
|
|
<div>
|
|
|
|
<img src="{{.Artist.GetAvatar}}" alt="" width="64" loading="lazy" class="artist-avatar">
|
|
|
|
<div class="credit-info">
|
|
|
|
<p class="artist-name">{{.Artist.Name}}</p>
|
|
|
|
<div class="credit-attribute">
|
|
|
|
<label for="role">Role:</label>
|
|
|
|
<input type="text" name="role" value="{{.Role}}">
|
|
|
|
</div>
|
|
|
|
<div class="credit-attribute">
|
|
|
|
<label for="primary">Primary:</label>
|
|
|
|
<input type="checkbox" name="primary" {{if .Primary}}checked{{end}}>
|
|
|
|
</div>
|
|
|
|
</div>
|
2024-08-31 00:30:30 +00:00
|
|
|
<a class="delete">Delete</a>
|
2024-08-23 22:08:28 +00:00
|
|
|
</div>
|
|
|
|
</li>
|
|
|
|
{{end}}
|
|
|
|
</ul>
|
|
|
|
|
|
|
|
<div class="dialog-actions">
|
|
|
|
<button id="discard" type="button">Discard</button>
|
|
|
|
<button id="save" type="submit" class="save">Save</button>
|
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
|
|
|
|
<script type="module">
|
2024-08-31 00:30:30 +00:00
|
|
|
import { makeMagicList } from "/admin/static/admin.js";
|
|
|
|
|
2024-08-23 22:08:28 +00:00
|
|
|
(() => {
|
|
|
|
const container = document.getElementById("editcredits");
|
|
|
|
const form = document.querySelector("#editcredits form");
|
|
|
|
const creditList = form.querySelector("ul");
|
|
|
|
const addCreditBtn = document.getElementById("add-credit");
|
|
|
|
const discardBtn = form.querySelector("button#discard");
|
|
|
|
|
2024-08-31 00:30:30 +00:00
|
|
|
makeMagicList(creditList, ".credit");
|
2024-08-23 22:08:28 +00:00
|
|
|
|
2024-09-01 03:43:32 +00:00
|
|
|
function rigCredit(el) {
|
|
|
|
console.log(el);
|
2024-08-31 00:30:30 +00:00
|
|
|
const artistID = el.dataset.artist;
|
|
|
|
const deleteBtn = el.querySelector("a.delete");
|
2024-08-23 22:08:28 +00:00
|
|
|
|
|
|
|
deleteBtn.addEventListener("click", e => {
|
|
|
|
if (!confirm("Are you sure you want to delete " + artistID + "'s credit?")) return;
|
|
|
|
el.remove();
|
|
|
|
});
|
|
|
|
|
2024-09-03 07:07:45 +00:00
|
|
|
el.draggable = true;
|
2024-08-31 00:30:30 +00:00
|
|
|
el.addEventListener("dragstart", () => { el.classList.add("moving") });
|
|
|
|
el.addEventListener("dragend", () => { el.classList.remove("moving") });
|
2024-09-01 03:43:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[...creditList.querySelectorAll(".credit")].map(rigCredit);
|
|
|
|
|
|
|
|
creditList.addEventListener("htmx:afterSwap", () => {
|
|
|
|
rigCredit(creditList.children[creditList.children.length - 1]);
|
2024-08-23 22:08:28 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
container.showModal();
|
|
|
|
|
|
|
|
container.addEventListener("close", () => {
|
|
|
|
container.remove();
|
|
|
|
});
|
|
|
|
|
|
|
|
form.addEventListener("submit", e => {
|
2024-08-31 00:30:30 +00:00
|
|
|
const credits = [...creditList.querySelectorAll(".credit")].map(el => {
|
|
|
|
return {
|
|
|
|
"artist": el.dataset.artist,
|
|
|
|
"role": el.querySelector(`input[name="role"]`).value,
|
|
|
|
"primary": el.querySelector(`input[name="primary"]`).checked,
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
2024-08-23 22:08:28 +00:00
|
|
|
e.preventDefault();
|
|
|
|
fetch(form.action, {
|
|
|
|
method: "PUT",
|
2024-08-31 00:30:30 +00:00
|
|
|
headers: { "Content-Type": "application/json" },
|
2024-08-23 22:08:28 +00:00
|
|
|
body: JSON.stringify(credits)
|
|
|
|
}).then(res => {
|
|
|
|
if (res.ok) location = location;
|
|
|
|
else {
|
|
|
|
res.text().then(err => {
|
|
|
|
alert(err);
|
|
|
|
console.error(err);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}).catch(err => {
|
2024-08-31 00:30:30 +00:00
|
|
|
alert("Failed to update credits. Check the console for details.");
|
2024-08-23 22:08:28 +00:00
|
|
|
console.error(err);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
discardBtn.addEventListener("click", e => {
|
|
|
|
e.preventDefault();
|
|
|
|
container.close();
|
|
|
|
});
|
|
|
|
})();
|
|
|
|
</script>
|
|
|
|
</dialog>
|