Add: player list manager
This commit is contained in:
@@ -0,0 +1,196 @@
|
||||
class PlayerListManager {
|
||||
|
||||
constructor(docList, docNav) {
|
||||
let self = this;
|
||||
this.docList = docList;
|
||||
this.docNav = docNav;
|
||||
|
||||
this.list = new PlayerList(this.docList);
|
||||
this.listNavigator = new PlayerListNavigator(this.docNav);
|
||||
// console.log(this.list);
|
||||
// console.log(this.listNavigator);
|
||||
|
||||
this.playerCount = 0;
|
||||
this.activePageNo = 1;
|
||||
this.lastPageNo = 0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
setupAddPlayerList() {
|
||||
let self = this;
|
||||
|
||||
let xhr = new XMLHttpRequest(); //new로 생성.
|
||||
xhr.open('POST', './../server/user/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.list.loadPlayerListPage(self.activePageNo);
|
||||
self.listNavigator.updateNavigator(self.playerCount);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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/user/registered_player_list_page.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.listNavigator.updateNavigator(self.playerCount);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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/user/registered_player_list_page.php', true);
|
||||
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
||||
xhr.send("maestro_id=" + maestroID + "&playerName=" + 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.listNavigator.updateNavigator(self.playerCount);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// onClickPlayerListPage(pageNo) {
|
||||
// this.listNavigator.onClickPlayerListPage(pageNo);
|
||||
// }
|
||||
|
||||
onClickPlayerListPage(pageNo) {
|
||||
switch(pageNo) {
|
||||
case "first":
|
||||
this.activePageNo = 1;
|
||||
this.list.loadPlayerListPage(this.activePageNo);
|
||||
return;
|
||||
|
||||
case "prev":
|
||||
if(this.activePageNo > 1)
|
||||
this.activePageNo -= 1;
|
||||
this.list.loadPlayerListPage(this.activePageNo);
|
||||
return;
|
||||
|
||||
case "next":
|
||||
if(this.activePageNo < this.lastPageNo)
|
||||
this.activePageNo += 1;
|
||||
this.list.loadPlayerListPage(this.activePageNo);
|
||||
return;
|
||||
|
||||
case "last":
|
||||
this.list.loadPlayerListPage(this.lastPageNo);
|
||||
return;
|
||||
}
|
||||
|
||||
this.activePageNo = pageNo;
|
||||
this.list.loadPlayerListPage(this.activePageNo);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user