From fa241a6ee06f991b52dc8e842097b75a33b9bfd2 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: Tue, 3 Jul 2018 14:35:39 +0900 Subject: [PATCH] Add: player_list.js --- src/web/css/maestro_main.css | 33 ++++- src/web/js/maestro_main.js | 53 ++++---- src/web/js/player_list.js | 99 +++++++++++++++ src/web/maestro/main_menu.html | 1 + .../module/maestro_section_add_player.html | 92 +++++++++++++- src/web/module/maestro_section_main.html | 17 +-- src/web/module/maestro_section_search.html | 113 ++++++++++++++++++ src/web/server/user/add_player.php | 8 +- src/web/server/user/delete_player.php | 97 +++++++++++++++ 9 files changed, 459 insertions(+), 54 deletions(-) create mode 100644 src/web/js/player_list.js create mode 100644 src/web/module/maestro_section_search.html create mode 100644 src/web/server/user/delete_player.php diff --git a/src/web/css/maestro_main.css b/src/web/css/maestro_main.css index 9f5881b..85817b0 100644 --- a/src/web/css/maestro_main.css +++ b/src/web/css/maestro_main.css @@ -51,12 +51,20 @@ text-align: center; } -#registered_player_list .registered_player_list_name { +#registered_player_list > li > span { + line-height: normal; +} + +#registered_player_list .player_id { + background-color: #ffffff; +} + +#registered_player_list .player_name { width: 200px; background-color: #ffdddd; } -#registered_player_list .registered_player_list_entercode { +#registered_player_list .player_entercode { width: 200px; background-color: #ddffdd; } @@ -74,4 +82,25 @@ cursor: pointer; } +#search { + overflow: hidden; +} + +#search_player { + float: left; + line-height: 2em; + width: 400px; + padding: 10px; + background-color: #aaaaff; +} + +#search_result { + float: right; + line-height: 2em; + width: 600px; + padding: 10px; + background-color: #ffaaaa; +} + + \ No newline at end of file diff --git a/src/web/js/maestro_main.js b/src/web/js/maestro_main.js index 440618f..2b7c3a0 100644 --- a/src/web/js/maestro_main.js +++ b/src/web/js/maestro_main.js @@ -3,6 +3,9 @@ let playerCount = 0; let playerListPage = 0; let lastPageNo = 0; +let addPlayerList; +let searchPlayerList + $(document).ready(function() { maestroID = sessionStorage.getItem("maestroID"); @@ -44,7 +47,6 @@ function loadPlayerList() { playerCount = replyJSON["Count"]; lastPageNo = Math.floor( (playerCount + 1) / 10 ); - console.log("registered player count : " + playerCount); loadPlayerListPage(1); addPlayerListPages(); } @@ -69,18 +71,21 @@ function onClickPlayerListPage(pageNo) { 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; @@ -90,13 +95,12 @@ function onClickPlayerListPage(pageNo) { } function loadPlayerListPage(pageNo) { + playerListPage = pageNo; + let pageIndex = pageNo - 1; let startNo = pageIndex * 10; let endNo = pageIndex * 10 + 9; - console.log("startNo : " + startNo); - console.log("endNo : " + endNo); - 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"); @@ -128,33 +132,26 @@ function loadPlayerListPage(pageNo) { return; } - console.log(replyJSON["PlayerList"]); + // console.log(replyJSON["PlayerList"]); updatePlayerListPage(replyJSON["PlayerList"]); } } } -function addPlayerListTitle() { - $("#registered_player_list").empty(); - - $("#registered_player_list").append( - '
  • 이름
  • 입장 코드
  • ' - ); -} - function updatePlayerListPage(playerList) { - $("#registered_player_list").empty(); - addPlayerListTitle(); + for(let i = 0; i < 10; i++) { + let listIndex = i + 1; // index 0 : list title - for(let i = 0; i < playerList.length; i++) { - $("#registered_player_list").append( - "
  • " - + "" + playerList[i]["UserID"] + "" - + "" - + "" - + "" - + "
  • " - ); + 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(""); + } } } @@ -245,5 +242,9 @@ function addPlayer() { loadPlayerListPage(1); } } +} + + +function deletePlayer(id) { } \ No newline at end of file diff --git a/src/web/js/player_list.js b/src/web/js/player_list.js new file mode 100644 index 0000000..550f3af --- /dev/null +++ b/src/web/js/player_list.js @@ -0,0 +1,99 @@ +class PlayerContent { + + constructor(playerID, playerName, enterCode) { + this.playerID = playerID; + this.playerName = playerName; + this.enterCode = enterCode; + } + +} + +class PlayerList { + + constructor(parent) { + let self = this; + this.listParent = parent; + // console.log(parent); + + let id_list = parent.find(".player_id"); + // console.log(id_list); + + this.playerContents = new Array(); + for(let i = 0; i < id_list.length; i++) { + this.playerContents[i] = new PlayerContent( + id_list[i], // span + $(id_list[i]).siblings(".player_name"), + $(id_list[i]).siblings(".player_entercode") + // name_list[i + 1], // input + // entercode_list[i + 1] // input + ); + + $(id_list[i]).siblings(".player_edit").click(function() { + self.editPlayer(this); + }) + + $(id_list[i]).siblings(".player_delete").click(function() { + self.deletePlayer(this); + }) + // console.log(this.playerContents[i].playerName.val()); + } + } + + editPlayer(inputButton) { + // console.log(inputButton); + + let id = $(inputButton).siblings(".player_id"); + // console.log(id); + let playerID = id.text(); + + console.log(playerID); + } + + deletePlayer(inputButton) { + let id = $(inputButton).siblings(".player_id"); + let playerID = id.text(); + + if(playerID === null || playerID === "") + return; + + console.log(playerID); + + let xhr = new XMLHttpRequest(); //new로 생성. + xhr.open('POST', './../server/user/delete_player.php', true); + xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); + xhr.send("maestro_id=" + maestroID + "&player_id=" + playerID); + 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); + } + } + + } + +} \ No newline at end of file diff --git a/src/web/maestro/main_menu.html b/src/web/maestro/main_menu.html index 7770c8c..2d89a8d 100644 --- a/src/web/maestro/main_menu.html +++ b/src/web/maestro/main_menu.html @@ -11,6 +11,7 @@ + + + + +

    추가

    1명 추가

    @@ -15,6 +24,7 @@ +
    - - 목록 + + 학생 목록
      +
    • + 이름 + 입장 코드 + +
    • +
    • + + + + + +
    • +
    • + + + + + +
    • +
    • + + + + + +
    • +
    • + + + + + +
    • +
    • + + + + + +
    • +
    • + + + + + +
    • +
    • + + + + + +
    • +
    • + + + + + +
    • +
    • + + + + + +
    • +
    • + + + + + +
    diff --git a/src/web/module/maestro_section_main.html b/src/web/module/maestro_section_main.html index e3bb500..f5fa85c 100644 --- a/src/web/module/maestro_section_main.html +++ b/src/web/module/maestro_section_main.html @@ -1,8 +1,7 @@  + + + + + 검색 + 아이디 +
    +
    + +

    검색 결과

    + + 학생 이름 +
    + 입장 코드 + +
    + + + 검색 결과 +
    +
      +
    • + 이름 + 입장 코드 + +
    • +
    • + + + + + +
    • +
    • + + + + + +
    • +
    • + + + + + +
    • +
    • + + + + + +
    • +
    • + + + + + +
    • +
    • + + + + + +
    • +
    • + + + + + +
    • +
    • + + + + + +
    • +
    • + + + + + +
    • +
    • + + + + + +
    • +
    +
    + + +
    \ No newline at end of file diff --git a/src/web/server/user/add_player.php b/src/web/server/user/add_player.php index 00a0c9d..d76ea79 100644 --- a/src/web/server/user/add_player.php +++ b/src/web/server/user/add_player.php @@ -16,15 +16,9 @@ if(!is_numeric($enterCode)) { include "./../setup/connect_db.php"; -function send_error_message2($replyJSON, $error_message) { - $replyJSON["ERROR"] = $error_message; - echo json_encode($replyJSON, JSON_UNESCAPED_UNICODE); - // $db_conn->close(); -} - $result = hasPlayerName($maestroID, $playerName, $enterCode); if($result !== null) { - send_error_message2($replyJSON, "이미 등록된 학생과 입장 코드 정보입니다."); + send_error_message($replyJSON, "이미 등록된 학생과 입장 코드 정보입니다."); // $db_conn->close(); exit; } diff --git a/src/web/server/user/delete_player.php b/src/web/server/user/delete_player.php new file mode 100644 index 0000000..7e2f8e8 --- /dev/null +++ b/src/web/server/user/delete_player.php @@ -0,0 +1,97 @@ +close(); + + +function deletePlayer($maestroID, $playerID) { + global $db_conn; + + $query = "DELETE FROM moty_best_record WHERE MaestroID = ? AND UserID = ?"; + $stmt = $db_conn->prepare($query); + $stmt->bind_param('ii', $maestroID, $playerID); + $result = $stmt->execute(); + $stmt->close(); + + // if($result) { + // echo "deleted row count : ".$stmt->affected_rows; + // } + + $query = "DELETE FROM moty_user WHERE MaestroID = ? AND UserID = ?"; + $stmt = $db_conn->prepare($query); + $stmt->bind_param('ii', $maestroID, $playerID); + $result = $stmt->execute(); + $stmt->close(); + + // if($result) { + // echo "deleted row count : ".$stmt->affected_rows; + // } +} + +function hasPlayerID($maestroID, $playerID) { + global $db_conn; + + $query = "SELECT UserID FROM moty_user WHERE MaestroID=? AND UserID=?"; + $stmt = $db_conn->prepare($query); + $stmt->bind_param('ii', $maestroID, $playerID); + $stmt->execute(); + $stmt->bind_result($userID); + // while($stmt->fetch()) + $stmt->fetch(); + $stmt->close(); + + if($userID !== null) + return true; + + return false; +} + +function hasPlayerRecord($maestroID, $playerID) { + global $db_conn; + + $query = "SELECT UserID FROM moty_best_record WHERE MaestroID=? AND UserID=?"; + $stmt = $db_conn->prepare($query); + $stmt->bind_param('ii', $maestroID, $playerID); + $stmt->execute(); + $stmt->bind_result($userID); + // while($stmt->fetch()) + $stmt->fetch(); + $stmt->close(); + + if($userID !== null) + return true; + + return false; +} + +?> \ No newline at end of file