Add: register_maestro
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
class MaestroListRow {
|
||||
|
||||
constructor(maestroID, maestroName, password, editButton, deleteButton) {
|
||||
this.maestroID = maestroID;
|
||||
this.maestroName = maestroName;
|
||||
this.password = password;
|
||||
this.editButton = editButton;
|
||||
this.deleteButton = deleteButton;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class MaestroList {
|
||||
|
||||
constructor(tagDiv, parent) {
|
||||
let self = this;
|
||||
this.parent = parent;
|
||||
// console.log(tagDiv);
|
||||
|
||||
this.maestroCount = 0;
|
||||
this.activePageNo = 1;
|
||||
|
||||
let id_list = tagDiv.find(".maestro_id");
|
||||
// console.log(id_list);
|
||||
|
||||
this.listRows = new Array();
|
||||
for(let i = 0; i < id_list.length; i++) {
|
||||
this.listRows[i] = new PaestroListRow(
|
||||
id_list[i], // span
|
||||
$(id_list[i]).siblings(".maestro_name"),
|
||||
$(id_list[i]).siblings(".maestro_password"),
|
||||
$(id_list[i]).siblings(".maestro_edit"),
|
||||
$(id_list[i]).siblings(".maestro_delete")
|
||||
);
|
||||
|
||||
this.disableItem(this.listRows[i]);
|
||||
|
||||
$(id_list[i]).siblings(".maestro_edit").click(function() {
|
||||
parent.editMaestro(this);
|
||||
})
|
||||
|
||||
$(id_list[i]).siblings(".maestro_delete").click(function() {
|
||||
parent.deleteMaestro(this);
|
||||
})
|
||||
// console.log(this.listRows[i].maestroName.val());
|
||||
// console.log(this.listRows[i]);
|
||||
}
|
||||
}
|
||||
|
||||
disableItem(item) {
|
||||
$(item.maestroID).empty();
|
||||
$(item.maestroName).prop("disabled", true);
|
||||
$(item.password).prop("disabled", true);
|
||||
$(item.editButton).prop("disabled", true);
|
||||
$(item.deleteButton).prop("disabled", true);
|
||||
}
|
||||
|
||||
enableItem(item) {
|
||||
$(item.maestroName).prop("disabled", false);
|
||||
$(item.password).prop("disabled", false);
|
||||
$(item.editButton).prop("disabled", false);
|
||||
$(item.deleteButton).prop("disabled", false);
|
||||
}
|
||||
|
||||
updatemaestroList(jsonData) {
|
||||
// console.log(jsonData);
|
||||
|
||||
for(let i = 0; i < 10; i++) {
|
||||
$(this.listRows[i].maestroID).empty();
|
||||
|
||||
if(i < jsonData.length) {
|
||||
$(this.listRows[i].maestroID).append(jsonData[i]["maestroID"]);
|
||||
$(this.listRows[i].maestroName).val(jsonData[i]["Name"]);
|
||||
$(this.listRows[i].password).val(jsonData[i]["Password"]);
|
||||
|
||||
this.enableItem(this.listRows[i]);
|
||||
} else {
|
||||
$(this.listRows[i].maestroName).val("");
|
||||
$(this.listRows[i].password).val("");
|
||||
|
||||
this.disableItem(this.listRows[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,411 @@
|
||||
class MaestroListManager {
|
||||
|
||||
constructor(docList, docNav) {
|
||||
let self = this;
|
||||
this.docList = docList;
|
||||
this.docNav = docNav;
|
||||
|
||||
this.list = new MaestroList(this.docList, this);
|
||||
this.listNavigator = new MaestroListNavigator(this.docNav);
|
||||
|
||||
this.maestroCount = 0;
|
||||
this.activePageNo = 1;
|
||||
this.lastPageNo = 0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
setupRegisteredMaestroList() {
|
||||
let self = this;
|
||||
|
||||
let xhr = new XMLHttpRequest(); //new로 생성.
|
||||
xhr.open('POST', './../server/maestro/registered_maestro_count.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");
|
||||
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;
|
||||
}
|
||||
|
||||
self.maestroCount = replyJSON["Count"];
|
||||
self.lastPageNo = Math.ceil( (self.maestroCount + 1) / 10 );
|
||||
self.activePageNo = 1;
|
||||
|
||||
self.loadRegisteredMaestroListPage(self.activePageNo);
|
||||
self.listNavigator.updateNavigator(self.activePageNo, self.lastPageNo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
loadRegisteredMaestroListPage(pageNo) {
|
||||
self = this;
|
||||
this.activePageNo = pageNo;
|
||||
|
||||
let pageIndex = pageNo - 1;
|
||||
let startNo = pageIndex * 10;
|
||||
let endNo = pageIndex * 10 + 9;
|
||||
|
||||
let xhr = new XMLHttpRequest(); //new로 생성.
|
||||
xhr.open('POST', './../server/maestro/registered_maestro_list.php', true);
|
||||
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
||||
xhr.send("maestro_id=" + maestroID + "&start_no=" + startNo + "&end_no=" + endNo);
|
||||
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(replyJSON["MaestroList"]);
|
||||
// updateMaestroListPage(replyJSON["MaestroList"]);
|
||||
self.list.updateMaestroList(replyJSON["MaestroList"]);
|
||||
|
||||
self.maestroCount = replyJSON["MaestroList"].length;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
updateRegisteredMaestroListPage(pageNo) {
|
||||
self = this;
|
||||
this.maestroListPage = pageNo;
|
||||
|
||||
let pageIndex = pageNo - 1;
|
||||
let startNo = pageIndex * 10;
|
||||
let endNo = pageIndex * 10 + 9;
|
||||
|
||||
let xhr = new XMLHttpRequest(); //new로 생성.
|
||||
xhr.open('POST', './../server/maestro/registered_maestro_list.php', true);
|
||||
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
||||
xhr.send("maestro_id=" + maestroID + "&start_no=" + startNo + "&end_no=" + endNo);
|
||||
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(replyJSON["MaestroList"]);
|
||||
self.list.updateMaestroList(replyJSON["MaestroList"]);
|
||||
|
||||
self.maestroCount = replyJSON["MaestroList"].length;
|
||||
// console.log(self.maestroCount);
|
||||
// self.lastPageNo = Math.ceil( (self.maestroCount + 1) / 10 );
|
||||
// self.activePageNo = 1;
|
||||
|
||||
self.listNavigator.updateNavigator(self.activePageNo, self.lastPageNo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
setupUpgradeMaestroList(maestroName) {
|
||||
let self = this;
|
||||
|
||||
let xhr = new XMLHttpRequest(); //new로 생성.
|
||||
xhr.open('POST', './../server/maestro/search_maestro_count.php', true);
|
||||
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
||||
xhr.send("maestro_id=" + maestroID + "&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");
|
||||
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;
|
||||
}
|
||||
|
||||
self.maestroCount = replyJSON["Count"];
|
||||
self.lastPageNo = Math.ceil( (self.maestroCount + 1) / 10 );
|
||||
self.activePageNo = 1;
|
||||
|
||||
self.updateSearchMaestroListPage(maestroName, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
updateUpgradeMaestroListPage(maestroName, pageNo) {
|
||||
let self = this;
|
||||
this.maestroListPage = pageNo;
|
||||
|
||||
let pageIndex = pageNo - 1;
|
||||
let startNo = pageIndex * 10;
|
||||
let endNo = pageIndex * 10 + 9;
|
||||
|
||||
let xhr = new XMLHttpRequest(); //new로 생성.
|
||||
xhr.open('POST', './../server/maestro/search_maestro_list.php', true);
|
||||
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
||||
xhr.send("maestro_id=" + maestroID + "&maestro_name=" + maestroName + "&start_no=" + startNo + "&end_no=" + endNo);
|
||||
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(replyJSON["MaestroList"]);
|
||||
self.list.updateMaestroList(replyJSON["MaestroList"]);
|
||||
|
||||
self.maestroCount = replyJSON["MaestroList"].length;
|
||||
// self.lastPageNo = Math.ceil( (self.maestroCount + 1) / 10 );
|
||||
// self.activePageNo = 1;
|
||||
|
||||
self.listNavigator.updateNavigator(self.activePageNo, self.lastPageNo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
onClickMaestroListPage(pageNo) {
|
||||
switch(pageNo) {
|
||||
case "first":
|
||||
this.activePageNo = 1;
|
||||
self.loadAddMaestroListPage(self.activePageNo);
|
||||
return;
|
||||
|
||||
case "prev":
|
||||
if(this.activePageNo > 1)
|
||||
this.activePageNo -= 1;
|
||||
self.loadAddMaestroListPage(self.activePageNo);
|
||||
return;
|
||||
|
||||
case "next":
|
||||
if(this.activePageNo < this.lastPageNo)
|
||||
this.activePageNo += 1;
|
||||
self.loadAddMaestroListPage(self.activePageNo);
|
||||
return;
|
||||
|
||||
case "last":
|
||||
this.loadAddMaestroListPage(this.lastPageNo);
|
||||
return;
|
||||
}
|
||||
|
||||
this.activePageNo = pageNo;
|
||||
self.loadAddMaestroListPage(self.activePageNo);
|
||||
}
|
||||
|
||||
|
||||
registMaestro(inputButton) {
|
||||
// console.log(inputButton);
|
||||
let clickedObjectID = this.getClickedObjectID(inputButton);
|
||||
|
||||
|
||||
let id = $(inputButton).siblings(".maestro_id");
|
||||
let maestroID = id.text();
|
||||
// console.log(maestroID);
|
||||
|
||||
let name = $(inputButton).siblings(".maestro_name");
|
||||
let maestroName = name.val();
|
||||
// console.log(maestroName);
|
||||
|
||||
let enterCode = $(inputButton).siblings(".maestro_entercode");
|
||||
let maestroEnterCode = enterCode.val();
|
||||
// console.log(maestroEnterCode);
|
||||
|
||||
let xhr = new XMLHttpRequest(); //new로 생성.
|
||||
xhr.open('POST', './../server/maestro/edit_maestro.php', true);
|
||||
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
||||
xhr.send("maestro_id=" + maestroID + "&maestro_id=" + maestroID + "&maestro_name=" + maestroName + "&enter_code=" + maestroEnterCode);
|
||||
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(clickedObjectID);
|
||||
if(clickedObjectID === "registered_maestro_list") {
|
||||
self.setupRegisteredMaestroList();
|
||||
} else if(clickedObjectID === "search_maestro_list") {
|
||||
let maestroName = $("#search_name").val();
|
||||
self.setupUpdateMaestroList(maestroName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
deleteMaestro(inputButton) {
|
||||
let self = this;
|
||||
|
||||
let id = $(inputButton).siblings(".maestro_id");
|
||||
let maestroID = id.text();
|
||||
|
||||
let clickedObjectID = this.getClickedObjectID(inputButton);
|
||||
|
||||
if(maestroID === null || maestroID === "")
|
||||
return;
|
||||
|
||||
let xhr = new XMLHttpRequest(); //new로 생성.
|
||||
xhr.open('POST', './../server/maestro/delete_maestro.php', true);
|
||||
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
||||
xhr.send("maestro_id=" + maestroID + "&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");
|
||||
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(clickedObjectID);
|
||||
if(clickedObjectID === "registered_maestro_list") {
|
||||
self.setupRegisteredMaestroList();
|
||||
} else if(clickedObjectID === "upgrade_maestro_list") {
|
||||
let maestroName = $("#search_name").val();
|
||||
self.setupUpgradeMaestroList(maestroName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
getClickedObjectID(clickedObject) {
|
||||
let tagDiv = $(clickedObject).closest(".maestro_list");
|
||||
let tagDivID = tagDiv.prop("id");
|
||||
// console.log(tagDivIDName);
|
||||
|
||||
return tagDivID;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
class MaestroListNavigator {
|
||||
|
||||
constructor(pageNoArea) {
|
||||
let self = this;
|
||||
this.pageNoArea = pageNoArea;
|
||||
// console.log(parent);
|
||||
|
||||
this.activePageNo = 1;
|
||||
this.lastPageNo = 1;
|
||||
}
|
||||
|
||||
updateNavigator(activePageNo, lastPageNo) {
|
||||
this.activePageNo = activePageNo;
|
||||
this.lastPageNo = lastPageNo;
|
||||
// this.lastPageNo = Math.ceil( (maestroCount + 1) / 10 );
|
||||
|
||||
$(this.pageNoArea).empty();
|
||||
|
||||
for(let pageNo = 1; pageNo < this.lastPageNo + 1; pageNo++) {
|
||||
$(this.pageNoArea).append(
|
||||
"<a onClick='onClickMaestroListPage(this, " + pageNo + ")'> " + pageNo + " </a>"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
onClickMaestroListPage(pageNo) {
|
||||
switch(pageNo) {
|
||||
case "first":
|
||||
this.activePageNo = 1;
|
||||
this.maestroList.loadMaestroListPage(this.activePageNo);
|
||||
return;
|
||||
|
||||
case "prev":
|
||||
if(this.activePageNo > 1)
|
||||
this.activePageNo -= 1;
|
||||
this.maestroList.loadMaestroListPage(this.activePageNo);
|
||||
return;
|
||||
|
||||
case "next":
|
||||
if(this.activePageNo < this.lastPageNo)
|
||||
this.activePageNo += 1;
|
||||
this.maestroList.loadMaestroListPage(this.activePageNo);
|
||||
return;
|
||||
|
||||
case "last":
|
||||
this.maestroList.loadMaestroListPage(this.lastPageNo);
|
||||
return;
|
||||
}
|
||||
|
||||
this.activePageNo = pageNo;
|
||||
this.maestroList.loadMaestroListPage(this.activePageNo);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user