Gitlab@Informatics

Skip to content
Snippets Groups Projects
Commit 4ff2ea28 authored by 65160024's avatar 65160024
Browse files

update confirm loan

parent 92d8ac24
No related branches found
No related tags found
No related merge requests found
......@@ -43,17 +43,13 @@
<div class="flex justify-center space-x-4">
<!-- ฟอร์มยืนยันการยืม -->
<form action="/submit-loan" method="POST" class="flex space-x-2">
<input type="hidden" name="equipment_id" value="<%= equipment.id %>">
<input type="hidden" name="quantity" value="<%= quantity %>">
<button type="submit"
class="bg-blue-600 text-white px-6 py-3 rounded-md hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-blue-400">ยืนยันการยืม</button>
</form>
<button id="confirmButton" class="bg-blue-600 text-white px-6 py-3 rounded-md hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-blue-400">
ยืนยันการยืม
</button>
<!-- ฟอร์มยกเลิกการยืม -->
<form action="/cancel-loan" method="GET" class="flex space-x-2">
<button type="submit"
class="bg-gray-300 text-gray-800 px-6 py-3 rounded-md hover:bg-gray-400 focus:outline-none focus:ring-2 focus:ring-gray-400">ยกเลิก</button>
<button type="submit" class="bg-gray-300 text-gray-800 px-6 py-3 rounded-md hover:bg-gray-400 focus:outline-none focus:ring-2 focus:ring-gray-400">ยกเลิก</button>
</form>
</div>
</div>
......@@ -64,6 +60,37 @@
</div>
<% } %>
<script>
// เมื่อกดปุ่ม "ยืนยันการยืม" ให้เปลี่ยนเส้นทางไปยังหน้า /loans
document.getElementById('confirmButton').addEventListener('click', function() {
// ส่งข้อมูลยืมไปยังเซิร์ฟเวอร์ (ในกรณีที่ต้องการให้มีการบันทึกข้อมูลก่อน)
const equipment_id = "<%= equipment.id %>";
const quantity = "<%= quantity %>";
fetch('/submit-loan', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
equipment_id: equipment_id,
quantity: quantity
})
})
.then(response => {
if (response.ok) {
// หลังจากยืนยันเสร็จแล้วเปลี่ยนเส้นทางไปที่ /loans
window.location.href = '/loans';
} else {
alert('การยืมอุปกรณ์ล้มเหลว');
}
})
.catch(error => {
alert('เกิดข้อผิดพลาด: ' + error);
});
});
</script>
</body>
</html>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment