97 lines
2.5 KiB
JavaScript
97 lines
2.5 KiB
JavaScript
class PlayerListRow {
|
|
|
|
constructor(playerID, playerName, enterCode, editButton, deleteButton) {
|
|
this.playerID = playerID;
|
|
this.playerName = playerName;
|
|
this.enterCode = enterCode;
|
|
this.editButton = editButton;
|
|
this.deleteButton = deleteButton;
|
|
}
|
|
|
|
}
|
|
|
|
class PlayerList {
|
|
|
|
constructor(tagDiv, playerListManager) {
|
|
let self = this;
|
|
this.playerListManager = playerListManager;
|
|
// console.log(tagDiv);
|
|
// console.log(playerListManager);
|
|
|
|
this.playerCount = 0;
|
|
this.activePageNo = 1;
|
|
|
|
// let id_list = tagDiv.find(".player_id");
|
|
let id_list = tagDiv.find(".player-list");
|
|
// console.log(id_list);
|
|
|
|
this.listRows = new Array();
|
|
for(let i = 0; i < id_list.length; i++) {
|
|
this.listRows[i] = new PlayerListRow(
|
|
id_list[i].getElementsByClassName("player_id"),
|
|
id_list[i].getElementsByClassName("player_name"),
|
|
id_list[i].getElementsByClassName("player_entercode"),
|
|
id_list[i].getElementsByClassName("player_edit"),
|
|
id_list[i].getElementsByClassName("player_delete")
|
|
);
|
|
|
|
$(this.listRows[i].editButton).click(function() {
|
|
playerListManager.editPlayer(this);
|
|
})
|
|
|
|
$(this.listRows[i].deleteButton).click(function() {
|
|
playerListManager.deletePlayer(this);
|
|
})
|
|
// console.log(this.listRows[i]);
|
|
// console.log(this.listRows[i].playerName.val());
|
|
|
|
this.disableItem(this.listRows[i]);
|
|
}
|
|
}
|
|
|
|
disableItem(item) {
|
|
$(item.playerID).empty();
|
|
$(item.playerName).prop("disabled", true);
|
|
$(item.enterCode).prop("disabled", true);
|
|
$(item.editButton).prop("disabled", true);
|
|
$(item.deleteButton).prop("disabled", true);
|
|
}
|
|
|
|
enableItem(item) {
|
|
$(item.playerName).prop("disabled", false);
|
|
$(item.enterCode).prop("disabled", false);
|
|
$(item.editButton).prop("disabled", false);
|
|
$(item.deleteButton).prop("disabled", false);
|
|
}
|
|
|
|
updatePlayerList(jsonData) {
|
|
if(jsonData === null) {
|
|
for(let i = 0; i < 10; i++) {
|
|
$(this.listRows[i].playerName).val("");
|
|
$(this.listRows[i].enterCode).val("");
|
|
|
|
this.disableItem(this.listRows[i]);
|
|
}
|
|
|
|
return;
|
|
}
|
|
|
|
for(let i = 0; i < 10; i++) {
|
|
$(this.listRows[i].playerID).empty();
|
|
|
|
if(i < jsonData.length) {
|
|
$(this.listRows[i].playerID).append(jsonData[i]["playerID"]);
|
|
$(this.listRows[i].playerName).val(jsonData[i]["playerName"]);
|
|
$(this.listRows[i].enterCode).val(jsonData[i]["enterCode"]);
|
|
|
|
this.enableItem(this.listRows[i]);
|
|
} else {
|
|
$(this.listRows[i].playerName).val("");
|
|
$(this.listRows[i].enterCode).val("");
|
|
|
|
this.disableItem(this.listRows[i]);
|
|
}
|
|
}
|
|
}
|
|
|
|
} |