Prepare Player-Delete modal. Update disabled-design.
This commit is contained in:
74
templates/modals/delete_player.html
Normal file
74
templates/modals/delete_player.html
Normal file
@@ -0,0 +1,74 @@
|
||||
{{ define "delete_player" }}
|
||||
|
||||
<div class="modal modal-lg fade" id="deletePlayerModal" tabindex="-1">
|
||||
<div class="modal-dialog modal-dialog-centered">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h1 class="modal-title fs-3 text-danger fw-bold" id="deletePlayerModalLabel">Spieler löschen</h1>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
|
||||
</div>
|
||||
<div class="modal-body fs-5">
|
||||
Möchtest du den Spieler "<span id="player"></span>" wirklich löschen?
|
||||
<br><br>
|
||||
Diese Aktion kann nicht rückgängig gemacht werden.
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="submit" name="submit" class="btn btn-lg btn-danger">Löschen</button>
|
||||
<button type="button" class="btn btn-lg btn-secondary" data-bs-dismiss="modal">Abbrechen</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script lang="javascript">
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
const deletePlayerModal = document.getElementById('deletePlayerModal')
|
||||
const deletePlayerModalBS = new bootstrap.Modal('#deletePlayerModal');
|
||||
if (deletePlayerModal) {
|
||||
deletePlayerModal.addEventListener('show.bs.modal', event => {
|
||||
return;
|
||||
const [clanList, otherClanList] = getClanLists(event);
|
||||
|
||||
const selectedClan = clanList.options[clanList.selectedIndex].text;
|
||||
const modalBodyInput = deletePlayerModal.querySelector('#clan');
|
||||
modalBodyInput.innerText = selectedClan;
|
||||
|
||||
const submitButton = deletePlayerModal.querySelector('button[name="submit"]');
|
||||
submitButton.addEventListener('click', function (e) {
|
||||
e.preventDefault();
|
||||
submitButton.onclick = function () {}
|
||||
|
||||
const clanId = parseInt(clanList.value);
|
||||
|
||||
fetch("/clan/" + clanId, {
|
||||
method: "DELETE",
|
||||
headers: {
|
||||
"Content-type": "application/json; charset=UTF-8"
|
||||
}
|
||||
})
|
||||
.then((response) => {
|
||||
if (response.ok) {
|
||||
const clanToRemove = clanList.children[clanList.selectedIndex];
|
||||
const clanIndex = clanToRemove.index;
|
||||
clanList.removeChild(clanToRemove);
|
||||
clanList.selectedIndex = 0;
|
||||
clanList.dispatchEvent(new Event('change'));
|
||||
|
||||
const lastOtherIndex = otherClanList.selectedIndex;
|
||||
otherClanList.children.item(clanIndex).remove();
|
||||
if (lastOtherIndex === clanIndex) {
|
||||
otherClanList.selectedIndex = 0;
|
||||
otherClanList.dispatchEvent(new Event('change'));
|
||||
}
|
||||
|
||||
deletePlayerModalBS.hide();
|
||||
} else
|
||||
throw new Error(response.error)
|
||||
});
|
||||
})
|
||||
});
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
{{ end }}
|
||||
Reference in New Issue
Block a user