411 lines
11 KiB
JavaScript
411 lines
11 KiB
JavaScript
class PlayerListManager {
|
|
|
|
constructor(docList, docNav) {
|
|
let self = this;
|
|
this.docList = docList;
|
|
this.docNav = docNav;
|
|
|
|
this.list = new PlayerList(this.docList, this);
|
|
this.listNavigator = new PlayerListNavigator(this.docNav);
|
|
|
|
this.playerCount = 0;
|
|
this.activePageNo = 1;
|
|
this.lastPageNo = 0;
|
|
|
|
}
|
|
|
|
|
|
setupAddPlayerList() {
|
|
let self = this;
|
|
|
|
let xhr = new XMLHttpRequest(); //new로 생성.
|
|
xhr.open('POST', './../server/player/registered_player_count.php', true);
|
|
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
|
xhr.send("maestro_id=" + maestroID);
|
|
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;
|
|
}
|
|
|
|
self.playerCount = replyJSON["Count"];
|
|
self.lastPageNo = Math.ceil( (self.playerCount + 1) / 10 );
|
|
self.activePageNo = 1;
|
|
|
|
self.loadAddPlayerListPage(self.activePageNo);
|
|
self.listNavigator.updateNavigator(self.activePageNo, self.lastPageNo);
|
|
}
|
|
}
|
|
}
|
|
|
|
loadAddPlayerListPage(pageNo) {
|
|
self = this;
|
|
this.activePageNo = pageNo;
|
|
|
|
let pageIndex = pageNo - 1;
|
|
let startNo = pageIndex * 10;
|
|
let endNo = pageIndex * 10 + 9;
|
|
|
|
let xhr = new XMLHttpRequest(); //new로 생성.
|
|
xhr.open('POST', './../server/player/registered_player_list.php', true);
|
|
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
|
xhr.send("maestro_id=" + maestroID + "&start_no=" + startNo + "&end_no=" + endNo);
|
|
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(replyJSON["PlayerList"]);
|
|
// updatePlayerListPage(replyJSON["PlayerList"]);
|
|
self.list.updatePlayerList(replyJSON["PlayerList"]);
|
|
|
|
self.playerCount = replyJSON["PlayerList"].length;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
updateAddPlayerListPage(pageNo) {
|
|
self = this;
|
|
this.playerListPage = pageNo;
|
|
|
|
let pageIndex = pageNo - 1;
|
|
let startNo = pageIndex * 10;
|
|
let endNo = pageIndex * 10 + 9;
|
|
|
|
let xhr = new XMLHttpRequest(); //new로 생성.
|
|
xhr.open('POST', './../server/player/registered_player_list.php', true);
|
|
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
|
xhr.send("maestro_id=" + maestroID + "&start_no=" + startNo + "&end_no=" + endNo);
|
|
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(replyJSON["PlayerList"]);
|
|
self.list.updatePlayerList(replyJSON["PlayerList"]);
|
|
|
|
self.playerCount = replyJSON["PlayerList"].length;
|
|
// console.log(self.playerCount);
|
|
// self.lastPageNo = Math.ceil( (self.playerCount + 1) / 10 );
|
|
// self.activePageNo = 1;
|
|
|
|
self.listNavigator.updateNavigator(self.activePageNo, self.lastPageNo);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
setupSearchPlayerList(playerName) {
|
|
let self = this;
|
|
|
|
let xhr = new XMLHttpRequest(); //new로 생성.
|
|
xhr.open('POST', './../server/player/search_player_count.php', true);
|
|
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
|
xhr.send("maestro_id=" + maestroID + "&player_name=" + playerName);
|
|
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;
|
|
}
|
|
|
|
self.playerCount = replyJSON["Count"];
|
|
self.lastPageNo = Math.ceil( (self.playerCount + 1) / 10 );
|
|
self.activePageNo = 1;
|
|
|
|
self.updateSearchPlayerListPage(playerName, 1);
|
|
}
|
|
}
|
|
}
|
|
|
|
updateSearchPlayerListPage(playerName, pageNo) {
|
|
let self = this;
|
|
this.playerListPage = pageNo;
|
|
|
|
let pageIndex = pageNo - 1;
|
|
let startNo = pageIndex * 10;
|
|
let endNo = pageIndex * 10 + 9;
|
|
|
|
let xhr = new XMLHttpRequest(); //new로 생성.
|
|
xhr.open('POST', './../server/player/search_player_list.php', true);
|
|
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
|
xhr.send("maestro_id=" + maestroID + "&player_name=" + playerName + "&start_no=" + startNo + "&end_no=" + endNo);
|
|
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(replyJSON["PlayerList"]);
|
|
self.list.updatePlayerList(replyJSON["PlayerList"]);
|
|
|
|
self.playerCount = replyJSON["PlayerList"].length;
|
|
// self.lastPageNo = Math.ceil( (self.playerCount + 1) / 10 );
|
|
// self.activePageNo = 1;
|
|
|
|
self.listNavigator.updateNavigator(self.activePageNo, self.lastPageNo);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
onClickPlayerListPage(pageNo) {
|
|
switch(pageNo) {
|
|
case "first":
|
|
this.activePageNo = 1;
|
|
self.loadAddPlayerListPage(self.activePageNo);
|
|
return;
|
|
|
|
case "prev":
|
|
if(this.activePageNo > 1)
|
|
this.activePageNo -= 1;
|
|
self.loadAddPlayerListPage(self.activePageNo);
|
|
return;
|
|
|
|
case "next":
|
|
if(this.activePageNo < this.lastPageNo)
|
|
this.activePageNo += 1;
|
|
self.loadAddPlayerListPage(self.activePageNo);
|
|
return;
|
|
|
|
case "last":
|
|
this.loadAddPlayerListPage(this.lastPageNo);
|
|
return;
|
|
}
|
|
|
|
this.activePageNo = pageNo;
|
|
self.loadAddPlayerListPage(self.activePageNo);
|
|
}
|
|
|
|
|
|
editPlayer(inputButton) {
|
|
// console.log(inputButton);
|
|
let clickedObjectID = this.getClickedObjectID(inputButton);
|
|
|
|
|
|
let id = $(inputButton).siblings(".player_id");
|
|
let playerID = id.text();
|
|
// console.log(playerID);
|
|
|
|
let name = $(inputButton).siblings(".player_name");
|
|
let playerName = name.val();
|
|
// console.log(playerName);
|
|
|
|
let enterCode = $(inputButton).siblings(".player_entercode");
|
|
let playerEnterCode = enterCode.val();
|
|
// console.log(playerEnterCode);
|
|
|
|
let xhr = new XMLHttpRequest(); //new로 생성.
|
|
xhr.open('POST', './../server/player/edit_player.php', true);
|
|
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
|
xhr.send("maestro_id=" + maestroID + "&player_id=" + playerID + "&player_name=" + playerName + "&enter_code=" + playerEnterCode);
|
|
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(clickedObjectID);
|
|
if(clickedObjectID === "add_player_list") {
|
|
self.setupAddPlayerList();
|
|
} else if(clickedObjectID === "search_player_list") {
|
|
let playerName = $("#search_name").val();
|
|
self.setupSearchPlayerList(playerName);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
deletePlayer(inputButton) {
|
|
let self = this;
|
|
|
|
let id = $(inputButton).siblings(".player_id");
|
|
let playerID = id.text();
|
|
|
|
let clickedObjectID = this.getClickedObjectID(inputButton);
|
|
|
|
if(playerID === null || playerID === "")
|
|
return;
|
|
|
|
let xhr = new XMLHttpRequest(); //new로 생성.
|
|
xhr.open('POST', './../server/player/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(clickedObjectID);
|
|
if(clickedObjectID === "add_player_list") {
|
|
self.setupAddPlayerList();
|
|
} else if(clickedObjectID === "search_player_list") {
|
|
let playerName = $("#search_name").val();
|
|
self.setupSearchPlayerList(playerName);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
getClickedObjectID(clickedObject) {
|
|
let tagDiv = $(clickedObject).closest(".player_list");
|
|
let tagDivID = tagDiv.prop("id");
|
|
// console.log(tagDivIDName);
|
|
|
|
return tagDivID;
|
|
}
|
|
|
|
|
|
|
|
} |