diff --git a/.env b/.env index 869ed1ff77bdb3831b47f587cc44650fcbf7ef9f..20f2165ac82ab9eaede93d4f575f14d745453c73 100644 --- a/.env +++ b/.env @@ -1,6 +1,6 @@ PORT=8080 -DB_HOST=10.104.21.172 +DB_HOST=localhost DB_USER=root -DB_PASS=MECyve10150 +DB_PASS= DB_NAME=repair_system -JWT_SECRET=chanut + diff --git a/public/edit_report.html b/public/edit_report.html index 0ff0cc9f124fb875f7ce88dde1f8a791eaafd2a5..260495678fb31da641066301468d83b596cd2839 100644 --- a/public/edit_report.html +++ b/public/edit_report.html @@ -9,7 +9,6 @@ <!-- Custom CSS --> <style> - /* เอฟเฟกต์กระพริบ */ @keyframes blinking { 0% { opacity: 1; } 50% { opacity: 0; } @@ -21,7 +20,6 @@ </style> </head> <body class="bg-light"> - <div class="container d-flex flex-column justify-content-center align-items-center min-vh-100"> <!-- ข้อความ IF-REPAIRS ด้านนอก Card --> <h1 class="text-center blinking mb-4" style="font-size: 2.5rem;"> @@ -31,7 +29,6 @@ <!-- Card สำหรับฟอร์มแก้ไข --> <div class="card p-4 shadow" style="width: 100%; max-width: 500px;"> <h2 class="card-title text-center mb-4">แก้ไขรายการแจ้งซ่อม</h2> - <form id="editReportForm"> <input type="hidden" id="reportId"> @@ -46,7 +43,26 @@ <label for="editDescription" class="form-label">รายละเอียด:</label> <textarea id="editDescription" class="form-control" rows="3" required></textarea> </div> - + + <!-- Dropdown เลือกชั้น --> + <div class="mb-3"> + <label for="floor" class="form-label">เลือกชั้น:</label> + <select id="floor" class="form-select" onchange="loadRooms();"> + <option value="">-- กรุณาเลือกชั้น --</option> + <option value="2">ชั้น 2</option> + <option value="3">ชั้น 3</option> + <option value="4">ชั้น 4</option> + </select> + </div> + + <!-- Dropdown เลือกห้อง --> + <div class="mb-3"> + <label for="room" class="form-label">เลือกห้อง:</label> + <select id="room" class="form-select"> + <option value="">-- กรุณาเลือกห้อง --</option> + </select> + </div> + <!-- ปุ่มยืนยันการแก้ไข / ยกเลิก --> <div class="d-grid gap-2"> <button type="submit" class="btn btn-primary">ยืนยันการแก้ไข</button> diff --git a/public/script.js b/public/script.js index 79e945b4ea430360b418149a176a7683e0d58cb4..00318648eede01c452d95cb494ead4ad1f0dae27 100644 --- a/public/script.js +++ b/public/script.js @@ -79,11 +79,12 @@ function goToReportForm() { // ==================== // 🔹 โหลดห้องเรียนตามชั้นที่เลือก (สำหรับ report_form.html หรือ dashboard.html) -function loadRooms() { +function loadRooms(callback) { const floor = document.getElementById("floor").value; const roomSelect = document.getElementById("room"); if (!floor) { roomSelect.innerHTML = '<option value="">-- กรุณาเลือกห้อง --</option>'; + if(callback) callback(); return; } fetch(`${API_URL}/reports/rooms/${floor}`, { @@ -99,10 +100,15 @@ function loadRooms() { } else { roomSelect.innerHTML = '<option value="">ไม่มีห้องในชั้นนี้</option>'; } + if(callback) callback(); }) - .catch(error => console.error("❌ Load Rooms Error:", error)); + .catch(error => { + console.error("❌ Load Rooms Error:", error); + if(callback) callback(); + }); } + // 🔹 โหลดรายการแจ้งซ่อม (กรองตาม search, floor, และ room) function loadReports() { const searchTerm = document.getElementById("search") ? document.getElementById("search").value.toLowerCase() : ""; @@ -185,40 +191,18 @@ function loadEditReport() { document.getElementById("reportId").value = report.id; document.getElementById("editTitle").value = report.title; document.getElementById("editDescription").value = report.description; + // ตั้งค่า dropdown ชั้น และโหลดรายการห้อง จากนั้นตั้งค่าห้องให้ตรงกับ report + if(document.getElementById("floor")){ + document.getElementById("floor").value = report.floor; + loadRooms(function(){ + if(document.getElementById("room")) + document.getElementById("room").value = report.room_id; + }); + } }) .catch(error => console.error("❌ Load Report Error:", error)); } -document.getElementById("editReportForm")?.addEventListener("submit", function(event) { - event.preventDefault(); - - const reportId = document.getElementById("reportId").value; - const title = document.getElementById("editTitle").value; - const description = document.getElementById("editDescription").value; - - fetch(`${API_URL}/reports/${reportId}`, { - method: "PUT", - headers: { - "Content-Type": "application/json", - "Authorization": `Bearer ${localStorage.getItem("token")}` - }, - body: JSON.stringify({ title, description }) - }) - .then(res => res.json()) - .then(data => { - alert(data.message); - window.location.href = "dashboard.html"; - }) - .catch(error => console.error("❌ Update Report Error:", error)); -}); - -function cancelEdit() { - window.location.href = "dashboard.html"; -} - -if (window.location.pathname.includes("edit_report.html")) { - loadEditReport(); -} // 🔹 ส่งข้อมูลแจ้งซ่อม (สำหรับ report_form.html) @@ -255,7 +239,10 @@ function submitReport() { alert("เกิดข้อผิดพลาด กรุณาลองใหม่"); } }) - .catch(error => console.error("❌ API Error:", error)); + .catch(error => { + console.error("❌ Load Report Error:", error); + alert("เกิดข้อผิดพลาดในการโหลดข้อมูลแจ้งซ่อม"); + }); } // 🔹 ยกเลิกการแจ้งซ่อม (สำหรับ report_form.html)