Fix: setupSearchPlayerList after delete search player list

This commit is contained in:
2018-07-04 11:05:17 +09:00
parent 4413f0de0b
commit 401d90e3f9
3 changed files with 148 additions and 130 deletions
+129 -9
View File
@@ -5,7 +5,7 @@
this.docList = docList;
this.docNav = docNav;
this.list = new PlayerList(this.docList);
this.list = new PlayerList(this.docList, this);
this.listNavigator = new PlayerListNavigator(this.docNav);
// console.log(this.list);
// console.log(this.listNavigator);
@@ -55,12 +55,60 @@
self.lastPageNo = Math.ceil( (self.playerCount + 1) / 10 );
self.activePageNo = 1;
self.list.loadPlayerListPage(self.activePageNo);
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/user/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;
@@ -154,8 +202,6 @@
self.lastPageNo = Math.ceil( (self.playerCount + 1) / 10 );
self.activePageNo = 1;
// self.list.loadPlayerListPage(self.activePageNo);
// self.listNavigator.updateNavigator(self.playerCount);
self.updateSearchPlayerListPage(playerName, 1);
}
}
@@ -217,28 +263,102 @@
switch(pageNo) {
case "first":
this.activePageNo = 1;
this.list.loadPlayerListPage(this.activePageNo);
self.loadAddPlayerListPage(self.activePageNo);
return;
case "prev":
if(this.activePageNo > 1)
this.activePageNo -= 1;
this.list.loadPlayerListPage(this.activePageNo);
self.loadAddPlayerListPage(self.activePageNo);
return;
case "next":
if(this.activePageNo < this.lastPageNo)
this.activePageNo += 1;
this.list.loadPlayerListPage(this.activePageNo);
self.loadAddPlayerListPage(self.activePageNo);
return;
case "last":
this.list.loadPlayerListPage(this.lastPageNo);
this.loadAddPlayerListPage(this.lastPageNo);
return;
}
this.activePageNo = pageNo;
this.list.loadPlayerListPage(this.activePageNo);
self.loadAddPlayerListPage(self.activePageNo);
}
editPlayer(inputButton) {
// console.log(inputButton);
let id = $(inputButton).siblings(".player_id");
// console.log(id);
let playerID = id.text();
console.log(playerID);
}
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/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(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;
}
}