Files
InfantrySkillCalculator/templates/modals/add_clan.html
2024-01-16 20:54:49 +01:00

95 lines
4.4 KiB
HTML

{{ define "add_clan" }}
<div class="modal fade" id="addClanModal" 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="addClanModalLabel">Clan 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="clanName" placeholder="Clan-Name">
<label for="clanName">Clan-Name</label>
</div>
<div class="form-floating">
<input type="text" class="form-control form-control-lg" id="clanTag" placeholder="Clan-Tag">
<label for="clanTag">Clan-Tag</label>
</div>
<div class="form-check form-check-inline mt-3 fs-5">
<input class="form-check-input" type="checkbox" id="keepUpdated" value="keepUpdated">
<label class="form-check-label" for="keepUpdated">Immer aktuell halten</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 addClanModal = document.getElementById('addClanModal');
const addClanModalBS = new bootstrap.Modal('#addClanModal');
if (addClanModal) {
addClanModal.addEventListener('shown.bs.modal', event => {
const submitButton = addClanModal.querySelector('button[name="submit"]');
submitButton.addEventListener('click', function () {
const [clanList, otherClanList] = getClanLists(event);
const clanName = addClanModal.querySelector('#clanName');
const clanTag = addClanModal.querySelector('#clanTag');
const keepUpdated = addClanModal.querySelector('#keepUpdated');
fetch("/clan", {
method: "POST",
body: JSON.stringify({
name: clanName.value,
tag: clanTag.value,
keep_updated: keepUpdated.checked
}),
headers: {
"Content-type": "application/json; charset=UTF-8"
}
})
.then(() => {
const lastIndex = otherClanList.selectedIndex;
fetch('/clans_html')
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.text();
})
.then(data => {
clanList.innerHTML = data;
otherClanList.innerHTML = data;
clanList.selectedIndex = clanList.children.length - 1;
otherClanList.selectedIndex = lastIndex;
clanList.dispatchEvent(new Event('change'));
})
.catch(error => {
console.error('There has been a problem with your fetch operation:', error);
});
addClanModalBS.hide();
clanName.value = "";
clanTag.value = "";
keepUpdated.checked = false;
})
.catch((error) => {
throw new Error(error)
});
}, { once: true });
});
}
});
</script>
{{ end }}