From f92e22f14232d96c5a373ffe90899055e8aac3b9 Mon Sep 17 00:00:00 2001 From: MaxJa4 <74194322+MaxJa4@users.noreply.github.com> Date: Tue, 16 Jan 2024 21:20:50 +0100 Subject: [PATCH] Implement select counter + select-all + select-none. --- static/index.js | 35 ++++++++++++++++++++++ templates/components/home_player_list.html | 6 ++-- templates/components/opp_player_list.html | 6 ++-- templates/player_list_item.html | 2 +- 4 files changed, 42 insertions(+), 7 deletions(-) diff --git a/static/index.js b/static/index.js index d4bdf3f..c697a7b 100644 --- a/static/index.js +++ b/static/index.js @@ -94,3 +94,38 @@ function loadClans() { console.error('There has been a problem with your fetch operation:', error); }); } + +function updateSelectedPlayers(sender) { + const playerList = sender.parentElement.parentElement.parentElement; + const checkCounter = playerList.parentElement.parentElement.querySelector('span.badge'); + let counter = 0; + + Array.from(playerList.children).forEach(p => { + if (p.querySelector('input[type="checkbox"]:checked')) + counter++; + }); + + checkCounter.innerText = counter; +} + +function selectAllPlayers(playerListId) { + const playerList = document.getElementById(playerListId); + const checkCounter = playerList.parentElement.parentElement.querySelector('span.badge'); + + Array.from(playerList.children).forEach(p => { + p.querySelector('input[type="checkbox"]').checked = true; + }); + + checkCounter.innerText = playerList.children.length; +} + +function deselectAllPlayers(playerListId) { + const playerList = document.getElementById(playerListId); + const checkCounter = playerList.parentElement.parentElement.querySelector('span.badge'); + + Array.from(playerList.children).forEach(p => { + p.querySelector('input[type="checkbox"]').checked = false; + }); + + checkCounter.innerText = 0; +} \ No newline at end of file diff --git a/templates/components/home_player_list.html b/templates/components/home_player_list.html index cc35f48..31b063b 100644 --- a/templates/components/home_player_list.html +++ b/templates/components/home_player_list.html @@ -8,8 +8,8 @@