Add: player list manager

This commit is contained in:
2018-07-04 08:48:36 +09:00
parent 8db6dd19ad
commit 8d9e48af39
8 changed files with 435 additions and 130 deletions
+22 -48
View File
@@ -1,13 +1,16 @@
let maestroID = -1;
let playerCount = 0;
let playerListPage = 0;
let lastPageNo = 0;
// let playerCount = 0;
// let playerListPage = 0;
// let lastPageNo = 0;
let addPlayerList;
let addPlayerListNavigator;
let addPlayerListManager;
let searchPlayerListManager;
let searchPlayerList;
let searchPlayerListNavigator;
// let addPlayerList;
// let addPlayerListNavigator;
// let searchPlayerList;
// let searchPlayerListNavigator;
let mouseAppList;
@@ -19,47 +22,6 @@ $(document).ready(function() {
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"];
loadPlayerListPage(1);
addPlayerListNavigator.addPlayerListPages(playerCount);
}
}
}
function tabClicked(tabNo) {
// hide and show tab
for(let i = 0; i < 4; i++) {
@@ -98,3 +60,15 @@ function tabClicked(tabNo) {
}
}
function onClickPlayerListPage(item, pageNo) {
let tagDiv = $(item).closest("div");
let tagDivIDName = tagDiv.prop("id");
// console.log(tagDivIDName);
if(tagDivIDName === "add_player_list_navigator")
addPlayerListManager.onClickPlayerListPage(pageNo);
else if(tagDivIDName === "search_player_list_navigator")
searchPlayerListManager.onClickPlayerListPage(pageNo);
}
+47 -40
View File
@@ -15,7 +15,10 @@ class PlayerList {
constructor(parent) {
let self = this;
this.listParent = parent;
console.log(parent);
// console.log(parent);
this.playerCount = 0;
this.playerListPage = 1;
let id_list = parent.find(".player_id");
// console.log(id_list);
@@ -136,50 +139,54 @@ class PlayerList {
}
}
}
}
loadPlayerListPage(pageNo) {
self = this;
this.playerListPage = pageNo;
function loadPlayerListPage(pageNo) {
playerListPage = pageNo;
let pageIndex = pageNo - 1;
let startNo = pageIndex * 10;
let endNo = pageIndex * 10 + 9;
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 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"]);
self.updatePlayerList(replyJSON["PlayerList"]);
self.playerCount = replyJSON["PlayerList"].length;
}
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"]);
}
}
}
+196
View File
@@ -0,0 +1,196 @@
class PlayerListManager {
constructor(docList, docNav) {
let self = this;
this.docList = docList;
this.docNav = docNav;
this.list = new PlayerList(this.docList);
this.listNavigator = new PlayerListNavigator(this.docNav);
// console.log(this.list);
// console.log(this.listNavigator);
this.playerCount = 0;
this.activePageNo = 1;
this.lastPageNo = 0;
}
setupAddPlayerList() {
let self = this;
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;
}
self.playerCount = replyJSON["Count"];
self.lastPageNo = Math.ceil( (self.playerCount + 1) / 10 );
self.activePageNo = 1;
self.list.loadPlayerListPage(self.activePageNo);
self.listNavigator.updateNavigator(self.playerCount);
}
}
}
updateAddPlayerListPage(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_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"]);
self.list.updatePlayerList(replyJSON["PlayerList"]);
self.playerCount = replyJSON["PlayerList"].length;
console.log(self.playerCount);
self.listNavigator.updateNavigator(self.playerCount);
}
}
}
updateSearchPlayerListPage(playerName, pageNo) {
let 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_page.php', true);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.send("maestro_id=" + maestroID + "&playerName=" + playerName + "&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"]);
self.list.updatePlayerList(replyJSON["PlayerList"]);
self.playerCount = replyJSON["PlayerList"].length;
self.listNavigator.updateNavigator(self.playerCount);
}
}
}
// onClickPlayerListPage(pageNo) {
// this.listNavigator.onClickPlayerListPage(pageNo);
// }
onClickPlayerListPage(pageNo) {
switch(pageNo) {
case "first":
this.activePageNo = 1;
this.list.loadPlayerListPage(this.activePageNo);
return;
case "prev":
if(this.activePageNo > 1)
this.activePageNo -= 1;
this.list.loadPlayerListPage(this.activePageNo);
return;
case "next":
if(this.activePageNo < this.lastPageNo)
this.activePageNo += 1;
this.list.loadPlayerListPage(this.activePageNo);
return;
case "last":
this.list.loadPlayerListPage(this.lastPageNo);
return;
}
this.activePageNo = pageNo;
this.list.loadPlayerListPage(this.activePageNo);
}
}
+31 -27
View File
@@ -4,48 +4,52 @@
let self = this;
this.pageNoArea = pageNoArea;
// console.log(parent);
this.activePageNo = 1;
this.lastPageNo = 1;
}
addPlayerListPages(playerCount) {
lastPageNo = Math.ceil( (playerCount + 1) / 10 );
updateNavigator(playerCount) {
this.lastPageNo = Math.ceil( (playerCount + 1) / 10 );
$(this.pageNoArea).empty();
for(let pageNo = 1; pageNo < lastPageNo + 1; pageNo++) {
for(let pageNo = 1; pageNo < this.lastPageNo + 1; pageNo++) {
$(this.pageNoArea).append(
"<a onClick='onClickPlayerListPage(" + pageNo + ")'> " + pageNo + " </a>"
"<a onClick='onClickPlayerListPage(this, " + pageNo + ")'> " + pageNo + " </a>"
);
}
}
}
onClickPlayerListPage(pageNo) {
switch(pageNo) {
case "first":
this.activePageNo = 1;
this.playerList.loadPlayerListPage(this.activePageNo);
return;
case "prev":
if(this.activePageNo > 1)
this.activePageNo -= 1;
this.playerList.loadPlayerListPage(this.activePageNo);
return;
case "next":
if(this.activePageNo < this.lastPageNo)
this.activePageNo += 1;
this.playerList.loadPlayerListPage(this.activePageNo);
return;
function onClickPlayerListPage(pageNo) {
switch(pageNo) {
case "first":
playerListPage = 1;
loadPlayerListPage(playerListPage);
return;
case "last":
this.playerList.loadPlayerListPage(this.lastPageNo);
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;
this.activePageNo = pageNo;
this.playerList.loadPlayerListPage(this.activePageNo);
}
loadPlayerListPage(pageNo);
}
+1
View File
@@ -13,6 +13,7 @@
<script type="text/javascript" src="./../js/maestro_main.js"></script>
<script type="text/javascript" src="./../js/player_list.js"></script>
<script type="text/javascript" src="./../js/player_list_navigator.js"></script>
<script type="text/javascript" src="./../js/player_list_manager.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#header").load("./../module/maestro_header.html");
+12 -8
View File
@@ -1,10 +1,14 @@
<script type="text/javascript">
$(document).ready(function() {
addPlayerList = new PlayerList($("#add_player_list"));
addPlayerListNavigator = new PlayerListNavigator($("#add_player_list_navigator > #page_no_area"));
addPlayerListManager = new PlayerListManager(
$("#add_player_list"),
$("#add_player_list_navigator > #page_no_area")
);
// addPlayerListNavigator = new PlayerListNavigator($("#add_player_list_navigator > #page_no_area"));
// addPlayerList = new PlayerList($("#add_player_list"), addPlayerListNavigator);
loadPlayerList();
addPlayerListNavigator.addPlayerListPages();
// addPlayerList.loadPlayerListPage(1);
addPlayerListManager.setupAddPlayerList();
});
function addPlayer() {
@@ -180,10 +184,10 @@ function addPlayer() {
</div>
<div id="add_player_list_navigator" class="player_list_navigator">
<span><a onClick="onClickPlayerListPage('first')"></a></span>
<span><a onClick="onClickPlayerListPage('prev')"> </a></span>
<span><a onClick="onClickPlayerListPage(this, 'first')"></a></span>
<span><a onClick="onClickPlayerListPage(this, 'prev')"> </a></span>
<span id="page_no_area"></span>
<span><a onClick="onClickPlayerListPage('next')"> </a></span>
<span><a onClick="onClickPlayerListPage('last')"></a></span>
<span><a onClick="onClickPlayerListPage(this, 'next')"> </a></span>
<span><a onClick="onClickPlayerListPage(this, 'last')"></a></span>
</div>
</span>
+55 -2
View File
@@ -1,8 +1,61 @@
<script type="text/javascript">
$(document).ready(function() {
searchPlayerList = new PlayerList($("#search_player_list"));
searchPlayerListNavigator = new PlayerListNavigator($("#search_player_list_navigator > #page_no_area"));
searchPlayerListManager = new PlayerListManager(
$("#search_player_list"),
$("#search_player_list_navigator > #page_no_area")
);
// searchPlayerList = new PlayerList($("#search_player_list"));
// searchPlayerListNavigator = new PlayerListNavigator($("#search_player_list_navigator > #page_no_area"));
searchPlayerListManager.updateSearchPlayerListPage(1);
});
function searchPlayer() {
// let maestroID = sessionStorage.getItem("maestroID");
let playerName = $("#search_name").val();
if(playerName.length === 0) {
$("#add_player_notice").val("학생 이름을 입력하세요.");
$("#add_player_name").focus();
}
let xhr = new XMLHttpRequest(); //new로 생성.
xhr.open('POST', './../server/user/search_player.php', true);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.send("maestro_id=" + maestroID + "&player_name=" + playerName);
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;
}
loadPlayerListPage(1);
}
}
}
</script>
+66
View File
@@ -0,0 +1,66 @@
<?php
header('Content-Type: application/json');
$maestroID = $_POST["maestro_id"];
$playerName = $_POST["player_name"];
$enterCode = $_POST["enter_code"];
/*
if(!is_numeric($enterCode)) {
send_error_code('생년월일이 숫자가 아닙니다. : '.$enterCode);
exit;
} else if(strlen($enterCode) != 6) {
send_error_code('6자리 숫자값을 정확히 입력하세요 : YYMMDD (예 : 120131) : '.$enterCode);
exit;
}
*/
include "./../setup/connect_db.php";
$result = hasPlayerName($maestroID, $playerName, $enterCode);
if($result !== null) {
send_error_message($replyJSON, "이미 등록된 학생과 입장 코드 정보입니다.");
// $db_conn->close();
exit;
}
addPlayer($maestroID, $playerName, $enterCode);
$result = hasPlayerName($maestroID, $playerName, $enterCode);
if($result === null) {
send_result_message($replyJSON, "fail");
exit;
} else {
send_result_message($replyJSON, "success");
exit;
}
// echo json_encode($replyJSON, JSON_UNESCAPED_UNICODE);
// $db_conn->close();
function hasPlayerName($maestroID, $playerName, $enterCode) {
global $db_conn;
$query = "SELECT UserID FROM moty_user WHERE MaestroID=? AND Name=? AND EnterCode=?";
$stmt = $db_conn->prepare($query);
$stmt->bind_param('iss', $maestroID, $playerName, $enterCode);
$stmt->execute();
$stmt->bind_result($userID);
// while($stmt->fetch())
$stmt->fetch();
$stmt->close();
// $replyJSON["UserID"] = $userID;
return $userID;
}
function addPlayer($maestroID, $playerName, $enterCode) {
global $db_conn;
$query = "INSERT INTO moty_user (MaestroID, Name, EnterCode) VALUES (?, ?, ?)";
$stmt = $db_conn->prepare($query);
$stmt->bind_param('iss', $maestroID, $playerName, $enterCode);
$stmt->execute();
}
?>