Add add-player modal and player bar button setup.

This commit is contained in:
MaxJa4
2024-01-15 11:26:55 +01:00
parent 65d3d994d7
commit 04a2a2815d
7 changed files with 139 additions and 7 deletions

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
/isc_rest.log

View File

@@ -18,7 +18,7 @@ func main() {
models.ConnectDatabase() models.ConnectDatabase()
f, _ := os.OpenFile("isc_rest.log", os.O_RDWR|os.O_APPEND, 0660) f, _ := os.OpenFile("isc_rest.log", os.O_RDWR|os.O_APPEND|os.O_CREATE, 0660)
utils.GinWriter = io.MultiWriter(f, os.Stdout) utils.GinWriter = io.MultiWriter(f, os.Stdout)
router.Use( router.Use(
gin.LoggerWithWriter(utils.GinWriter, "/update"), gin.LoggerWithWriter(utils.GinWriter, "/update"),
@@ -40,6 +40,7 @@ func main() {
"./templates/modals/delete_clan.html", "./templates/modals/delete_clan.html",
"./templates/modals/add_clan.html", "./templates/modals/add_clan.html",
"./templates/modals/edit_clan.html", "./templates/modals/edit_clan.html",
"./templates/modals/add_player.html",
"./templates/components/header.html", "./templates/components/header.html",
} }
tmpl, err := template.ParseFiles(files...) tmpl, err := template.ParseFiles(files...)

View File

@@ -9,6 +9,24 @@ function setupClanButtons(dropdownId, delBtnId, editBtnId) {
}); });
} }
function setupPlayerButtons(dropdownId, listId, delBtnId, editBtnId, addBtnId) {
const dropdown = document.getElementById(dropdownId);
const deleteButton = document.getElementById(delBtnId);
const editButton = document.getElementById(editBtnId);
const addButton = document.getElementById(addBtnId);
dropdown.addEventListener('change', function () {
deleteButton.disabled = !this.value;
editButton.disabled = !this.value && (dropdown.selectedIndex !== -1);
addButton.disabled = !this.value && (dropdown.selectedIndex !== -1);
});
dropdown.addEventListener('change', function () {
deleteButton.disabled = (this.selectedIndex !== -1);
editButton.disabled = (this.selectedIndex !== -1);
});
}
function getClanLists(event) { function getClanLists(event) {
const button = event.relatedTarget; const button = event.relatedTarget;
const clanListId = button.getAttribute('data-bs-list'); const clanListId = button.getAttribute('data-bs-list');
@@ -22,4 +40,33 @@ function getClanLists(event) {
const otherClanList = document.querySelector(otherClanListId); const otherClanList = document.querySelector(otherClanListId);
return [clanList, otherClanList]; return [clanList, otherClanList];
}
function getPlayerLists(event) {
const button = event.relatedTarget;
const playerListId = button.getAttribute('data-bs-list');
const playerList = document.querySelector(playerListId);
let otherPlayerListId;
if (playerListId === '#home-player-list')
otherPlayerListId = '#opponent-player-list'
else
otherPlayerListId = '#home-player-list'
const otherPlayerList = document.querySelector(otherPlayerListId);
return [playerList, otherPlayerList];
}
function getSelectedClan(event) {
const button = event.relatedTarget;
const playerListId = button.getAttribute('data-bs-list');
let clanListId;
if (playerListId === '#home-player-list')
clanListId = '#home-clan'
else
clanListId = '#opponent-clan'
const clanList = document.querySelector(clanListId);
return clanList.options[clanList.selectedIndex];
} }

View File

@@ -12,11 +12,23 @@
</div> </div>
<div class="col-auto"> <div class="col-auto">
<div class="btn-group btn-group-lg" role="group"> <div class="btn-group btn-group-lg" role="group">
<button type="button" class="btn btn-outline-secondary text-danger py-1 px-3"><i class="bi bi-person-dash fs-4"></i></button> <button type="button" class="btn btn-outline-secondary text-danger py-1 px-3" id="home-player-delete" disabled>
<button type="button" class="btn btn-outline-secondary text-primary py-1 px-3"><i class="bi bi-person-gear fs-4"></i></button> <i class="bi bi-person-dash fs-4"></i>
<button type="button" class="btn btn-outline-secondary text-success py-1 px-3"><i class="bi bi-person-add fs-4"></i></button> </button>
<button type="button" class="btn btn-outline-secondary text-primary py-1 px-3" id="home-player-edit" disabled>
<i class="bi bi-person-gear fs-4"></i>
</button>
<button type="button" class="btn btn-outline-secondary text-success py-1 px-3" id="home-player-add" data-bs-toggle="modal" data-bs-list="#home-player-list" data-bs-target="#addPlayerModal" disabled>
<i class="bi bi-person-add fs-4"></i>
</button>
</div> </div>
</div> </div>
</div> </div>
<script lang="javascript">
document.addEventListener('DOMContentLoaded', function() {
setupPlayerButtons('home-clan', 'home-player-list', 'home-player-delete', 'home-player-edit', 'home-player-add');
});
</script>
{{ end }} {{ end }}

View File

@@ -12,11 +12,23 @@
</div> </div>
<div class="col-auto"> <div class="col-auto">
<div class="btn-group btn-group-lg" role="group"> <div class="btn-group btn-group-lg" role="group">
<button type="button" class="btn btn-outline-secondary text-danger py-1 px-3"><i class="bi bi-person-dash fs-4"></i></button> <button type="button" class="btn btn-outline-secondary text-danger py-1 px-3" id="opponent-player-delete" disabled>
<button type="button" class="btn btn-outline-secondary text-primary py-1 px-3"><i class="bi bi-person-gear fs-4"></i></button> <i class="bi bi-person-dash fs-4"></i>
<button type="button" class="btn btn-outline-secondary text-success py-1 px-3"><i class="bi bi-person-add fs-4"></i></button> </button>
<button type="button" class="btn btn-outline-secondary text-primary py-1 px-3" id="opponent-player-edit" disabled>
<i class="bi bi-person-gear fs-4"></i>
</button>
<button type="button" class="btn btn-outline-secondary text-success py-1 px-3" id="opponent-player-add" data-bs-toggle="modal" data-bs-list="#opponent-player-list" data-bs-target="#addPlayerModal" disabled>
<i class="bi bi-person-add fs-4"></i>
</button>
</div> </div>
</div> </div>
</div> </div>
<script lang="javascript">
document.addEventListener('DOMContentLoaded', function() {
setupPlayerButtons('opponent-clan', 'opponent-player-list', 'opponent-player-delete', 'opponent-player-edit', 'opponent-player-add');
});
</script>
{{ end }} {{ end }}

View File

@@ -43,6 +43,11 @@
{{ template "add_clan" . }} {{ template "add_clan" . }}
<!-- Edit Clan Modal --> <!-- Edit Clan Modal -->
{{ template "edit_clan" . }} {{ template "edit_clan" . }}
<!-- Add Player Modal -->
{{ template "add_player" . }}
<script lang="javascript"> <script lang="javascript">
document.addEventListener('DOMContentLoaded', function() { document.addEventListener('DOMContentLoaded', function() {

View File

@@ -0,0 +1,54 @@
{{ 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="clanName" placeholder="Clan-Name" disabled>
<label for="clanName">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 clanTag = addPlayerModal.querySelector('#playerName');
const clanName = addPlayerModal.querySelector('#clanName');
clanName.value = selectedClan.innerText;
const submitButton = addPlayerModal.querySelector('button[name="submit"]');
submitButton.addEventListener('click', function (e) {
e.preventDefault();
submitButton.onclick = function () {}
})
});
}
});
</script>
{{ end }}