55 lines
1.3 KiB
HTML
55 lines
1.3 KiB
HTML
{{ define "stores" }}
|
|
<div id="operation-state" class="warning"> </div><br>
|
|
<table>
|
|
<tr>
|
|
<th></th>
|
|
<th>ID</th>
|
|
<th>Name</th>
|
|
</tr>
|
|
{{ range .stores }}
|
|
<tr>
|
|
<th>
|
|
<a class="store-delete-button"
|
|
hx-delete="/stores/{{ .StoreID }}"
|
|
hx-on::after-request="handleDeleteResponse(event)"
|
|
> X </a>
|
|
</th>
|
|
<th><a href="/stores/{{ .StoreID }}">{{ .StoreID }}</a></th>
|
|
<th spellcheck="false" contenteditable>{{ .StoreName }}</th>
|
|
</tr>
|
|
{{ end }}
|
|
</table>
|
|
|
|
<script>
|
|
function handleDeleteResponse(evt) {
|
|
const status = evt.detail.xhr.status;
|
|
const messageDiv = document.getElementById("operation-state")
|
|
|
|
if (status >= 400) {
|
|
messageDiv.textContent = evt.detail.xhr.responseText || "Delete failed";
|
|
|
|
setTimeout(() => {
|
|
messageDiv.textContent = "";
|
|
}, 5000);
|
|
}
|
|
|
|
if (status == 204) {
|
|
const tr = evt.target.closest('tr');
|
|
tr.remove();
|
|
}
|
|
}
|
|
|
|
document.querySelectorAll(".store-delete-button").forEach(btn => {
|
|
// Add the spinner
|
|
btn.addEventListener('htmx:beforeRequest', function () {
|
|
btn.classList.add("loading");
|
|
})
|
|
|
|
// Remove the spinner
|
|
btn.addEventListener('htmx:afterRequest', function (evt) {
|
|
btn.classList.remove("loading");
|
|
});
|
|
})
|
|
</script>
|
|
{{ end }}
|