Spaces:
Sleeping
Sleeping
File size: 7,075 Bytes
42a477c 3b0c90a 42a477c a953942 3b0c90a 42a477c a953942 3b0c90a d14c362 3b0c90a 42a477c 3b0c90a 4587ee9 3b0c90a d14c362 3b0c90a 42a477c 3b0c90a 4587ee9 42a477c 3b0c90a 4242ae5 42a477c 3b0c90a 42a477c 3b0c90a 42a477c 3b0c90a 42a477c 3b0c90a 42a477c 3b0c90a 42a477c 4587ee9 3b0c90a 42a477c 3b0c90a 42a477c 3b0c90a 6bbca28 4242ae5 6bbca28 a407bd4 3b0c90a 42a477c 3b0c90a 42a477c 3b0c90a 4242ae5 3b0c90a 4242ae5 3b0c90a 4242ae5 3b0c90a 42a477c 3b0c90a 42a477c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{{ page_title }}</title>
<style>
body { font-family: Arial, sans-serif; max-width: 600px; margin: 0 auto; padding: 20px; }
select, input, button { margin: 10px 0; padding: 5px; }
#message { margin-top: 20px; font-weight: bold; }
</style>
</head>
<body>
<h1>{{ page_title }}</h1>
<h2>Buch zurückgeben</h2>
<input type="number" id="returnBookId" placeholder="Buchnummer eingeben">
<button onclick="returnBook()">Buch zurückgeben</button>
<h2>Buch ausleihen</h2>
<select id="groupSelect" onchange="loadStudents()">
<option value="">Gruppe auswählen</option>
</select>
<select id="studentSelect" onchange="loadOutstandingBooks()">
<option value="">Schüler auswählen</option>
</select>
<input type="number" id="borrowBookId" placeholder="Buchnummer eingeben">
<button onclick="borrowBook()">Buch ausleihen</button>
<div id="message"></div>
<div id="outstandingBooks"></div>
<script>
// Load groups when the page loads
window.onload = function() {
loadGroups();
document.getElementById('returnBookId').addEventListener('keyup', function(event) {
if (event.key === 'Enter') {
returnBook();
}
});
document.getElementById('borrowBookId').addEventListener('keyup', function(event) {
if (event.key === 'Enter') {
borrowBook();
}
});
};
function loadGroups() {
fetch('/groups')
.then(response => response.json())
.then(groups => {
const select = document.getElementById('groupSelect');
// Add "Alle Gruppen" option
const allGroupsOption = document.createElement('option');
allGroupsOption.value = "all";
allGroupsOption.textContent = "Alle Gruppen";
select.appendChild(allGroupsOption);
// Add other groups
groups.forEach(group => {
const option = document.createElement('option');
option.value = group.idGruppe;
option.textContent = group.Gruppe;
select.appendChild(option);
});
});
}
function loadStudents() {
const groupId = document.getElementById('groupSelect').value;
if (!groupId) return;
let url = groupId === 'all' ? '/students/all' : `/students/${groupId}`;
fetch(url)
.then(response => response.json())
.then(students => {
const select = document.getElementById('studentSelect');
select.innerHTML = '<option value="">Schüler auswählen</option>';
students.forEach(student => {
const option = document.createElement('option');
option.value = student.idKind;
option.textContent = student.Kind;
select.appendChild(option);
});
// Clear outstanding books when changing students
document.getElementById('outstandingBooks').innerHTML = '';
});
}
function loadOutstandingBooks() {
const studentId = document.getElementById('studentSelect').value;
if (!studentId) {
document.getElementById('outstandingBooks').innerHTML = '';
return;
}
fetch(`/borrowed/${studentId}`)
.then(response => response.json())
.then(books => {
const outstandingBooksDiv = document.getElementById('outstandingBooks');
if (books.length === 0) {
outstandingBooksDiv.innerHTML = '<p>Keine ausstehenden Bücher</p>';
} else {
let html = '<h3>Ausstehende Bücher:</h3><ul>';
books.forEach(book => {
const borrowDate = new Date(book.ausleihe).toLocaleDateString('de-DE');
html += `<li>Buch ID: ${book.idBuch}, Ausgeliehen am: ${borrowDate}</li>`;
});
html += '</ul>';
outstandingBooksDiv.innerHTML = html;
}
});
}
function returnBook() {
const bookId = document.getElementById('returnBookId').value;
if (!bookId) {
setMessage('Bitte geben Sie eine Buchnummer ein');
return;
}
fetch(`/return/${bookId}`)
.then(response => response.json())
.then(result => {
if (result.success) {
let message = `Buch (Nummer: ${bookId}) erfolgreich zurückgegeben.`;
if (result.student_names.length === 1) {
message += ` Ausgeliehen von: ${result.student_names[0]}`;
} else if (result.student_names.length > 1) {
message += ` Ausgeliehen von: ${result.student_names.join(', ')}`;
}
setMessage(message);
document.getElementById('returnBookId').value = ''; // Clear input field
} else {
setMessage(`Buch (Nummer: ${bookId}) nicht zurückgegeben. ` + result.message);
}
});
}
function borrowBook() {
const studentId = document.getElementById('studentSelect').value;
const bookId = document.getElementById('borrowBookId').value;
if (!studentId || !bookId) {
setMessage('Bitte wählen Sie einen Schüler aus und geben Sie eine Buchnummer ein');
return;
}
fetch(`/borrow/${bookId}/${studentId}`)
.then(response => response.json())
.then(result => {
if (result.success) {
setMessage(`Buch (Nummer: ${bookId}) erfolgreich ausgeliehen`);
document.getElementById('borrowBookId').value = ''; // Clear input field
} else {
setMessage('Fehler beim Ausleihen des Buches: ' + result.message);
}
// Refresh the outstanding books list
loadOutstandingBooks();
});
}
function setMessage(msg) {
document.getElementById('message').textContent = msg;
}
</script>
</body>
</html>
|