diff options
Diffstat (limited to 'WebInterface/NodeJSServer/src/modules/ui/server-listing.js')
-rw-r--r-- | WebInterface/NodeJSServer/src/modules/ui/server-listing.js | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/WebInterface/NodeJSServer/src/modules/ui/server-listing.js b/WebInterface/NodeJSServer/src/modules/ui/server-listing.js index 0069ac6..78ca323 100644 --- a/WebInterface/NodeJSServer/src/modules/ui/server-listing.js +++ b/WebInterface/NodeJSServer/src/modules/ui/server-listing.js @@ -1,3 +1,5 @@ +import LoginModal from './login-modal.js'; + /** * Class for handling the server list */ @@ -5,9 +7,11 @@ export default class ServerListing { /** * Creates reference to container * @param {string} serverListId ID of the server list div + * @param {BannerController} notifications Notification Manager */ - constructor(serverListId) { + constructor(serverListId, notifications) { this.serverListing = document.getElementById(serverListId); + this.notifications = notifications; } /** @@ -20,12 +24,13 @@ export default class ServerListing { /** * Populates servers from a given array of games * @param {array} array Array of available games + * @param {ServerClient} serverClient Server Client to handle login + * @param {array} ui UI Elements to reload after login */ - addElements(array) { + addElements(array, serverClient, ui) { for (let server of array) { const name = server['name']; - const playerList = server['users']; - const playerAmount = playerList.length; + const playerAmount = server['userCount']; let serverDiv = document.createElement('div'); let nameSpan = document.createElement('span'); @@ -46,13 +51,16 @@ export default class ServerListing { playerCountSpan.textContent = playerAmount; playerCountStaticSpan.textContent = 'Spieler online'; joinButton.textContent = 'Beitreten'; + joinButton.addEventListener('click', () => { + new LoginModal(name, serverClient, this.notifications, ui); + }); rightAlignDiv.appendChild(onlineDot); rightAlignDiv.appendChild(playerCountSpan); rightAlignDiv.appendChild(playerCountStaticSpan); rightAlignDiv.appendChild(joinButton); serverDiv.appendChild(nameSpan); - serverDiv.appendChild(rightAlignDiv) + serverDiv.appendChild(rightAlignDiv); this.serverListing.appendChild(serverDiv); } } |