Fix: maestro html ES6 -> ES5

This commit is contained in:
2018-09-15 13:51:48 +09:00
parent 53e3dbb3bc
commit 753325d84a
9 changed files with 585 additions and 613 deletions
+64 -69
View File
@@ -1,88 +1,83 @@
class AccountValidator { function AccountValidator() {
this.patternMaestroID = /^[A-Za-z가-힣]{1}[A-Za-z0-9가-힣]{2,19}$/;
this.patternMaestroPW = /^[A-Za-z0-9]{4,16}$/;
constructor() { this.patternPlayerID = /^[A-Za-z0-9가-힣-_]{1,8}$/;
this.patternMaestroID = /^[A-Za-z가-힣]{1}[A-Za-z0-9가-힣]{2,19}$/; this.patternPlayerPW = /^[0-9]{4,6}$/;
this.patternMaestroPW = /^[A-Za-z0-9]{4,16}$/; }
this.patternPlayerID = /^[A-Za-z0-9가-힣-_]{1,8}$/; // maestro
this.patternPlayerPW = /^[0-9]{4,6}$/; AccountValidator.prototype.isValidMaestroID = function(textID) {
} if(!this.patternMaestroID.test(textID))
return false;
// maestro return true;
isValidMaestroID(textID) { }
if(!this.patternMaestroID.test(textID))
return false;
return true; AccountValidator.prototype.messageForInvalidMaestroID = function(textID) {
} if(textID.length < AccountValidator.MAESTRO_ID_LENGTH_MINIMUM)
return "마에스트로 계정명은 " + AccountValidator.MAESTRO_ID_LENGTH_MINIMUM + "글자 이상이어야 합니다.";
messageForInvalidMaestroID(textID) { else if(textID.length > AccountValidator.MAESTRO_ID_LENGTH_MAXIMUM)
if(textID.length < AccountValidator.MAESTRO_ID_LENGTH_MINIMUM) return "마에스트로 계정명은 " + AccountValidator.MAESTRO_ID_LENGTH_MAXIMUM + "글자 이하이어야 합니다.";
return "마에스트로 계정명은 " + AccountValidator.MAESTRO_ID_LENGTH_MINIMUM + "글자 이상이어야 합니다."; else if(!(/^[A-Za-z]/.test(textID)))
else if(textID.length > AccountValidator.MAESTRO_ID_LENGTH_MAXIMUM) return "마에스트로 계정명은 알파벳으로 시작해야 합니다.";
return "마에스트로 계정명은 " + AccountValidator.MAESTRO_ID_LENGTH_MAXIMUM + "글자 이하이어야 합니다."; else if((/[^\w]/g).test(textID))
else if(!(/^[A-Za-z]/.test(textID))) return "마에스트로 계정명은 알파벳과 숫자로만 적어주세요.";
return "마에스트로 계정명은 알파벳으로 시작해야 합니다."; }
else if((/[^\w]/g).test(textID))
return "마에스트로 계정명은 알파벳과 숫자로만 적어주세요.";
}
isValidMaestroPW(textPW) { AccountValidator.prototype.isValidMaestroPW = function(textPW) {
if(!this.patternMaestroPW.test(textPW)) if(!this.patternMaestroPW.test(textPW))
return false; return false;
return true; return true;
} }
messageForInvalidMaestroPW(textPW) { AccountValidator.prototype.messageForInvalidMaestroPW = function(textPW) {
console.log(textPW); console.log(textPW);
if(textPW.length < AccountValidator.MAESTRO_PW_LENGTH_MINIMUM) if(textPW.length < AccountValidator.MAESTRO_PW_LENGTH_MINIMUM)
return "마에스트로의 암호는 " + AccountValidator.MAESTRO_PW_LENGTH_MINIMUM + "글자 이상이어야 합니다."; return "마에스트로의 암호는 " + AccountValidator.MAESTRO_PW_LENGTH_MINIMUM + "글자 이상이어야 합니다.";
else if(textPW.length > AccountValidator.MAESTRO_PW_LENGTH_MAXIMUM) else if(textPW.length > AccountValidator.MAESTRO_PW_LENGTH_MAXIMUM)
return "마에스트로의 암호는 " + AccountValidator.MAESTRO_PW_LENGTH_MAXIMUM + "글자 이하이어야 합니다."; return "마에스트로의 암호는 " + AccountValidator.MAESTRO_PW_LENGTH_MAXIMUM + "글자 이하이어야 합니다.";
else if((/[^\w]/g).test(textPW)) else if((/[^\w]/g).test(textPW))
return "마에스트로의 암호는 알파벳과 숫자로만 적어주세요."; return "마에스트로의 암호는 알파벳과 숫자로만 적어주세요.";
else else
return "???"; return "???";
} }
// player // player
isValidPlayerID(textID) { AccountValidator.prototype.isValidPlayerID = function(textID) {
if(!this.patternPlayerID.test(textID)) if(!this.patternPlayerID.test(textID))
return false; return false;
return true; return true;
} }
messageForInvalidPlayerID(textID) { AccountValidator.prototype.messageForInvalidPlayerID = function(textID) {
if(textID.length < Number(AccountValidator.Player_ID_LENGTH_MINIMUM)) if(textID.length < Number(AccountValidator.Player_ID_LENGTH_MINIMUM))
return "학생 이름은 " + AccountValidator.Player_ID_LENGTH_MINIMUM + "글자 이상이어야 합니다."; return "학생 이름은 " + AccountValidator.Player_ID_LENGTH_MINIMUM + "글자 이상이어야 합니다.";
else if(textID.length > Number(AccountValidator.PLAYER_ID_LENGTH_MAXIMUM)) else if(textID.length > Number(AccountValidator.PLAYER_ID_LENGTH_MAXIMUM))
return "학생 이름은 " + AccountValidator.PLAYER_ID_LENGTH_MAXIMUM + "글자 이하이어야 합니다."; return "학생 이름은 " + AccountValidator.PLAYER_ID_LENGTH_MAXIMUM + "글자 이하이어야 합니다.";
else // if((/[^A-Za-z0-9가-힣-_]/g).test(textID)) else // if((/[^A-Za-z0-9가-힣-_]/g).test(textID))
return "학생 이름 입력 가능한 문자는 [ 한글, 알파벳, 숫자, -, _ ] 입니다."; return "학생 이름 입력 가능한 문자는 [ 한글, 알파벳, 숫자, -, _ ] 입니다.";
} }
isValidPlayerPW(textPW) { AccountValidator.prototype.isValidPlayerPW = function(textPW) {
if(!this.patternPlayerPW.test(textPW)) if(!this.patternPlayerPW.test(textPW))
return false; return false;
return true;
}
messageForInvalidPlayerPW(textPW) {
if(textPW.length < Number(AccountValidator.PLAYER_PW_LENGTH_MINIMUM))
return "학생 입장 번호는 " + AccountValidator.PLAYER_PW_LENGTH_MINIMUM + "글자 이상의 숫자로 입력해 주세요.";
else if(textPW.length > Number(AccountValidator.PLAYER_PW_LENGTH_MAXIMUM))
return "학생 입장 번호는 " + AccountValidator.PLAYER_PW_LENGTH_MAXIMUM + "글자 이하의 숫자로 입력해 주세요.";
else
return "학생 입장 번호는 4~6자리 숫자로 입력해 주세요.";
}
return true;
}
AccountValidator.prototype.messageForInvalidPlayerPW = function(textPW) {
if(textPW.length < Number(AccountValidator.PLAYER_PW_LENGTH_MINIMUM))
return "학생 입장 번호는 " + AccountValidator.PLAYER_PW_LENGTH_MINIMUM + "글자 이상의 숫자로 입력해 주세요.";
else if(textPW.length > Number(AccountValidator.PLAYER_PW_LENGTH_MAXIMUM))
return "학생 입장 번호는 " + AccountValidator.PLAYER_PW_LENGTH_MAXIMUM + "글자 이하의 숫자로 입력해 주세요.";
else
return "학생 입장 번호는 4~6자리 숫자로 입력해 주세요.";
} }
+56 -60
View File
@@ -1,61 +1,57 @@
class MaestroInfo { function MaestroInfo() {
this.maestroID = sessionStorage.getItem("maestroID");
constructor() { this.maestroName = "";
this.maestroID = sessionStorage.getItem("maestroID"); this.accountType = 0;
this.maestroName = ""; this.playerCount = 0;
this.accountType = 0;
this.playerCount = 0;
}
loadMaestroInfo(onSuccess, onFail) {
let self = this;
sendRequestServer( //url, sendParams, onSuccess, onFail, isDebugMode);
"./../server/maestro/maestro_info.php",
"maestro_id=" + this.maestroID,
function(jsonData) {
self.maestroName = jsonData["name"];
self.accountType = jsonData["accountType"];
self.playerCount = jsonData["playerCount"];
onSuccess();
},
function(errorMessage, errorCode) {
onFail(errorMessage, errorCode);
}
);
}
getMaxPlayerCount() {
switch(this.accountType) {
case 0:
case 1:
case 100:
case 101:
return 20;
case 2:
return 50;
case 3:
return 100;
case 4:
return 500;
case 5:
return 1000;
default:
return 0;
}
}
getRegisteredPlayerCount() {
return this.playerCount;
}
} }
MaestroInfo.prototype.loadMaestroInfo = function(onSuccess, onFail) {
var self = this;
sendRequestServer( //url, sendParams, onSuccess, onFail, isDebugMode);
"./../server/maestro/maestro_info.php",
"maestro_id=" + this.maestroID,
function(jsonData) {
self.maestroName = jsonData["name"];
self.accountType = jsonData["accountType"];
self.playerCount = jsonData["playerCount"];
onSuccess();
},
function(errorMessage, errorCode) {
onFail(errorMessage, errorCode);
}
);
}
MaestroInfo.prototype.getMaxPlayerCount = function() {
switch(this.accountType) {
case 0:
case 1:
case 100:
case 101:
return 20;
case 2:
return 50;
case 3:
return 100;
case 4:
return 500;
case 5:
return 1000;
default:
return 0;
}
}
MaestroInfo.prototype.getRegisteredPlayerCount = function() {
return this.playerCount;
}
+5 -5
View File
@@ -1,7 +1,7 @@
let addPlayerListManager; var addPlayerListManager;
let searchPlayerListManager; var searchPlayerListManager;
let mouseAppList; var mouseAppList;
let typingAppList; var typingAppList;
let accountValidator = new AccountValidator(); var accountValidator = new AccountValidator();
+6 -6
View File
@@ -1,4 +1,4 @@
let maestroID = -1; var maestroID = -1;
$(document).ready(function() { $(document).ready(function() {
loadMaestroID(); loadMaestroID();
@@ -21,7 +21,7 @@ function saveMaestroID(maestroID) {
} }
function getParentDirectory(url) { function getParentDirectory(url) {
let directories = url.split("/"); var directories = url.split("/");
if(directories.length < 2) if(directories.length < 2)
return ""; return "";
@@ -29,7 +29,7 @@ function getParentDirectory(url) {
} }
function getPage(url) { function getPage(url) {
let directories = url.split("/"); var directories = url.split("/");
if(directories.length < 1) if(directories.length < 1)
return ""; return "";
@@ -37,7 +37,7 @@ function getPage(url) {
} }
function goHome() { function goHome() {
let url = window.location.href; var url = window.location.href;
if(getParentDirectory(url) === "maestro") { if(getParentDirectory(url) === "maestro") {
if(getPage(url) !== "main_menu.html") if(getPage(url) !== "main_menu.html")
@@ -66,12 +66,12 @@ function logout() {
function showErrorMessage(message, type) { function showErrorMessage(message, type) {
console.log("showErrorMessage : " + message); console.log("showErrorMessage : " + message);
let messageBox = $("#message_box"); var messageBox = $("#message_box");
if(!messageBox) if(!messageBox)
return; return;
let alertType = ""; var alertType = "";
switch(type) { switch(type) {
case "success": case "success":
alertType = "alert-success"; alertType = "alert-success";
+15 -20
View File
@@ -1,25 +1,20 @@
class MouseAppList { function MouseAppList(pageNoArea) {
var self = this;
constructor(pageNoArea) { this.pageNoArea = pageNoArea;
let self = this; // console.log(parent);
this.pageNoArea = pageNoArea;
// console.log(parent);
}
addPlayerListPages(playerCount) {
lastPageNo = Math.ceil( (playerCount + 1) / 10 );
$(this.pageNoArea).empty();
for(let pageNo = 1; pageNo < lastPageNo + 1; pageNo++) {
$(this.pageNoArea).append(
"<a onClick='onClickPlayerListPage(" + pageNo + ")'> " + pageNo + " </a>"
);
}
}
} }
MouseAppList.prototype.addPlayerListPages = function(playerCount) {
lastPageNo = Math.ceil( (playerCount + 1) / 10 );
$(this.pageNoArea).empty();
for(var pageNo = 1; pageNo < lastPageNo + 1; pageNo++) {
$(this.pageNoArea).append(
"<a onClick='onClickPlayerListPage(" + pageNo + ")'> " + pageNo + " </a>"
);
}
}
function onClickPlayerListPage(pageNo) { function onClickPlayerListPage(pageNo) {
+81 -88
View File
@@ -1,101 +1,94 @@
class PlayerListRow { function PlayerListRow(playerID, playerName, enterCode, editButton, deleteButton) {
this.playerID = playerID;
constructor(playerID, playerName, enterCode, editButton, deleteButton) { this.playerName = playerName;
this.playerID = playerID; this.enterCode = enterCode;
this.playerName = playerName; this.editButton = editButton;
this.enterCode = enterCode; this.deleteButton = deleteButton;
this.editButton = editButton;
this.deleteButton = deleteButton;
}
} }
class PlayerList {
constructor(tagDiv, playerListManager) { function PlayerList(tagDiv, playerListManager) {
let self = this; var self = this;
this.playerListManager = playerListManager; this.playerListManager = playerListManager;
// console.log(tagDiv); // console.log(tagDiv);
// console.log(playerListManager); // console.log(playerListManager);
this.playerCount = 0; this.playerCount = 0;
this.activePageNo = 1; this.activePageNo = 1;
// let id_list = tagDiv.find(".player_id"); // var id_list = tagDiv.find(".player_id");
let id_list = tagDiv.find(".player-list"); var id_list = tagDiv.find(".player-list");
// console.log(id_list); // console.log(id_list);
this.listRows = new Array(); this.listRows = new Array();
for(let i = 0; i < id_list.length; i++) { for(var i = 0; i < id_list.length; i++) {
this.listRows[i] = new PlayerListRow( this.listRows[i] = new PlayerListRow(
id_list[i].getElementsByClassName("player_id"), id_list[i].getElementsByClassName("player_id"),
id_list[i].getElementsByClassName("player_name"), id_list[i].getElementsByClassName("player_name"),
id_list[i].getElementsByClassName("player_entercode"), id_list[i].getElementsByClassName("player_entercode"),
id_list[i].getElementsByClassName("player_edit"), id_list[i].getElementsByClassName("player_edit"),
id_list[i].getElementsByClassName("player_delete") id_list[i].getElementsByClassName("player_delete")
); );
$(this.listRows[i].editButton).click(function() { $(this.listRows[i].editButton).click(function() {
playerListManager.editPlayer(this); playerListManager.editPlayer(this);
}) })
$(this.listRows[i].deleteButton).click(function() { $(this.listRows[i].deleteButton).click(function() {
playerListManager.deletePlayer(this); playerListManager.deletePlayer(this);
}) })
// console.log(this.listRows[i]); // console.log(this.listRows[i]);
// console.log(this.listRows[i].playerName.val()); // console.log(this.listRows[i].playerName.val());
this.disableItem(this.listRows[i]);
}
}
PlayerList.prototype.disableItem = function(item) {
$(item.playerID).empty();
$(item.playerName).prop("disabled", true);
$(item.enterCode).prop("disabled", true);
// $(item.playerName).prop("readonly", true);
// $(item.enterCode).prop("readonly", true);
$(item.editButton).prop("disabled", true);
$(item.deleteButton).prop("disabled", true);
}
PlayerList.prototype.enableItem = function(item) {
$(item.playerName).prop("disabled", false);
$(item.enterCode).prop("disabled", false);
// $(item.playerName).prop("readonly", false);
// $(item.enterCode).prop("readonly", false);
$(item.editButton).prop("disabled", false);
$(item.deleteButton).prop("disabled", false);
}
PlayerList.prototype.updatePlayerList = function(jsonData) {
if(jsonData === null) {
for(var i = 0; i < 10; i++) {
$(this.listRows[i].playerName).val("");
$(this.listRows[i].enterCode).val("");
this.disableItem(this.listRows[i]);
}
return;
}
for(var i = 0; i < 10; i++) {
$(this.listRows[i].playerID).empty();
if(i < jsonData.length) {
$(this.listRows[i].playerID).append(jsonData[i]["playerID"]);
$(this.listRows[i].playerName).val(jsonData[i]["playerName"]);
$(this.listRows[i].enterCode).val(jsonData[i]["enterCode"]);
this.enableItem(this.listRows[i]);
} else {
$(this.listRows[i].playerName).val("");
$(this.listRows[i].enterCode).val("");
this.disableItem(this.listRows[i]); this.disableItem(this.listRows[i]);
} }
} }
disableItem(item) {
$(item.playerID).empty();
$(item.playerName).prop("disabled", true);
$(item.enterCode).prop("disabled", true);
// $(item.playerName).prop("readonly", true);
// $(item.enterCode).prop("readonly", true);
$(item.editButton).prop("disabled", true);
$(item.deleteButton).prop("disabled", true);
}
enableItem(item) {
$(item.playerName).prop("disabled", false);
$(item.enterCode).prop("disabled", false);
// $(item.playerName).prop("readonly", false);
// $(item.enterCode).prop("readonly", false);
$(item.editButton).prop("disabled", false);
$(item.deleteButton).prop("disabled", false);
}
updatePlayerList(jsonData) {
if(jsonData === null) {
for(let i = 0; i < 10; i++) {
$(this.listRows[i].playerName).val("");
$(this.listRows[i].enterCode).val("");
this.disableItem(this.listRows[i]);
}
return;
}
for(let i = 0; i < 10; i++) {
$(this.listRows[i].playerID).empty();
if(i < jsonData.length) {
$(this.listRows[i].playerID).append(jsonData[i]["playerID"]);
$(this.listRows[i].playerName).val(jsonData[i]["playerName"]);
$(this.listRows[i].enterCode).val(jsonData[i]["enterCode"]);
this.enableItem(this.listRows[i]);
} else {
$(this.listRows[i].playerName).val("");
$(this.listRows[i].enterCode).val("");
this.disableItem(this.listRows[i]);
}
}
}
} }
+221 -224
View File
@@ -1,237 +1,234 @@
class PlayerListManager { function PlayerListManager(docList, docNav) {
var self = this;
this.docList = docList;
this.docNav = docNav;
this.playerListID = $(docList).attr("id");
constructor(docList, docNav) { this.list = new PlayerList(this.docList, this);
let self = this; this.list.updatePlayerList(null);
this.docList = docList; this.listNavigator = new PlayerListNavigator(this.docNav, this);
this.docNav = docNav;
this.playerListID = $(docList).attr("id");
this.list = new PlayerList(this.docList, this); this.playerCount = 0;
this.list.updatePlayerList(null); this.activePageNo = 1;
this.listNavigator = new PlayerListNavigator(this.docNav, this); this.lastPageNo = 0;
this.playerCount = 0; this.searchPlayerName = "";
this.activePageNo = 1; }
this.lastPageNo = 0;
this.searchPlayerName = "";
}
setupAddPlayerList() { PlayerListManager.prototype.setupAddPlayerList = function() {
let self = this; var self = this;
sendRequestServer( //url, sendParams, onSuccess, onFail, isDebugMode); sendRequestServer( //url, sendParams, onSuccess, onFail, isDebugMode);
"./../server/player/registered_player_count.php", "./../server/player/registered_player_count.php",
"maestro_id=" + maestroID, "maestro_id=" + maestroID,
function(jsonData) { function(jsonData) {
self.playerCount = jsonData["playerCount"]; self.playerCount = jsonData["playerCount"];
self.lastPageNo = Math.ceil( (self.playerCount + 1) / 10 ); self.lastPageNo = Math.ceil( (self.playerCount + 1) / 10 );
self.activePageNo = 1; self.activePageNo = 1;
self.loadAddPlayerListPage(self.activePageNo); self.loadAddPlayerListPage(self.activePageNo);
self.listNavigator.updateNavigator(self.activePageNo, self.lastPageNo); self.listNavigator.updateNavigator(self.activePageNo, self.lastPageNo);
}, },
function(errorMessage, errorCode) { function(errorMessage, errorCode) {
showErrorMessage(errorMessage, "error"); showErrorMessage(errorMessage, "error");
}
);
}
loadAddPlayerListPage(pageNo) {
let self = this;
this.activePageNo = pageNo;
let pageIndex = pageNo - 1;
let startNo = pageIndex * 10;
let endNo = pageIndex * 10 + 9;
sendRequestServer( //url, sendParams, onSuccess, onFail, isDebugMode);
"./../server/player/registered_player_list.php",
"maestro_id=" + maestroID + "&start_no=" + startNo + "&end_no=" + endNo,
function(jsonData) {
self.playerCount = jsonData["playerList"].length;
self.list.updatePlayerList(jsonData["playerList"]);
},
function(errorMessage, errorCode) {
showErrorMessage(errorMessage, "error");
}
);
}
updateAddPlayerListPage(pageNo) {
let self = this;
this.playerListPage = pageNo;
let pageIndex = pageNo - 1;
let startNo = pageIndex * 10;
let endNo = pageIndex * 10 + 9;
sendRequestServer( //url, sendParams, onSuccess, onFail, isDebugMode);
"./../server/player/registered_player_list.php",
"maestro_id=" + maestroID + "&start_no=" + startNo + "&end_no=" + endNo,
function(jsonData) {
self.playerCount = jsonData["playerList"].length;
self.list.updatePlayerList(jsonData["playerList"]);
self.listNavigator.updateNavigator(self.activePageNo, self.lastPageNo);
},
function(errorMessage, errorCode) {
showErrorMessage(errorMessage, "error");
}
);
}
setupSearchPlayerList(playerName) {
let self = this;
this.searchPlayerName = playerName;
sendRequestServer( //url, sendParams, onSuccess, onFail, isDebugMode);
"./../server/player/search_player_count.php",
"maestro_id=" + maestroID + "&player_name=" + this.searchPlayerName,
function(jsonData) {
self.playerCount = jsonData["playerCount"];
self.lastPageNo = Math.ceil( (self.playerCount + 1) / 10 );
self.activePageNo = 1;
self.updateSearchPlayerListPage(this.searchPlayerName, 1);
if(self.playerCount === 0)
showErrorMessage(this.searchPlayerName + " : 검색 결과가 없습니다.", "info");
},
function(errorMessage, errorCode) {
showErrorMessage(errorMessage, "error");
}
);
}
updateSearchPlayerListPage(playerName, pageNo) {
let self = this;
this.playerListPage = pageNo;
let pageIndex = pageNo - 1;
let startNo = pageIndex * 10;
let endNo = pageIndex * 10 + 9;
sendRequestServer( //url, sendParams, onSuccess, onFail, isDebugMode);
"./../server/player/search_player_list.php",
"maestro_id=" + maestroID + "&player_name=" + playerName + "&start_no=" + startNo + "&end_no=" + endNo,
function(jsonData) {
self.playerCount = jsonData["playerList"].length;
self.list.updatePlayerList(jsonData["playerList"]);
self.listNavigator.updateNavigator(self.activePageNo, self.lastPageNo);
},
function(errorMessage, errorCode) {
showErrorMessage(errorMessage, "error");
}
);
}
editPlayer(inputButton) {
let self = this;
console.log(inputButton);
// let clickedObjectID = this.getClickedObjectID(inputButton);
let id = $(inputButton).siblings(".player_id");
let playerID = id.text();
// console.log(playerID);
let name = $(inputButton).siblings(".player_name");
let playerName = name.val();
// console.log(playerName);
let enterCode = $(inputButton).siblings(".player_entercode");
let playerEnterCode = enterCode.val();
// console.log(playerEnterCode);
sendRequestServer( //url, sendParams, onSuccess, onFail, isDebugMode);
"./../server/player/edit_player.php",
"maestro_id=" + maestroID + "&player_id=" + playerID + "&player_name=" + playerName + "&enter_code=" + playerEnterCode,
function(jsonData) {
// console.log(jsonData);
if(this.playerListID === "add_player_list") {
self.setupAddPlayerList();
} else if(this.playerListID === "search_player_list") {
self.setupSearchPlayerList(this.searchPlayerName);
}
showErrorMessage("학생 데이터가 [ " + playerName + " / " + playerEnterCode + " ] 으로 변경되었습니다.", "success");
},
function(errorMessage, errorCode) {
showErrorMessage(errorMessage, "error");
}
);
}
deletePlayer(inputButton) {
let self = this;
let id = $(inputButton).siblings(".player_id");
let playerID = id.text();
let name = $(inputButton).siblings(".player_name");
let playerName = name.val();
// console.log(playerName);
// let clickedObjectID = this.getClickedObjectID(inputButton);
if(playerID === null || playerID === "")
return;
sendRequestServer( //url, sendParams, onSuccess, onFail, isDebugMode);
"./../server/player/delete_player.php",
"maestro_id=" + maestroID + "&player_id=" + playerID,
function(jsonData) {
if(this.playerListID === "add_player_list") {
self.setupAddPlayerList();
} else if(this.playerListID === "search_player_list") {
self.setupSearchPlayerList(this.searchPlayerName);
}
showErrorMessage("[ " + playerName + "] 학생 데이터가 삭제되었습니다.", "success");
onChangePlayerCount();
},
function(errorMessage, errorCode) {
showErrorMessage(errorMessage, "error");
}
);
}
onClickPageNo(pageNo) {
let self = this;
self.activePageNo = pageNo;
if(this.playerListID === "add_player_list") {
self.updateAddPlayerListPage(self.activePageNo);
} else if(this.playerListID === "search_player_list") {
self.updateSearchPlayerListPage(this.searchPlayerName, self.activePageNo);
} }
);
}
PlayerListManager.prototype.loadAddPlayerListPage = function(pageNo) {
var self = this;
this.activePageNo = pageNo;
var pageIndex = pageNo - 1;
var startNo = pageIndex * 10;
var endNo = pageIndex * 10 + 9;
sendRequestServer( //url, sendParams, onSuccess, onFail, isDebugMode);
"./../server/player/registered_player_list.php",
"maestro_id=" + maestroID + "&start_no=" + startNo + "&end_no=" + endNo,
function(jsonData) {
self.playerCount = jsonData["playerList"].length;
self.list.updatePlayerList(jsonData["playerList"]);
},
function(errorMessage, errorCode) {
showErrorMessage(errorMessage, "error");
}
);
}
PlayerListManager.prototype.updateAddPlayerListPage = function(pageNo) {
var self = this;
this.playerListPage = pageNo;
var pageIndex = pageNo - 1;
var startNo = pageIndex * 10;
var endNo = pageIndex * 10 + 9;
sendRequestServer( //url, sendParams, onSuccess, onFail, isDebugMode);
"./../server/player/registered_player_list.php",
"maestro_id=" + maestroID + "&start_no=" + startNo + "&end_no=" + endNo,
function(jsonData) {
self.playerCount = jsonData["playerList"].length;
self.list.updatePlayerList(jsonData["playerList"]);
self.listNavigator.updateNavigator(self.activePageNo, self.lastPageNo);
},
function(errorMessage, errorCode) {
showErrorMessage(errorMessage, "error");
}
);
}
PlayerListManager.prototype.setupSearchPlayerList = function(playerName) {
var self = this;
this.searchPlayerName = playerName;
sendRequestServer( //url, sendParams, onSuccess, onFail, isDebugMode);
"./../server/player/search_player_count.php",
"maestro_id=" + maestroID + "&player_name=" + this.searchPlayerName,
function(jsonData) {
self.playerCount = jsonData["playerCount"];
self.lastPageNo = Math.ceil( (self.playerCount + 1) / 10 );
self.activePageNo = 1;
self.updateSearchPlayerListPage(this.searchPlayerName, 1);
if(self.playerCount === 0)
showErrorMessage(this.searchPlayerName + " : 검색 결과가 없습니다.", "info");
},
function(errorMessage, errorCode) {
showErrorMessage(errorMessage, "error");
}
);
}
PlayerListManager.prototype.updateSearchPlayerListPage = function(playerName, pageNo) {
var self = this;
this.playerListPage = pageNo;
var pageIndex = pageNo - 1;
var startNo = pageIndex * 10;
var endNo = pageIndex * 10 + 9;
sendRequestServer( //url, sendParams, onSuccess, onFail, isDebugMode);
"./../server/player/search_player_list.php",
"maestro_id=" + maestroID + "&player_name=" + playerName + "&start_no=" + startNo + "&end_no=" + endNo,
function(jsonData) {
self.playerCount = jsonData["playerList"].length;
self.list.updatePlayerList(jsonData["playerList"]);
self.listNavigator.updateNavigator(self.activePageNo, self.lastPageNo);
},
function(errorMessage, errorCode) {
showErrorMessage(errorMessage, "error");
}
);
}
PlayerListManager.prototype.editPlayer = function(inputButton) {
var self = this;
console.log(inputButton);
// var clickedObjectID = this.getClickedObjectID(inputButton);
var id = $(inputButton).siblings(".player_id");
var playerID = id.text();
// console.log(playerID);
var name = $(inputButton).siblings(".player_name");
var playerName = name.val();
// console.log(playerName);
var enterCode = $(inputButton).siblings(".player_entercode");
var playerEnterCode = enterCode.val();
// console.log(playerEnterCode);
sendRequestServer( //url, sendParams, onSuccess, onFail, isDebugMode);
"./../server/player/edit_player.php",
"maestro_id=" + maestroID + "&player_id=" + playerID + "&player_name=" + playerName + "&enter_code=" + playerEnterCode,
function(jsonData) {
// console.log(jsonData);
if(this.playerListID === "add_player_list") {
self.setupAddPlayerList();
} else if(this.playerListID === "search_player_list") {
self.setupSearchPlayerList(this.searchPlayerName);
}
showErrorMessage("학생 데이터가 [ " + playerName + " / " + playerEnterCode + " ] 으로 변경되었습니다.", "success");
},
function(errorMessage, errorCode) {
showErrorMessage(errorMessage, "error");
}
);
}
PlayerListManager.prototype.deletePlayer = function(inputButton) {
var self = this;
var id = $(inputButton).siblings(".player_id");
var playerID = id.text();
var name = $(inputButton).siblings(".player_name");
var playerName = name.val();
// console.log(playerName);
// var clickedObjectID = this.getClickedObjectID(inputButton);
if(playerID === null || playerID === "")
return;
sendRequestServer( //url, sendParams, onSuccess, onFail, isDebugMode);
"./../server/player/delete_player.php",
"maestro_id=" + maestroID + "&player_id=" + playerID,
function(jsonData) {
if(this.playerListID === "add_player_list") {
self.setupAddPlayerList();
} else if(this.playerListID === "search_player_list") {
self.setupSearchPlayerList(this.searchPlayerName);
}
showErrorMessage("[ " + playerName + "] 학생 데이터가 삭제되었습니다.", "success");
onChangePlayerCount();
},
function(errorMessage, errorCode) {
showErrorMessage(errorMessage, "error");
}
);
}
PlayerListManager.prototype.onClickPageNo = function(pageNo) {
var self = this;
self.activePageNo = pageNo;
if(this.playerListID === "add_player_list") {
self.updateAddPlayerListPage(self.activePageNo);
} else if(this.playerListID === "search_player_list") {
self.updateSearchPlayerListPage(this.searchPlayerName, self.activePageNo);
} }
} }
+129 -133
View File
@@ -1,163 +1,159 @@
class PlayerListNavigator { function PlayerListNavigator(pageNoArea, playerListManager) {
var self = this;
this.playerListManager = playerListManager;
this.pagination = pageNoArea;
// console.log(parent);
constructor(pageNoArea, playerListManager) { this.activePageNo = 1;
let self = this; this.lastPageNo = 1;
this.playerListManager = playerListManager; }
this.pagination = pageNoArea;
// console.log(parent);
this.activePageNo = 1; PlayerListNavigator.prototype.updateNavigator = function(activePageNo, lastPageNo) {
this.lastPageNo = 1; this.activePageNo = activePageNo;
} this.lastPageNo = lastPageNo;
// this.lastPageNo = Math.ceil( (playerCount + 1) / 10 );
updateNavigator(activePageNo, lastPageNo) { $(this.pagination).empty();
this.activePageNo = activePageNo; this.makePagination();
this.lastPageNo = lastPageNo; this.applyClickEvent();
// this.lastPageNo = Math.ceil( (playerCount + 1) / 10 ); this.disableNavButtons();
}
$(this.pagination).empty(); PlayerListNavigator.prototype.makePagination = function() {
this.makePagination(); // left arrows
this.applyClickEvent(); var paginationLeftArrows = '\
this.disableNavButtons(); <li class="page-item">\
} <a class="page-link" href="javascript:void(0);" aria-label="First">\
<span aria-hidden="true">&laquo;</span>\
makePagination() { <span class="sr-only">First</span>\
// left arrows </a>\
let paginationLeftArrows = '\ </li>\
<li class="page-item">\
<a class="page-link" href="javascript:void(0);" aria-label="First">\
<span aria-hidden="true">&laquo;</span>\
<span class="sr-only">First</span>\
</a>\
</li>\
\ \
<li class="page-item">\ <li class="page-item">\
<a class="page-link" href="javascript:void(0);" aria-label="Previous">\ <a class="page-link" href="javascript:void(0);" aria-label="Previous">\
<span aria-hidden="true">&lt;</span>\ <span aria-hidden="true">&lt;</span>\
<span class="sr-only">Previous</span>\ <span class="sr-only">Previous</span>\
</a>\ </a>\
</li>\ </li>\
\ \
<li>&nbsp</li>\ <li>&nbsp</li>\
\ '; \ ';
$(this.pagination).append(paginationLeftArrows); $(this.pagination).append(paginationLeftArrows);
// numbers // numbers
for(let pageNo = 1; pageNo < this.lastPageNo + 1; pageNo++) { for(var pageNo = 1; pageNo < this.lastPageNo + 1; pageNo++) {
$(this.pagination).append( $(this.pagination).append(
'<li class="page-item"><a class="page-link" href="javascript:void(0);" aria-label="' + pageNo + '">' + pageNo + '</a></li>' '<li class="page-item"><a class="page-link" href="javascript:void(0);" aria-label="' + pageNo + '">' + pageNo + '</a></li>'
); );
} }
// right arrows // right arrows
let paginationRightArrows = '\ var paginationRightArrows = '\
<li>&nbsp</li>\ <li>&nbsp</li>\
\ \
<li class="page-item">\ <li class="page-item">\
<a class="page-link" href="javascript:void(0);" aria-label="Next">\ <a class="page-link" href="javascript:void(0);" aria-label="Next">\
<span aria-hidden="true">&gt;</span>\ <span aria-hidden="true">&gt;</span>\
<span class="sr-only">Next</span>\ <span class="sr-only">Next</span>\
</a>\ </a>\
</li>\ </li>\
\ \
<li class="page-item">\ <li class="page-item">\
<a class="page-link" href="javascript:void(0);" aria-label="Last">\ <a class="page-link" href="javascript:void(0);" aria-label="Last">\
<span aria-hidden="true">&raquo;</span>\ <span aria-hidden="true">&raquo;</span>\
<span class="sr-only">Last</span>\ <span class="sr-only">Last</span>\
</a>\ </a>\
</li>\ </li>\
'; ';
$(this.pagination).append(paginationRightArrows); $(this.pagination).append(paginationRightArrows);
} }
applyClickEvent() { PlayerListNavigator.prototype.applyClickEvent = function() {
let self = this; var self = this;
$("[aria-label='First']").click(function() { $("[aria-label='First']").click(function() {
self.onClickPageNo("first"); self.onClickPageNo("first");
}); });
$("[aria-label='Previous']").click(function() { $("[aria-label='Previous']").click(function() {
self.onClickPageNo("previous"); self.onClickPageNo("previous");
}); });
for(let pageNo = 1; pageNo < this.lastPageNo + 1; pageNo++) { for(var pageNo = 1; pageNo < this.lastPageNo + 1; pageNo++) {
$("[aria-label='" + pageNo + "']").click(function() { $("[aria-label='" + pageNo + "']").click(function() {
self.onClickPageNo(pageNo); self.onClickPageNo(pageNo);
});
}
$("[aria-label='Next']").click(function() {
self.onClickPageNo("next");
});
$("[aria-label='Last']").click(function() {
self.onClickPageNo("last");
}); });
} }
disableNavButtons() { $("[aria-label='Next']").click(function() {
/* self.onClickPageNo("next");
console.log(this.activePageNo); });
console.log(this.lastPageNo);
console.log($("[aria-label='First']").parent());
if(this.activePageNo === 1 || this.lastPageNo === 1) $("[aria-label='Last']").click(function() {
$("[aria-label='First']").parent().prop("disabled", true); self.onClickPageNo("last");
});
}
PlayerListNavigator.prototype.disableNavButtons = function() {
/*
console.log(this.activePageNo);
console.log(this.lastPageNo);
console.log($("[aria-label='First']").parent());
if(this.activePageNo === 1 || this.lastPageNo === 1)
$("[aria-label='First']").parent().prop("disabled", true);
else
$("[aria-label='First']").parent().prop("disabled", false);
if(this.activePageNo === 1 || this.lastPageNo === 1)
$("[aria-label='Previous']").parent().prop("disabled", true);
else
$("[aria-label='Previous']").parent().prop("disabled", false);
for(var pageNo = 1; pageNo < this.lastPageNo + 1; pageNo++) {
if(this.activePageNo === pageNo)
$("[aria-label='" + pageNo + "']").parent().prop("disabled", true);
else else
$("[aria-label='First']").parent().prop("disabled", false); $("[aria-label='" + pageNo + "']").parent().prop("disabled", false);
if(this.activePageNo === 1 || this.lastPageNo === 1)
$("[aria-label='Previous']").parent().prop("disabled", true);
else
$("[aria-label='Previous']").parent().prop("disabled", false);
for(let pageNo = 1; pageNo < this.lastPageNo + 1; pageNo++) {
if(this.activePageNo === pageNo)
$("[aria-label='" + pageNo + "']").parent().prop("disabled", true);
else
$("[aria-label='" + pageNo + "']").parent().prop("disabled", false);
}
if(this.activePageNo === this.lastPageNo)
$("[aria-label='Next']").parent().prop("disabled", true);
else
$("[aria-label='Next']").parent().prop("disabled", false);
if(this.activePageNo === this.lastPageNo)
$("[aria-label='Last']").parent().prop("disabled", true);
else
$("[aria-label='Last']").parent().prop("disabled", false);
*/
} }
onClickPageNo(pageNo) { if(this.activePageNo === this.lastPageNo)
console.log(pageNo); $("[aria-label='Next']").parent().prop("disabled", true);
switch(pageNo) { else
case "first": $("[aria-label='Next']").parent().prop("disabled", false);
this.activePageNo = 1;
break;
case "previous": if(this.activePageNo === this.lastPageNo)
if(this.activePageNo > 1) $("[aria-label='Last']").parent().prop("disabled", true);
this.activePageNo -= 1; else
break; $("[aria-label='Last']").parent().prop("disabled", false);
*/
}
case "next": PlayerListNavigator.prototype.onClickPageNo = function(pageNo) {
if(this.activePageNo < this.lastPageNo) console.log(pageNo);
this.activePageNo += 1; switch(pageNo) {
break; case "first":
this.activePageNo = 1;
break;
case "last": case "previous":
this.activePageNo = this.lastPageNo; if(this.activePageNo > 1)
break; this.activePageNo -= 1;
break;
default: case "next":
this.activePageNo = pageNo; if(this.activePageNo < this.lastPageNo)
} this.activePageNo += 1;
break;
console.log(this.activePageNo); case "last":
this.playerListManager.onClickPageNo(this.activePageNo); this.activePageNo = this.lastPageNo;
break;
default:
this.activePageNo = pageNo;
} }
console.log(this.activePageNo);
this.playerListManager.onClickPageNo(this.activePageNo);
} }
+8 -8
View File
@@ -5,7 +5,7 @@
// console.log(onFail); // console.log(onFail);
// console.log(isDebugMode); // console.log(isDebugMode);
let xhr = new XMLHttpRequest(); //new로 생성. var xhr = new XMLHttpRequest(); //new로 생성.
xhr.open('POST', url, true); xhr.open('POST', url, true);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.send(sendParams); xhr.send(sendParams);
@@ -15,25 +15,25 @@
// console.log(xhr.responseText.length); // console.log(xhr.responseText.length);
if(xhr.responseText.length === 0 || xhr.responseText === null) { if(xhr.responseText.length === 0 || xhr.responseText === null) {
let errorMessage = "서버에서 요청을 수행하지 못했습니다."; var errorMessage = "서버에서 요청을 수행하지 못했습니다.";
let errorCode = "no_reply_from_server"; var errorCode = "no_reply_from_server";
printErrorMessage(errorMessage, errorCode, onFail, isDebugMode); printErrorMessage(errorMessage, errorCode, onFail, isDebugMode);
return; return;
} }
let jsonReply = JSON.parse(xhr.responseText); var jsonReply = JSON.parse(xhr.responseText);
// console.log(jsonReply); // console.log(jsonReply);
if(jsonReply === null) { if(jsonReply === null) {
let errorMessage = "서버에서 데이터가 넘어오지 않았습니다."; var errorMessage = "서버에서 데이터가 넘어오지 않았습니다.";
let errorCode = "no_data_from_server"; var errorCode = "no_data_from_server";
printErrorMessage(errorMessage, errorCode, onFail, isDebugMode); printErrorMessage(errorMessage, errorCode, onFail, isDebugMode);
return; return;
} }
if(!isSuccess(jsonReply)) { if(!isSuccess(jsonReply)) {
let errorMessage = getErrorMessage(jsonReply); var errorMessage = getErrorMessage(jsonReply);
let errorCode = jsonReply["error_code"]; var errorCode = jsonReply["error_code"];
printErrorMessage(errorMessage, errorCode, onFail, isDebugMode); printErrorMessage(errorMessage, errorCode, onFail, isDebugMode);
return; return;
} }