From e28bcf3437b7b39d65de9a16f48de82842513227 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=A2=E1=84=91=E1=85=B3=E1=86=AF=20=E1=84=82?= =?UTF-8?q?=E1=85=A9=E1=84=90=E1=85=B3=E1=84=87=E1=85=AE=E1=86=A8?= Date: Tue, 3 Jul 2018 15:57:49 +0900 Subject: [PATCH] Fix: revise code --- src/web/js/maestro_main.js | 10 +++----- src/web/js/player_list.js | 49 +++++++++++++++++++++++++++++++------- 2 files changed, 44 insertions(+), 15 deletions(-) diff --git a/src/web/js/maestro_main.js b/src/web/js/maestro_main.js index 2b7c3a0..1b7fb5f 100644 --- a/src/web/js/maestro_main.js +++ b/src/web/js/maestro_main.js @@ -133,12 +133,13 @@ function loadPlayerListPage(pageNo) { } // console.log(replyJSON["PlayerList"]); - updatePlayerListPage(replyJSON["PlayerList"]); + // updatePlayerListPage(replyJSON["PlayerList"]); + addPlayerList.updatePlayerList(replyJSON["PlayerList"]); } } } -function updatePlayerListPage(playerList) { +function updatePlayerList(playerList) { for(let i = 0; i < 10; i++) { let listIndex = i + 1; // index 0 : list title @@ -242,9 +243,4 @@ function addPlayer() { loadPlayerListPage(1); } } -} - - -function deletePlayer(id) { - } \ No newline at end of file diff --git a/src/web/js/player_list.js b/src/web/js/player_list.js index 550f3af..6b41ec2 100644 --- a/src/web/js/player_list.js +++ b/src/web/js/player_list.js @@ -1,9 +1,11 @@ -class PlayerContent { +class PlayerListRow { - constructor(playerID, playerName, enterCode) { + constructor(playerID, playerName, enterCode, editButton, deleteButton) { this.playerID = playerID; this.playerName = playerName; this.enterCode = enterCode; + this.editButton = editButton; + this.deleteButton = deleteButton; } } @@ -18,14 +20,14 @@ class PlayerList { let id_list = parent.find(".player_id"); // console.log(id_list); - this.playerContents = new Array(); + this.listRows = new Array(); for(let i = 0; i < id_list.length; i++) { - this.playerContents[i] = new PlayerContent( + this.listRows[i] = new PlayerListRow( id_list[i], // span $(id_list[i]).siblings(".player_name"), - $(id_list[i]).siblings(".player_entercode") - // name_list[i + 1], // input - // entercode_list[i + 1] // input + $(id_list[i]).siblings(".player_entercode"), + $(id_list[i]).siblings(".player_edit"), + $(id_list[i]).siblings(".player_delete") ); $(id_list[i]).siblings(".player_edit").click(function() { @@ -35,7 +37,38 @@ class PlayerList { $(id_list[i]).siblings(".player_delete").click(function() { self.deletePlayer(this); }) - // console.log(this.playerContents[i].playerName.val()); + // console.log(this.listRows[i].playerName.val()); + // console.log(this.listRows[i]); + } + } + + updatePlayerList(jsonData) { + // console.log(jsonData); + + for(let i = 0; i < 10; i++) { + $(this.listRows[i].playerID).empty(); + + if(i < jsonData.length) { + $(this.listRows[i].playerID).append(jsonData[i]["UserID"]); + + $(this.listRows[i].playerName).val(jsonData[i]["Name"]); + $(this.listRows[i].playerName).prop("disabled", false); + + $(this.listRows[i].enterCode).val(jsonData[i]["EnterCode"]); + $(this.listRows[i].enterCode).prop("disabled", false); + + $(this.listRows[i].editButton).prop("disabled", false); + $(this.listRows[i].deleteButton).prop("disabled", false); + } else { + $(this.listRows[i].playerName).val(""); + $(this.listRows[i].playerName).prop("disabled", true); + + $(this.listRows[i].enterCode).val(""); + $(this.listRows[i].enterCode).prop("disabled", true); + + $(this.listRows[i].editButton).prop("disabled", true); + $(this.listRows[i].deleteButton).prop("disabled", true); + } } }