Add: player_list.js
This commit is contained in:
@@ -0,0 +1,99 @@
|
||||
class PlayerContent {
|
||||
|
||||
constructor(playerID, playerName, enterCode) {
|
||||
this.playerID = playerID;
|
||||
this.playerName = playerName;
|
||||
this.enterCode = enterCode;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class PlayerList {
|
||||
|
||||
constructor(parent) {
|
||||
let self = this;
|
||||
this.listParent = parent;
|
||||
// console.log(parent);
|
||||
|
||||
let id_list = parent.find(".player_id");
|
||||
// console.log(id_list);
|
||||
|
||||
this.playerContents = new Array();
|
||||
for(let i = 0; i < id_list.length; i++) {
|
||||
this.playerContents[i] = new PlayerContent(
|
||||
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_edit").click(function() {
|
||||
self.editPlayer(this);
|
||||
})
|
||||
|
||||
$(id_list[i]).siblings(".player_delete").click(function() {
|
||||
self.deletePlayer(this);
|
||||
})
|
||||
// console.log(this.playerContents[i].playerName.val());
|
||||
}
|
||||
}
|
||||
|
||||
editPlayer(inputButton) {
|
||||
// console.log(inputButton);
|
||||
|
||||
let id = $(inputButton).siblings(".player_id");
|
||||
// console.log(id);
|
||||
let playerID = id.text();
|
||||
|
||||
console.log(playerID);
|
||||
}
|
||||
|
||||
deletePlayer(inputButton) {
|
||||
let id = $(inputButton).siblings(".player_id");
|
||||
let playerID = id.text();
|
||||
|
||||
if(playerID === null || playerID === "")
|
||||
return;
|
||||
|
||||
console.log(playerID);
|
||||
|
||||
let xhr = new XMLHttpRequest(); //new로 생성.
|
||||
xhr.open('POST', './../server/user/delete_player.php', true);
|
||||
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
||||
xhr.send("maestro_id=" + maestroID + "&player_id=" + playerID);
|
||||
xhr.onload = function() {
|
||||
if(xhr.readyState === 4 && xhr.status === 200) {
|
||||
// console.log(xhr.responseText);
|
||||
// console.log(xhr.responseText.length);
|
||||
if(xhr.responseText.length === 0 || xhr.responseText === null) {
|
||||
console.log("no data from server");
|
||||
return;
|
||||
}
|
||||
|
||||
let replyJSON = JSON.parse(xhr.responseText);
|
||||
// console.log(replyJSON);
|
||||
|
||||
if(replyJSON === null) {
|
||||
console.log("no data from server");
|
||||
return;
|
||||
}
|
||||
|
||||
if(replyJSON["ERROR"] !== undefined || replyJSON["RESULT"] === undefined) {
|
||||
console.log(replyJSON["ERROR"]);
|
||||
return;
|
||||
}
|
||||
|
||||
if(replyJSON["RESULT"] === "fail") {
|
||||
console.log(replyJSON["RESULT"]);
|
||||
return;
|
||||
}
|
||||
|
||||
console.log("update player list");
|
||||
loadPlayerListPage(1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user