81 lines
3.8 KiB
HTML
81 lines
3.8 KiB
HTML
{{ define "add_player" }}
|
|
|
|
<div class="modal fade" id="addPlayerModal" tabindex="-1">
|
|
<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="addPlayerModalLabel">Spieler hinzufügen</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="playerClanName" placeholder="Clan-Name" disabled>
|
|
<label for="playerClanName">Clan-Name</label>
|
|
</div>
|
|
<div class="form-floating">
|
|
<input type="text" class="form-control form-control-lg" id="playerName" placeholder="Spieler-Name">
|
|
<label for="playerName">Spieler-Name</label>
|
|
</div>
|
|
</div>
|
|
<div class="modal-footer">
|
|
<button type="submit" name="submit" class="btn btn-lg btn-primary">Hinzufügen</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 addPlayerModal = document.getElementById('addPlayerModal');
|
|
const addPlayerModalBS = new bootstrap.Modal('#addPlayerModal');
|
|
if (addPlayerModal) {
|
|
addPlayerModal.addEventListener('show.bs.modal', event => {
|
|
const [playerList, otherPlayerList] = getPlayerLists(event);
|
|
const selectedClan = getSelectedClan(event);
|
|
const playerName = addPlayerModal.querySelector('#playerName');
|
|
const clanName = addPlayerModal.querySelector('#playerClanName');
|
|
clanName.value = selectedClan.innerText;
|
|
const clanId = parseInt(selectedClan.value);
|
|
|
|
const submitButton = addPlayerModal.querySelector('button[name="submit"]');
|
|
submitButton.addEventListener('click', function (e) {
|
|
e.preventDefault();
|
|
submitButton.onclick = function () {}
|
|
|
|
fetch("/player", {
|
|
method: "POST",
|
|
body: JSON.stringify({
|
|
name: playerName.value,
|
|
clan_id: clanId
|
|
}),
|
|
headers: {
|
|
"Content-type": "application/json; charset=UTF-8"
|
|
}
|
|
})
|
|
.then((response) => response.json())
|
|
.then((json) => {
|
|
const opt = document.createElement('option');
|
|
opt.innerText = playerName.value;
|
|
opt.value = json['ID'];
|
|
|
|
playerList.appendChild(opt.cloneNode(true));
|
|
playerList.selectedIndex = playerList.children.length - 1;
|
|
playerList.dispatchEvent(new Event('change'));
|
|
|
|
if (document.getElementById('home-clan').selectedIndex === document.getElementById('opponent-clan').selectedIndex)
|
|
otherPlayerList.appendChild(opt);
|
|
|
|
addPlayerModalBS.hide();
|
|
playerName.value = "";
|
|
clanName.value = "";
|
|
}).catch((error) => {
|
|
throw new Error(error)
|
|
});
|
|
})
|
|
});
|
|
}
|
|
});
|
|
</script>
|
|
|
|
{{ end }} |