document.addEventListener('DOMContentLoaded', function() { const tooltipTriggerList = document.querySelectorAll('[data-bs-toggle="tooltip"]'); tooltipTriggerList.forEach((elem) => { new bootstrap.Tooltip(elem); }); }); function setupClanButtons(dropdownId, delBtnId, editBtnId) { const dropdown = document.getElementById(dropdownId); const deleteButton = document.getElementById(delBtnId); const editButton = document.getElementById(editBtnId); dropdown.addEventListener('change', function () { deleteButton.disabled = !this.value; deleteButton.classList.toggle("bg-secondary-subtle"); editButton.disabled = !this.value; editButton.classList.toggle("bg-secondary-subtle"); }); } function getSelectedClanId(dropdownId) { const dropdown = document.getElementById(dropdownId); const selectedClanId = dropdown.options[dropdown.selectedIndex].value; return parseInt(selectedClanId); } function setupPlayerButtons(dropdownId, listId, addBtnId) { const dropdown = document.getElementById(dropdownId); const addButton = document.getElementById(addBtnId); dropdown.addEventListener('change', function () { addButton.disabled = !this.value && (dropdown.selectedIndex !== -1); addButton.classList.toggle("bg-secondary-subtle"); }); } function getClanLists(event) { const button = event.relatedTarget; const clanListId = button.getAttribute('data-bs-list'); const clanList = document.querySelector(clanListId); let otherClanListId; if (clanListId === '#home-clan') otherClanListId = '#opponent-clan' else otherClanListId = '#home-clan' const otherClanList = document.querySelector(otherClanListId); return [clanList, otherClanList]; } function getPlayerLists(event) { const button = event.relatedTarget; let playerListId = button.getAttribute('data-bs-list'); if (playerListId === null) playerListId = '#' + button.closest('ul').parentElement.parentElement.id; 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; let playerListId = button.getAttribute('data-bs-list'); if (playerListId === null) playerListId = '#' + button.closest('ul').parentElement.parentElement.id; let clanListId; if (playerListId === '#home-player-list') clanListId = '#home-clan' else clanListId = '#opponent-clan' const clanList = document.querySelector(clanListId); return clanList.options[clanList.selectedIndex]; } function loadClans() { const homeClanList = document.getElementById('home-clan'); const oppClanList = document.getElementById('opponent-clan'); fetch('/clans_html') .then(response => { if (!response.ok) { throw new Error('Network response was not ok'); } return response.text(); }) .then(data => { homeClanList.innerHTML = data; oppClanList.innerHTML = data; }) .catch(error => { 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; }