From 04a2a2815d44c562876c508f1380a273794a33dc Mon Sep 17 00:00:00 2001 From: MaxJa4 <74194322+MaxJa4@users.noreply.github.com> Date: Mon, 15 Jan 2024 11:26:55 +0100 Subject: [PATCH] Add add-player modal and player bar button setup. --- .gitignore | 1 + main.go | 3 +- static/index.js | 47 ++++++++++++++++++++ templates/components/home_player_bar.html | 18 ++++++-- templates/components/opp_player_bar.html | 18 ++++++-- templates/index.html | 5 +++ templates/modals/add_player.html | 54 +++++++++++++++++++++++ 7 files changed, 139 insertions(+), 7 deletions(-) create mode 100644 .gitignore create mode 100644 templates/modals/add_player.html diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e4194d8 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/isc_rest.log diff --git a/main.go b/main.go index cbf1b94..86bd75d 100644 --- a/main.go +++ b/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...) diff --git a/static/index.js b/static/index.js index bb2c1fd..f268b54 100644 --- a/static/index.js +++ b/static/index.js @@ -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]; } \ No newline at end of file diff --git a/templates/components/home_player_bar.html b/templates/components/home_player_bar.html index ac9cb17..2e2080d 100644 --- a/templates/components/home_player_bar.html +++ b/templates/components/home_player_bar.html @@ -12,11 +12,23 @@
- - - + + +
+ + {{ end }} \ No newline at end of file diff --git a/templates/components/opp_player_bar.html b/templates/components/opp_player_bar.html index f07ec08..aac331a 100644 --- a/templates/components/opp_player_bar.html +++ b/templates/components/opp_player_bar.html @@ -12,11 +12,23 @@
- - - + + +
+ + {{ end }} \ No newline at end of file diff --git a/templates/index.html b/templates/index.html index 99e124e..f68b600 100644 --- a/templates/index.html +++ b/templates/index.html @@ -43,6 +43,11 @@ {{ template "add_clan" . }} {{ template "edit_clan" . }} + + +{{ template "add_player" . }} + + + +{{ end }} \ No newline at end of file