From 8db6dd19ad34dbcdccb8ac53fbd4796d2cae09c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=A2=E1=84=91=E1=85=B3=E1=86=AF=20=E1=84=82?= =?UTF-8?q?=E1=85=A9=E1=84=90=E1=85=B3=E1=84=87=E1=85=AE=E1=86=A8?= Date: Wed, 4 Jul 2018 07:07:11 +0900 Subject: [PATCH] Fix: move addPlayer function --- src/web/js/maestro_main.js | 56 ++----------------- src/web/js/mouse_app_list.js | 51 +++++++++++++++++ .../module/maestro_section_add_player.html | 50 +++++++++++++++++ 3 files changed, 107 insertions(+), 50 deletions(-) create mode 100644 src/web/js/mouse_app_list.js diff --git a/src/web/js/maestro_main.js b/src/web/js/maestro_main.js index f263f68..0041e4d 100644 --- a/src/web/js/maestro_main.js +++ b/src/web/js/maestro_main.js @@ -4,11 +4,15 @@ let playerListPage = 0; let lastPageNo = 0; let addPlayerList; -let searchPlayerList; - let addPlayerListNavigator; + +let searchPlayerList; let searchPlayerListNavigator; +let mouseAppList; + +let typingAppList; + $(document).ready(function() { maestroID = sessionStorage.getItem("maestroID"); @@ -94,51 +98,3 @@ function tabClicked(tabNo) { } } -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; - } - - loadPlayerListPage(1); - } - } -} \ No newline at end of file diff --git a/src/web/js/mouse_app_list.js b/src/web/js/mouse_app_list.js new file mode 100644 index 0000000..c9ea772 --- /dev/null +++ b/src/web/js/mouse_app_list.js @@ -0,0 +1,51 @@ +class MouseAppList { + + constructor(pageNoArea) { + let self = this; + 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( + " " + pageNo + " " + ); + } + } + +} + + + +function onClickPlayerListPage(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); +} + diff --git a/src/web/module/maestro_section_add_player.html b/src/web/module/maestro_section_add_player.html index e00a410..5553270 100644 --- a/src/web/module/maestro_section_add_player.html +++ b/src/web/module/maestro_section_add_player.html @@ -6,6 +6,56 @@ $(document).ready(function() { loadPlayerList(); addPlayerListNavigator.addPlayerListPages(); }); + +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; + } + + loadPlayerListPage(1); + } + } +} +