This commit is contained in:
Dvorinka
2025-06-20 09:27:56 +02:00
parent 6d1c95060b
commit d5d2bdf9cd
2 changed files with 95 additions and 9 deletions
+86
View File
@@ -4955,6 +4955,92 @@ async function saveReservation(event) {
}
}
// Function to load and display reservations
function loadReservations() {
fetch('/api/reservations')
.then(response => response.json())
.then(data => {
const reservations = data.reservations || [];
displayReservations(reservations);
updateVehicleFilter(reservations);
})
.catch(error => {
console.error('Error loading reservations:', error);
showNotification('Nepodařilo se načíst rezervace', 'error');
});
}
// Function to display reservations
function displayReservations(reservations) {
const reservationsContainer = document.getElementById('reservationsContainer');
if (!reservationsContainer) return;
// Clear existing content
reservationsContainer.innerHTML = '';
if (reservations.length === 0) {
// Show no reservations message
const noReservations = document.createElement('div');
noReservations.className = 'text-center py-6 text-gray-500';
noReservations.innerHTML = 'Zatím nebyly vytvořeny žádné rezervace.';
reservationsContainer.appendChild(noReservations);
return;
}
// Sort reservations by date
reservations.sort((a, b) => new Date(a.date) - new Date(b.date));
// Add table header
const table = document.createElement('table');
table.className = 'min-w-full divide-y divide-gray-200';
const thead = document.createElement('thead');
thead.className = 'bg-gray-50';
const headerRow = document.createElement('tr');
const headers = ['Datum', 'Čas', 'Vozidlo', 'Jméno', 'Telefon', 'Email', 'Délka', 'Akce'];
headers.forEach(header => {
const th = document.createElement('th');
th.className = 'px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider';
th.textContent = header;
headerRow.appendChild(th);
});
thead.appendChild(headerRow);
table.appendChild(thead);
// Add table body
const tbody = document.createElement('tbody');
tbody.className = 'bg-white divide-y divide-gray-200';
// Add reservations
reservations.forEach(reservation => {
const row = document.createElement('tr');
row.className = 'hover:bg-gray-50';
// Add cells
const cells = [
formatDateTime(reservation.date, reservation.time),
reservation.vehicle,
reservation.name,
reservation.phone,
reservation.email,
calculateDuration(reservation),
'<button onclick="editReservation(\'' + reservation.id + '\')" class="text-blue-600 hover:text-blue-900">Upravit</button> '
];
cells.forEach(cellContent => {
const cell = document.createElement('td');
cell.className = 'px-6 py-4 whitespace-nowrap text-sm text-gray-900';
cell.innerHTML = cellContent;
row.appendChild(cell);
});
tbody.appendChild(row);
});
table.appendChild(tbody);
reservationsContainer.appendChild(table);
}
// Add event listeners when the page loads
document.addEventListener('DOMContentLoaded', function() {
// Initialize filters