Add: player_list.js

This commit is contained in:
2018-07-03 14:35:39 +09:00
parent c4edd7abe1
commit fa241a6ee0
9 changed files with 459 additions and 54 deletions
+27 -26
View File
@@ -3,6 +3,9 @@ let playerCount = 0;
let playerListPage = 0;
let lastPageNo = 0;
let addPlayerList;
let searchPlayerList
$(document).ready(function() {
maestroID = sessionStorage.getItem("maestroID");
@@ -44,7 +47,6 @@ function loadPlayerList() {
playerCount = replyJSON["Count"];
lastPageNo = Math.floor( (playerCount + 1) / 10 );
console.log("registered player count : " + playerCount);
loadPlayerListPage(1);
addPlayerListPages();
}
@@ -69,18 +71,21 @@ function onClickPlayerListPage(pageNo) {
playerListPage = 1;
loadPlayerListPage(playerListPage);
return;
case "prev":
if(playerListPage > 1)
playerListPage -= 1;
loadPlayerListPage(playerListPage);
return;
case "next":
console.log("playerListPage : " + playerListPage);
console.log("lastPageNo : " + lastPageNo);
if(playerListPage < lastPageNo)
playerListPage += 1;
loadPlayerListPage(playerListPage);
return;
case "last":
loadPlayerListPage(lastPageNo);
return;
@@ -90,13 +95,12 @@ function onClickPlayerListPage(pageNo) {
}
function loadPlayerListPage(pageNo) {
playerListPage = pageNo;
let pageIndex = pageNo - 1;
let startNo = pageIndex * 10;
let endNo = pageIndex * 10 + 9;
console.log("startNo : " + startNo);
console.log("endNo : " + endNo);
let xhr = new XMLHttpRequest(); //new로 생성.
xhr.open('POST', './../server/user/registered_player_list_page.php', true);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
@@ -128,33 +132,26 @@ function loadPlayerListPage(pageNo) {
return;
}
console.log(replyJSON["PlayerList"]);
// console.log(replyJSON["PlayerList"]);
updatePlayerListPage(replyJSON["PlayerList"]);
}
}
}
function addPlayerListTitle() {
$("#registered_player_list").empty();
$("#registered_player_list").append(
'<li class="registered_player_list_name">이름</li><li class="registered_player_list_entercode">입장 코드</li>'
);
}
function updatePlayerListPage(playerList) {
$("#registered_player_list").empty();
addPlayerListTitle();
for(let i = 0; i < 10; i++) {
let listIndex = i + 1; // index 0 : list title
for(let i = 0; i < playerList.length; i++) {
$("#registered_player_list").append(
"<li>"
+ "" + playerList[i]["UserID"] + ""
+ "<input type='text' value='" + playerList[i]["Name"] + "' class='registered_player_list_name'>"
+ "<input type='text' value='" + playerList[i]["EnterCode"] + "' class='registered_player_list_entercode'>"
+ "<input type='button' value='수정'>"
+ "</li>"
);
if(i < playerList.length) {
$("#registered_player_list .player_id").filter(":eq(" + i + ")").empty();
$("#registered_player_list .player_id").filter(":eq(" + i + ")").append(playerList[i]["UserID"]);
$("#registered_player_list .player_name").filter(":eq(" + listIndex + ")").val(playerList[i]["Name"]);
$("#registered_player_list .player_entercode").filter(":eq(" + listIndex + ")").val(playerList[i]["EnterCode"]);
} else {
$("#registered_player_list .player_id").filter(":eq(" + i + ")").empty();
$("#registered_player_list .player_name").filter(":eq(" + listIndex + ")").val("");
$("#registered_player_list .player_entercode").filter(":eq(" + listIndex + ")").val("");
}
}
}
@@ -245,5 +242,9 @@ function addPlayer() {
loadPlayerListPage(1);
}
}
}
function deletePlayer(id) {
}
+99
View File
@@ -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);
}
}
}
}