Optimize all modals (fetching). Implement add-player modal.
This commit is contained in:
@@ -37,6 +37,8 @@
|
||||
const clanName = addPlayerModal.querySelector('#playerClanName');
|
||||
clanName.value = selectedClan.innerText;
|
||||
const clanId = parseInt(selectedClan.value);
|
||||
const homeClanListIndex = document.getElementById('home-clan').selectedIndex;
|
||||
const oppClanListIndex = document.getElementById('opponent-clan').selectedIndex;
|
||||
|
||||
const submitButton = addPlayerModal.querySelector('button[name="submit"]');
|
||||
submitButton.addEventListener('click', function (e) {
|
||||
@@ -53,18 +55,12 @@
|
||||
"Content-type": "application/json; charset=UTF-8"
|
||||
}
|
||||
})
|
||||
.then((response) => response.json())
|
||||
.then((json) => {
|
||||
const opt = document.createElement('option');
|
||||
opt.innerText = playerName.value;
|
||||
opt.value = json['ID'];
|
||||
|
||||
playerList.appendChild(opt.cloneNode(true));
|
||||
playerList.selectedIndex = playerList.children.length - 1;
|
||||
playerList.dispatchEvent(new Event('change'));
|
||||
|
||||
if (document.getElementById('home-clan').selectedIndex === document.getElementById('opponent-clan').selectedIndex)
|
||||
otherPlayerList.appendChild(opt);
|
||||
.then(() => {
|
||||
const sameClan = homeClanListIndex === oppClanListIndex;
|
||||
if (playerList.id === 'home-player-list' || sameClan)
|
||||
htmx.ajax('GET', '/players_html', {target: '#home-player-list', values: {"clan_id": getSelectedClanId("home-clan")}});
|
||||
if (playerList.id === 'opponent-player-list' || sameClan)
|
||||
htmx.ajax('GET', '/players_html', {target: '#opponent-player-list', values: {"clan_id": getSelectedClanId("opponent-clan")}});
|
||||
|
||||
addPlayerModalBS.hide();
|
||||
playerName.value = "";
|
||||
@@ -72,7 +68,7 @@
|
||||
}).catch((error) => {
|
||||
throw new Error(error)
|
||||
});
|
||||
})
|
||||
}, { once: true });
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user