Fix: revised php code to admin

This commit is contained in:
2018-07-12 07:20:44 +09:00
parent b5b56e8c2d
commit 070b870044
8 changed files with 77 additions and 687 deletions
+34 -92
View File
@@ -11,9 +11,7 @@
<script type="text/javascript" src="./../../../resources/jquery/jquery-3.3.1.min.js"></script>
<script type="text/javascript" src="./../js/main.js"></script>
<script type="text/javascript" src="./../js/maestro_list_manager.js"></script>
<script type="text/javascript" src="./../js/maestro_list.js"></script>
<script type="text/javascript" src="./../js/maestro_list_navigator.js"></script>
<script type="text/javascript" src="./../js/request_server.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#header").load("admin_header.html");
@@ -32,45 +30,22 @@
loadMaestroList(maestroName);
}
function loadMaestroList($maestroName) {
let xhr = new XMLHttpRequest();
xhr.open('POST', './../server/admin/registered_maestro_list.php', true);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.send("maestro_name=" + $maestroName);
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");
$("#error_message").text("서버에서 요청을 수행하지 못했습니다.");
return;
function loadMaestroList(maestroName) {
sendRequestServer( //url, sendParams, onSuccess, onFail, isDebugMode);
"./../server/admin/registered_maestro_list.php",
"maestro_name=" + maestroName,
(jsonData) => {
updateMaestroList(jsonData["maestroList"]);
},
(errorMessage) => {
if($("#error_message").length) {
$("#error_message").text(errorMessage);
}
let replyJSON = JSON.parse(xhr.responseText);
// console.log(replyJSON);
if(replyJSON === null) {
console.log("no data from server");
$("#error_message").text("서버에서 데이터가 넘어오지 않았습니다.");
return;
}
if(replyJSON["ERROR"] !== undefined || replyJSON["RESULT"] === undefined) {
console.log(replyJSON["ERROR"]);
$("#error_message").text(replyJSON["ERROR"]);
return;
}
if(replyJSON["RESULT"] === "fail") {
console.log(replyJSON["RESULT"]);
$("#error_message").text(replyJSON["ERROR"]);
return;
}
updateMaestroList(replyJSON["MaestroList"]);
}
}
);
}
@@ -99,9 +74,9 @@
for(let i = 0; i < jsonList.length; i++) {
$("#maestro_list_result_contents").append(
"<li class='search_result_list'>"
+ " <span class='maestro_id hide'>" + jsonList[i].MaestroID + "</span>"
+ " <input type='text' value='" + jsonList[i].Name + "' class='maestro_name'>"
+ " <input type='text' value='" + jsonList[i].AccountType + "' class='maestro_account_type'>"
+ " <span class='maestro_id hide'>" + jsonList[i].maestroID + "</span>"
+ " <input type='text' value='" + jsonList[i].maestroName + "' class='maestro_name'>"
+ " <input type='text' value='" + jsonList[i].accountType + "' class='maestro_account_type'>"
+ " <input type='button' class='maestro_register' value='등록' onClick='register(this)'>"
+ "</li>"
);
@@ -112,65 +87,32 @@
$("#maestro_list_result_contents").append("</ul>");
}
function getClickedObjectID(clickedObject) {
let tagDiv = $(clickedObject).closest(".player_list");
let tagDivID = tagDiv.prop("id");
// console.log(tagDivIDName);
return tagDivID;
}
function register(inputButton) {
console.log(inputButton);
let id = $(inputButton).siblings(".maestro_id");
let maestroID = id.text();
console.log(maestroID);
// console.log(maestroID);
let name = $(inputButton).siblings(".maestro_name");
let maestroName = name.val();
console.log(maestroName);
// let name = $(inputButton).siblings(".maestro_name");
// let maestroName = name.val();
// console.log(maestroName);
let xhr = new XMLHttpRequest(); //new로 생성.
xhr.open('POST', './../server/admin/register_maestro.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");
$("#error_message").text("서버에서 요청을 수행하지 못했습니다.");
return;
}
let replyJSON = JSON.parse(xhr.responseText);
// console.log(replyJSON);
if(replyJSON === null) {
console.log("no data from server");
$("#error_message").text("서버에서 데이터가 넘어오지 않았습니다.");
return;
}
if(replyJSON["ERROR"] !== undefined || replyJSON["RESULT"] === undefined) {
console.log(replyJSON["ERROR"]);
$("#error_message").text(replyJSON["ERROR"]);
return;
}
if(replyJSON["RESULT"] === "fail") {
console.log(replyJSON["RESULT"]);
$("#error_message").text(replyJSON["ERROR"]);
return;
}
sendRequestServer( //url, sendParams, onSuccess, onFail, isDebugMode);
"./../server/admin/register_maestro.php",
"maestro_id=" + maestroID,
(jsonData) => {
loadMaestroList("");
$("#error_message").text("마에스트로 계정이 정상적으로 등록되었습니다.");
},
(errorMessage) => {
if($("#error_message").length) {
$("#error_message").text(errorMessage);
}
}
}
);
}
</script>