Add: maestro_section_add_player
This commit is contained in:
@@ -0,0 +1,247 @@
|
||||
let maestroID = -1;
|
||||
let playerCount = 0;
|
||||
let playerListPage = 0;
|
||||
let lastPageNo = 0;
|
||||
|
||||
|
||||
$(document).ready(function() {
|
||||
maestroID = sessionStorage.getItem("maestroID");
|
||||
console.log("maestroID : " + maestroID);
|
||||
});
|
||||
|
||||
function loadPlayerList() {
|
||||
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;
|
||||
}
|
||||
|
||||
playerCount = replyJSON["Count"];
|
||||
lastPageNo = Math.floor( (playerCount + 1) / 10 );
|
||||
|
||||
console.log("registered player count : " + playerCount);
|
||||
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":
|
||||
if(playerListPage < lastPageNo)
|
||||
playerListPage += 1;
|
||||
|
||||
loadPlayerListPage(playerListPage);
|
||||
return;
|
||||
case "last":
|
||||
loadPlayerListPage(lastPageNo);
|
||||
return;
|
||||
}
|
||||
|
||||
loadPlayerListPage(pageNo);
|
||||
}
|
||||
|
||||
function loadPlayerListPage(pageNo) {
|
||||
let pageIndex = pageNo - 1;
|
||||
let startNo = pageIndex * 10;
|
||||
let endNo = pageIndex * 10 + 9;
|
||||
|
||||
console.log("startNo : " + startNo);
|
||||
console.log("endNo : " + endNo);
|
||||
|
||||
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"]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function addPlayerListTitle() {
|
||||
$("#registered_player_list").empty();
|
||||
|
||||
$("#registered_player_list").append(
|
||||
'<li class="registered_player_list_name">이름</li><li class="registered_player_list_entercode">입장 코드</li>'
|
||||
);
|
||||
}
|
||||
|
||||
function updatePlayerListPage(playerList) {
|
||||
$("#registered_player_list").empty();
|
||||
addPlayerListTitle();
|
||||
|
||||
for(let i = 0; i < playerList.length; i++) {
|
||||
$("#registered_player_list").append(
|
||||
"<li>"
|
||||
+ "" + playerList[i]["UserID"] + ""
|
||||
+ "<input type='text' value='" + playerList[i]["Name"] + "' class='registered_player_list_name'>"
|
||||
+ "<input type='text' value='" + playerList[i]["EnterCode"] + "' class='registered_player_list_entercode'>"
|
||||
+ "<input type='button' value='수정'>"
|
||||
+ "</li>"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function tabClicked(tabNo) {
|
||||
for(let i = 0; i < 4; i++) {
|
||||
$("#page-tabs li").filter(":eq(" + i + ")").removeClass("activated");
|
||||
}
|
||||
|
||||
let tabIndex = tabNo - 1;
|
||||
$("#page-tabs li").filter(":eq(" + tabIndex + ")").addClass("activated");
|
||||
|
||||
switch(tabNo) {
|
||||
case 1:
|
||||
$(".player_list").removeClass("hide");
|
||||
$(".search").addClass("hide");
|
||||
$(".mouse_app_list").addClass("hide");
|
||||
$(".typing_app_list").addClass("hide");
|
||||
break;
|
||||
case 2:
|
||||
$(".player_list").addClass("hide");
|
||||
$(".search").removeClass("hide");
|
||||
$(".mouse_app_list").addClass("hide");
|
||||
$(".typing_app_list").addClass("hide");
|
||||
break;
|
||||
case 3:
|
||||
$(".player_list").addClass("hide");
|
||||
$(".search").addClass("hide");
|
||||
$(".mouse_app_list").removeClass("hide");
|
||||
$(".typing_app_list").addClass("hide");
|
||||
break;
|
||||
case 4:
|
||||
$(".player_list").addClass("hide");
|
||||
$(".search").addClass("hide");
|
||||
$(".mouse_app_list").addClass("hide");
|
||||
$(".typing_app_list").removeClass("hide");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
function addPlayer() {
|
||||
// let maestroID = sessionStorage.getItem("maestroID");
|
||||
let playerName = $("#add_player_name").val();
|
||||
let enterCode = $("#add_player_enter_code").val();
|
||||
|
||||
if(playerName.length === 0) {
|
||||
$("#add_player_notice").val("학생 이름을 입력하세요.");
|
||||
$("#add_player_name").focus();
|
||||
} else if(enterCode.length === 0) {
|
||||
$("#add_player_notice").val("엔터 코드를 입력하세요.");
|
||||
$("#add_player_enter_code").focus();
|
||||
}
|
||||
|
||||
let xhr = new XMLHttpRequest(); //new로 생성.
|
||||
xhr.open('POST', './../server/user/add_player.php', true);
|
||||
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
||||
xhr.send("maestro_id=" + maestroID + "&player_name=" + playerName + "&enter_code=" + enterCode);
|
||||
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");
|
||||
loadPlayerListPage(1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user