Fix: revise code

This commit is contained in:
2018-07-03 15:57:49 +09:00
parent fa241a6ee0
commit e28bcf3437
2 changed files with 44 additions and 15 deletions
+3 -7
View File
@@ -133,12 +133,13 @@ function loadPlayerListPage(pageNo) {
} }
// console.log(replyJSON["PlayerList"]); // 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++) { for(let i = 0; i < 10; i++) {
let listIndex = i + 1; // index 0 : list title let listIndex = i + 1; // index 0 : list title
@@ -242,9 +243,4 @@ function addPlayer() {
loadPlayerListPage(1); loadPlayerListPage(1);
} }
} }
}
function deletePlayer(id) {
} }
+41 -8
View File
@@ -1,9 +1,11 @@
class PlayerContent { class PlayerListRow {
constructor(playerID, playerName, enterCode) { constructor(playerID, playerName, enterCode, editButton, deleteButton) {
this.playerID = playerID; this.playerID = playerID;
this.playerName = playerName; this.playerName = playerName;
this.enterCode = enterCode; this.enterCode = enterCode;
this.editButton = editButton;
this.deleteButton = deleteButton;
} }
} }
@@ -18,14 +20,14 @@ class PlayerList {
let id_list = parent.find(".player_id"); let id_list = parent.find(".player_id");
// console.log(id_list); // console.log(id_list);
this.playerContents = new Array(); this.listRows = new Array();
for(let i = 0; i < id_list.length; i++) { 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], // span
$(id_list[i]).siblings(".player_name"), $(id_list[i]).siblings(".player_name"),
$(id_list[i]).siblings(".player_entercode") $(id_list[i]).siblings(".player_entercode"),
// name_list[i + 1], // input $(id_list[i]).siblings(".player_edit"),
// entercode_list[i + 1] // input $(id_list[i]).siblings(".player_delete")
); );
$(id_list[i]).siblings(".player_edit").click(function() { $(id_list[i]).siblings(".player_edit").click(function() {
@@ -35,7 +37,38 @@ class PlayerList {
$(id_list[i]).siblings(".player_delete").click(function() { $(id_list[i]).siblings(".player_delete").click(function() {
self.deletePlayer(this); 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);
}
} }
} }