function PlayerListManager(docList, docNav) { this.docList = docList; this.docNav = docNav; this.playerListID = $(docList).attr("id"); this.list = new PlayerList(this.docList, this); this.list.updatePlayerList(null); this.listNavigator = new PlayerListNavigator(this.docNav, this); this.playerCount = 0; this.activePageNo = 1; this.lastPageNo = 0; this.searchPlayerName = ""; } PlayerListManager.prototype.setupAddPlayerList = function() { sendRequestServer( //url, sendParams, onSuccess, onFail, isDebugMode); "./../server/player/registered_player_count.php", "maestro_id=" + maestroID, (function(jsonData) { this.playerCount = jsonData["playerCount"]; this.lastPageNo = Math.ceil( (this.playerCount + 1) / 10 ); this.activePageNo = 1; this.loadAddPlayerListPage(this.activePageNo); this.listNavigator.updateNavigator(this.activePageNo, this.lastPageNo); }).bind(this), function(errorMessage, errorCode) { showErrorMessage(errorMessage, "error"); } ); } PlayerListManager.prototype.loadAddPlayerListPage = function(pageNo) { 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) { this.playerCount = jsonData["playerList"].length; this.list.updatePlayerList(jsonData["playerList"]); }).bind(this), function(errorMessage, errorCode) { showErrorMessage(errorMessage, "error"); } ); } PlayerListManager.prototype.updateAddPlayerListPage = function(pageNo) { 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) { console.log("updateAddPlayerListPage"); console.log(jsonData); this.playerCount = jsonData["playerList"].length; this.list.updatePlayerList(jsonData["playerList"]); this.listNavigator.updateNavigator(this.activePageNo, this.lastPageNo); }).bind(this), function(errorMessage, errorCode) { showErrorMessage(errorMessage, "error"); } ); } PlayerListManager.prototype.setupSearchPlayerList = function(playerName) { this.searchPlayerName = playerName; sendRequestServer( //url, sendParams, onSuccess, onFail, isDebugMode); "./../server/player/search_player_count.php", "maestro_id=" + maestroID + "&player_name=" + this.searchPlayerName, (function(jsonData) { this.playerCount = jsonData["playerCount"]; this.lastPageNo = Math.ceil( (this.playerCount + 1) / 10 ); this.activePageNo = 1; this.updateSearchPlayerListPage(this.searchPlayerName, 1); if(this.playerCount === 0) showErrorMessage(this.searchPlayerName + " : 검색 결과가 없습니다.", "info"); }).bind(this), function(errorMessage, errorCode) { showErrorMessage(errorMessage, "error"); } ); } PlayerListManager.prototype.updateSearchPlayerListPage = function(playerName, pageNo) { 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) { this.playerCount = jsonData["playerList"].length; this.list.updatePlayerList(jsonData["playerList"]); this.listNavigator.updateNavigator(this.activePageNo, this.lastPageNo); }).bind(this), function(errorMessage, errorCode) { showErrorMessage(errorMessage, "error"); } ); } PlayerListManager.prototype.refreshAddPlayerListPage = function() { this.loadAddPlayerListPage(this.activePageNo); } PlayerListManager.prototype.refreshSearchPlayerListPage = function() { this.updateSearchPlayerListPage(this.searchPlayerName, this.activePageNo); } PlayerListManager.prototype.editPlayer = function(inputButton) { // console.log(inputButton); // var clickedObjectID = this.getClickedObjectID(inputButton); var id = $(inputButton).parent().siblings(".player_id"); var playerID = id.text(); // console.log(playerID); var name = $(inputButton).parent().siblings(".player_name"); var playerName = name.val(); // console.log(playerName); var enterCode = $(inputButton).parent().siblings(".player_entercode"); var playerEnterCode = enterCode.val(); // console.log(playerEnterCode); if(!accountValidator.isValidPlayerID(playerName)) { // console.log("Error - playerName : " + playerName); onErrorPlayerName(accountValidator.messageForInvalidPlayerID(playerName)); return; } else if(!accountValidator.isValidPlayerPW(playerEnterCode)) { // console.log("Error - enterCode : " + enterCode); // onErrorPlayerPW(accountValidator.messageForInvalidPlayerPW(playerEnterCode)); showErrorMessage(accountValidator.messageForInvalidPlayerPW(playerEnterCode), "error"); $(enterCode).focus(); $(enterCode).select(); return; } 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") { // this.setupAddPlayerList(); refreshAddPlayerList(); refreshSearchPlayerList(); } else if(this.playerListID === "search_player_list") { // this.setupSearchPlayerList(this.searchPlayerName); refreshAddPlayerList(); refreshSearchPlayerList(); } showErrorMessage("학생 데이터가 [ " + playerName + " / " + playerEnterCode + " ] 으로 변경되었습니다.", "success"); }).bind(this), function(errorMessage, errorCode) { showErrorMessage(errorMessage, "error"); } ); } PlayerListManager.prototype.deletePlayer = function(inputButton) { var id = $(inputButton).parent().siblings(".player_id"); var playerID = id.text(); var name = $(inputButton).parent().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") { // this.setupAddPlayerList(); refreshAddPlayerList(); refreshSearchPlayerList(); } else if(this.playerListID === "search_player_list") { // this.setupSearchPlayerList(this.searchPlayerName); refreshAddPlayerList(); refreshSearchPlayerList(); } showErrorMessage("[ " + playerName + " ] 학생 데이터가 삭제되었습니다.", "success"); onChangePlayerCount(); }).bind(this), function(errorMessage, errorCode) { showErrorMessage(errorMessage, "error"); } ); } PlayerListManager.prototype.onClickPageNo = function(pageNo) { this.activePageNo = pageNo; if(this.playerListID === "add_player_list") { this.updateAddPlayerListPage(this.activePageNo); } else if(this.playerListID === "search_player_list") { this.updateSearchPlayerListPage(this.searchPlayerName, this.activePageNo); } }