Fix: setupSearchPlayerList after delete search player list
This commit is contained in:
@@ -24,7 +24,9 @@ function tabClicked(tabNo) {
|
||||
// hide and show content
|
||||
switch(tabNo) {
|
||||
case 1:
|
||||
addPlayerListManager.setupAddPlayerList();
|
||||
$("#section_add_player").removeClass("hide");
|
||||
|
||||
$("#search").addClass("hide");
|
||||
$("#mouse_app_list").addClass("hide");
|
||||
$("#typing_app_list").addClass("hide");
|
||||
|
||||
+17
-121
@@ -12,15 +12,15 @@
|
||||
|
||||
class PlayerList {
|
||||
|
||||
constructor(parent) {
|
||||
constructor(tagDiv, parent) {
|
||||
let self = this;
|
||||
this.listParent = parent;
|
||||
// console.log(parent);
|
||||
this.parent = parent;
|
||||
// console.log(tagDiv);
|
||||
|
||||
this.playerCount = 0;
|
||||
this.playerListPage = 1;
|
||||
this.activePageNo = 1;
|
||||
|
||||
let id_list = parent.find(".player_id");
|
||||
let id_list = tagDiv.find(".player_id");
|
||||
// console.log(id_list);
|
||||
|
||||
this.listRows = new Array();
|
||||
@@ -36,11 +36,11 @@ class PlayerList {
|
||||
this.disableItem(this.listRows[i]);
|
||||
|
||||
$(id_list[i]).siblings(".player_edit").click(function() {
|
||||
self.editPlayer(this);
|
||||
parent.editPlayer(this);
|
||||
})
|
||||
|
||||
$(id_list[i]).siblings(".player_delete").click(function() {
|
||||
self.deletePlayer(this);
|
||||
parent.deletePlayer(this);
|
||||
})
|
||||
// console.log(this.listRows[i].playerName.val());
|
||||
// console.log(this.listRows[i]);
|
||||
@@ -55,136 +55,32 @@ class PlayerList {
|
||||
$(item.deleteButton).prop("disabled", true);
|
||||
}
|
||||
|
||||
enableItem(item) {
|
||||
$(item.playerName).prop("disabled", false);
|
||||
$(item.enterCode).prop("disabled", false);
|
||||
$(item.editButton).prop("disabled", false);
|
||||
$(item.deleteButton).prop("disabled", false);
|
||||
}
|
||||
|
||||
updatePlayerList(jsonData) {
|
||||
// console.log(jsonData);
|
||||
|
||||
for(let i = 0; i < 10; i++) {
|
||||
// $(this.listRows[i].playerID).empty();
|
||||
this.disableItem(this.listRows[i]);
|
||||
$(this.listRows[i].playerID).empty();
|
||||
|
||||
if(i < jsonData.length) {
|
||||
$(this.listRows[i].playerID).append(jsonData[i]["UserID"]);
|
||||
|
||||
$(this.listRows[i].playerName).val(jsonData[i]["Name"]);
|
||||
$(this.listRows[i].playerName).prop("disabled", false);
|
||||
|
||||
$(this.listRows[i].enterCode).val(jsonData[i]["EnterCode"]);
|
||||
$(this.listRows[i].enterCode).prop("disabled", false);
|
||||
|
||||
$(this.listRows[i].editButton).prop("disabled", false);
|
||||
$(this.listRows[i].deleteButton).prop("disabled", false);
|
||||
this.enableItem(this.listRows[i]);
|
||||
} else {
|
||||
$(this.listRows[i].playerName).val("");
|
||||
// $(this.listRows[i].playerName).prop("disabled", true);
|
||||
|
||||
$(this.listRows[i].enterCode).val("");
|
||||
// $(this.listRows[i].enterCode).prop("disabled", true);
|
||||
|
||||
// $(this.listRows[i].editButton).prop("disabled", true);
|
||||
// $(this.listRows[i].deleteButton).prop("disabled", true);
|
||||
this.disableItem(this.listRows[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
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");
|
||||
self.loadPlayerListPage(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
loadPlayerListPage(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.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.updatePlayerList(replyJSON["PlayerList"]);
|
||||
|
||||
self.playerCount = replyJSON["PlayerList"].length;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user