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; } }