Add: player list navigator
This commit is contained in:
+5
-107
@@ -4,7 +4,10 @@ let playerListPage = 0;
|
||||
let lastPageNo = 0;
|
||||
|
||||
let addPlayerList;
|
||||
let searchPlayerList
|
||||
let searchPlayerList;
|
||||
|
||||
let addPlayerListNavigator;
|
||||
let searchPlayerListNavigator;
|
||||
|
||||
|
||||
$(document).ready(function() {
|
||||
@@ -45,113 +48,9 @@ function loadPlayerList() {
|
||||
}
|
||||
|
||||
playerCount = replyJSON["Count"];
|
||||
lastPageNo = Math.floor( (playerCount + 1) / 10 );
|
||||
|
||||
loadPlayerListPage(1);
|
||||
addPlayerListPages();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function addPlayerListPages() {
|
||||
$("#player_list_pages").empty();
|
||||
|
||||
for(let pageNo = 1; pageNo < lastPageNo + 1; pageNo++) {
|
||||
$("#player_list_pages").append(
|
||||
"<a onClick='onClickPlayerListPage(" + pageNo + ")'> " + pageNo + " </a>"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function onClickPlayerListPage(pageNo) {
|
||||
console.log(pageNo);
|
||||
|
||||
switch(pageNo) {
|
||||
case "first":
|
||||
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;
|
||||
}
|
||||
|
||||
loadPlayerListPage(pageNo);
|
||||
}
|
||||
|
||||
function loadPlayerListPage(pageNo) {
|
||||
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"]);
|
||||
// updatePlayerListPage(replyJSON["PlayerList"]);
|
||||
addPlayerList.updatePlayerList(replyJSON["PlayerList"]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function updatePlayerList(playerList) {
|
||||
for(let i = 0; i < 10; i++) {
|
||||
let listIndex = i + 1; // index 0 : list title
|
||||
|
||||
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("");
|
||||
addPlayerListNavigator.addPlayerListPages(playerCount);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -239,7 +138,6 @@ function addPlayer() {
|
||||
return;
|
||||
}
|
||||
|
||||
console.log("update player list");
|
||||
loadPlayerListPage(1);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user