let maestroID = -1; let playerCount = 0; let playerListPage = 0; let lastPageNo = 0; let addPlayerList; let searchPlayerList $(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 ); loadPlayerListPage(1); addPlayerListPages(); } } } function addPlayerListPages() { $("#player_list_pages").empty(); for(let pageNo = 1; pageNo < lastPageNo + 1; pageNo++) { $("#player_list_pages").append( " " + pageNo + " " ); } } 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"]); } } } function updatePlayerListPage(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(""); } } } function tabClicked(tabNo) { // hide and show tab 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"); // hide and show content switch(tabNo) { case 1: $("#section_add_player").removeClass("hide"); $("#search").addClass("hide"); $("#mouse_app_list").addClass("hide"); $("#typing_app_list").addClass("hide"); break; case 2: $("#section_add_player").addClass("hide"); $("#search").removeClass("hide"); $("#mouse_app_list").addClass("hide"); $("#typing_app_list").addClass("hide"); break; case 3: $("#section_add_player").addClass("hide"); $("#search").addClass("hide"); $("#mouse_app_list").removeClass("hide"); $("#typing_app_list").addClass("hide"); break; case 4: $("#section_add_player").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); } } } function deletePlayer(id) { }