Implement edit-player. Optimizations.
This commit is contained in:
@@ -42,6 +42,8 @@
|
||||
{{ template "add_player" . }}
|
||||
<!-- Delete Player Modal -->
|
||||
{{ template "delete_player" . }}
|
||||
<!-- Edit Player Modal -->
|
||||
{{ template "edit_player" . }}
|
||||
|
||||
<script lang="javascript">
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
|
||||
@@ -36,10 +36,7 @@
|
||||
if (addClanModal) {
|
||||
addClanModal.addEventListener('shown.bs.modal', event => {
|
||||
const submitButton = addClanModal.querySelector('button[name="submit"]');
|
||||
submitButton.addEventListener('click', function (e) {
|
||||
e.preventDefault();
|
||||
submitButton.onclick = function () {}
|
||||
|
||||
submitButton.addEventListener('click', function () {
|
||||
const [clanList, otherClanList] = getClanLists(event);
|
||||
|
||||
const clanName = addClanModal.querySelector('#clanName');
|
||||
@@ -89,7 +86,7 @@
|
||||
.catch((error) => {
|
||||
throw new Error(error)
|
||||
});
|
||||
})
|
||||
}, { once: true });
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
@@ -41,10 +41,7 @@
|
||||
const oppClanListIndex = document.getElementById('opponent-clan').selectedIndex;
|
||||
|
||||
const submitButton = addPlayerModal.querySelector('button[name="submit"]');
|
||||
submitButton.addEventListener('click', function (e) {
|
||||
e.preventDefault();
|
||||
submitButton.onclick = function () {}
|
||||
|
||||
submitButton.addEventListener('click', function () {
|
||||
fetch("/player", {
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
|
||||
@@ -33,10 +33,7 @@
|
||||
modalBodyInput.innerText = selectedClan;
|
||||
|
||||
const submitButton = deleteClanModal.querySelector('button[name="submit"]');
|
||||
submitButton.addEventListener('click', function (e) {
|
||||
e.preventDefault();
|
||||
submitButton.onclick = function () {}
|
||||
|
||||
submitButton.addEventListener('click', function () {
|
||||
const clanId = parseInt(clanList.value);
|
||||
|
||||
fetch("/clan/" + clanId, {
|
||||
@@ -69,7 +66,7 @@
|
||||
.catch((error) => {
|
||||
throw new Error(error)
|
||||
});
|
||||
})
|
||||
}, { once: true });
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
@@ -38,10 +38,7 @@
|
||||
const oppClanListIndex = document.getElementById('opponent-clan').selectedIndex;
|
||||
|
||||
const submitButton = deletePlayerModal.querySelector('button[name="submit"]');
|
||||
submitButton.addEventListener('click', function (e) {
|
||||
e.preventDefault();
|
||||
submitButton.onclick = function () {}
|
||||
|
||||
submitButton.addEventListener('click', function () {
|
||||
fetch("/player/" + playerId, {
|
||||
method: "DELETE",
|
||||
headers: {
|
||||
@@ -60,7 +57,7 @@
|
||||
.catch((error) => {
|
||||
throw new Error(error)
|
||||
});
|
||||
})
|
||||
}, { once: true });
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<div class="modal-dialog modal-dialog-centered">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h1 class="modal-title fs-3 text-success fw-bold" id="editClanModalLabel">Clan bearbeiten</h1>
|
||||
<h1 class="modal-title fs-3 text-primary fw-bold" id="editClanModalLabel">Clan bearbeiten</h1>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
@@ -32,17 +32,12 @@
|
||||
|
||||
<script lang="javascript">
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
|
||||
const editClanModal = document.getElementById('editClanModal');
|
||||
const editClanModalBS = new bootstrap.Modal('#editClanModal');
|
||||
if (editClanModal) {
|
||||
editClanModal.addEventListener('show.bs.modal', event => {
|
||||
const [clanList, otherClanList] = getClanLists(event);
|
||||
|
||||
const selectedClanIndex = clanList.selectedIndex;
|
||||
const selectedClanItem = clanList.options[selectedClanIndex];
|
||||
const otherSelClanItem = otherClanList.options[selectedClanIndex];
|
||||
|
||||
const clanName = editClanModal.querySelector('#editClanName');
|
||||
const clanTag = editClanModal.querySelector('#editClanTag');
|
||||
const keepUpdated = editClanModal.querySelector('#editKeepUpdated');
|
||||
@@ -67,9 +62,7 @@
|
||||
throw new Error(error);
|
||||
});
|
||||
|
||||
submitButton.addEventListener('click', function (e) {
|
||||
e.preventDefault();
|
||||
submitButton.onclick = function () {}
|
||||
submitButton.addEventListener('click', function () {
|
||||
fetch("/clan/" + clanId, {
|
||||
method: "PATCH",
|
||||
body: JSON.stringify({
|
||||
@@ -111,7 +104,7 @@
|
||||
.catch((error) => {
|
||||
throw new Error(error)
|
||||
});
|
||||
})
|
||||
}, { once: true });
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
75
templates/modals/edit_player.html
Normal file
75
templates/modals/edit_player.html
Normal file
@@ -0,0 +1,75 @@
|
||||
{{ define "edit_player" }}
|
||||
|
||||
<div class="modal fade" id="editPlayerModal" tabindex="-1">
|
||||
<div class="modal-dialog modal-dialog-centered">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h1 class="modal-title fs-3 text-primary fw-bold" id="editPlayerModalLabel">Spieler bearbeiten</h1>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<div class="form-floating mb-3">
|
||||
<input type="text" class="form-control form-control-lg" id="editPlayerName" placeholder="Spieler-Name">
|
||||
<label for="editPlayerName">Spieler-Name</label>
|
||||
</div>
|
||||
<input type="hidden" id="editPlayerId" value="">
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="submit" name="submit" class="btn btn-lg btn-primary">Speichern</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 editPlayerModal = document.getElementById('editPlayerModal');
|
||||
const editPlayerModalBS = new bootstrap.Modal('#editPlayerModal');
|
||||
if (editPlayerModal) {
|
||||
editPlayerModal.addEventListener('show.bs.modal', event => {
|
||||
const [playerList, otherPlayerList] = getPlayerLists(event);
|
||||
const selectedClan = getSelectedClan(event);
|
||||
const playerName = editPlayerModal.querySelector('#editPlayerName');
|
||||
const clanId = parseInt(selectedClan.value);
|
||||
const homeClanListIndex = document.getElementById('home-clan').selectedIndex;
|
||||
const oppClanListIndex = document.getElementById('opponent-clan').selectedIndex;
|
||||
|
||||
const button = event.relatedTarget;
|
||||
const playerId = parseInt(button.getAttribute('data-bs-id'));
|
||||
playerName.value = button.closest('.input-group').querySelector('span').innerText;
|
||||
|
||||
const submitButton = editPlayerModal.querySelector('button[name="submit"]');
|
||||
submitButton.addEventListener('click', function (e) {
|
||||
e.preventDefault();
|
||||
submitButton.onclick = function () {}
|
||||
|
||||
fetch("/player/" + playerId, {
|
||||
method: "PATCH",
|
||||
body: JSON.stringify({
|
||||
name: playerName.value,
|
||||
clan_id: clanId
|
||||
}),
|
||||
headers: {
|
||||
"Content-type": "application/json; charset=UTF-8"
|
||||
}
|
||||
})
|
||||
.then(() => {
|
||||
const sameClan = homeClanListIndex === oppClanListIndex;
|
||||
if (playerList.id === 'home-player-list' || sameClan)
|
||||
htmx.ajax('GET', '/players_html', {target: '#home-player-list', values: {"clan_id": getSelectedClanId("home-clan")}});
|
||||
if (playerList.id === 'opponent-player-list' || sameClan)
|
||||
htmx.ajax('GET', '/players_html', {target: '#opponent-player-list', values: {"clan_id": getSelectedClanId("opponent-clan")}});
|
||||
|
||||
editPlayerModalBS.hide();
|
||||
playerName.value = "";
|
||||
}).catch((error) => {
|
||||
throw new Error(error)
|
||||
});
|
||||
}, { once: true });
|
||||
});
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
{{ end }}
|
||||
@@ -5,7 +5,7 @@
|
||||
<span class="form-control py-1 px-2">%s</span>
|
||||
<button class="btn btn-outline-secondary text-secondary-emphasis dropdown-toggle py-1" type="button" data-bs-toggle="dropdown"></button>
|
||||
<ul class="dropdown-menu dropdown-menu-end">
|
||||
<li><a class="dropdown-item text-primary fs-5" href="#">
|
||||
<li><a class="dropdown-item text-primary fs-5" href="#" data-bs-toggle="modal" data-bs-id="%d" data-bs-target="#editPlayerModal">
|
||||
<i class="bi bi-person-gear fs-4 me-2"></i>Bearbeiten
|
||||
</a></li>
|
||||
<li><a class="dropdown-item text-danger fs-5" href="#" data-bs-toggle="modal" data-bs-id="%d" data-bs-target="#deletePlayerModal">
|
||||
|
||||
Reference in New Issue
Block a user