Add add-player modal and player bar button setup.
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/isc_rest.log
|
||||
3
main.go
3
main.go
@@ -18,7 +18,7 @@ func main() {
|
||||
|
||||
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)
|
||||
router.Use(
|
||||
gin.LoggerWithWriter(utils.GinWriter, "/update"),
|
||||
@@ -40,6 +40,7 @@ func main() {
|
||||
"./templates/modals/delete_clan.html",
|
||||
"./templates/modals/add_clan.html",
|
||||
"./templates/modals/edit_clan.html",
|
||||
"./templates/modals/add_player.html",
|
||||
"./templates/components/header.html",
|
||||
}
|
||||
tmpl, err := template.ParseFiles(files...)
|
||||
|
||||
@@ -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) {
|
||||
const button = event.relatedTarget;
|
||||
const clanListId = button.getAttribute('data-bs-list');
|
||||
@@ -22,4 +40,33 @@ function getClanLists(event) {
|
||||
const otherClanList = document.querySelector(otherClanListId);
|
||||
|
||||
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];
|
||||
}
|
||||
@@ -12,11 +12,23 @@
|
||||
</div>
|
||||
<div class="col-auto">
|
||||
<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-primary py-1 px-3"><i class="bi bi-person-gear fs-4"></i></button>
|
||||
<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 type="button" class="btn btn-outline-secondary text-danger py-1 px-3" id="home-player-delete" disabled>
|
||||
<i class="bi bi-person-dash fs-4"></i>
|
||||
</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>
|
||||
|
||||
<script lang="javascript">
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
setupPlayerButtons('home-clan', 'home-player-list', 'home-player-delete', 'home-player-edit', 'home-player-add');
|
||||
});
|
||||
</script>
|
||||
|
||||
{{ end }}
|
||||
@@ -12,11 +12,23 @@
|
||||
</div>
|
||||
<div class="col-auto">
|
||||
<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-primary py-1 px-3"><i class="bi bi-person-gear fs-4"></i></button>
|
||||
<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 type="button" class="btn btn-outline-secondary text-danger py-1 px-3" id="opponent-player-delete" disabled>
|
||||
<i class="bi bi-person-dash fs-4"></i>
|
||||
</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>
|
||||
|
||||
<script lang="javascript">
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
setupPlayerButtons('opponent-clan', 'opponent-player-list', 'opponent-player-delete', 'opponent-player-edit', 'opponent-player-add');
|
||||
});
|
||||
</script>
|
||||
|
||||
{{ end }}
|
||||
@@ -43,6 +43,11 @@
|
||||
{{ template "add_clan" . }}
|
||||
<!-- Edit Clan Modal -->
|
||||
{{ template "edit_clan" . }}
|
||||
|
||||
<!-- Add Player Modal -->
|
||||
{{ template "add_player" . }}
|
||||
|
||||
|
||||
<script lang="javascript">
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
|
||||
|
||||
54
templates/modals/add_player.html
Normal file
54
templates/modals/add_player.html
Normal 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 }}
|
||||
Reference in New Issue
Block a user