mirror of
https://github.com/Dvorinka/PPve.git
synced 2026-06-04 04:22:58 +00:00
test ad
This commit is contained in:
+37
-29
@@ -4627,22 +4627,26 @@ async function deleteReservation(id) {
|
||||
if (!confirm('Opravdu chcete smazat tuto rezervaci?')) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
const response = await fetch(`/api/delete-reservation`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({ id: id })
|
||||
});
|
||||
|
||||
const result = await response.json();
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(result.error || 'Nepodařilo se smazat rezervaci');
|
||||
const token = localStorage.getItem('token');
|
||||
if (!token) {
|
||||
window.location.href = '/login.html';
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
const response = await fetch(`/api/reservations/${id}`, {
|
||||
method: 'DELETE',
|
||||
headers: {
|
||||
'Authorization': `Bearer ${token}`,
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error('Nepodařilo se smazat rezervaci');
|
||||
}
|
||||
|
||||
// Remove the reservation from the local array and update the display
|
||||
window.allReservations = window.allReservations.filter(r => r.id !== id);
|
||||
updateVehicleFilter(window.allReservations);
|
||||
@@ -4700,29 +4704,32 @@ async function saveReservation(event) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Create ISO date strings
|
||||
const start = new Date(`${startDate}T${startTime}`).toISOString();
|
||||
const end = new Date(`${endDate}T${endTime}`).toISOString();
|
||||
|
||||
try {
|
||||
const response = await fetch('/api/update-reservation', {
|
||||
method: 'POST',
|
||||
const token = localStorage.getItem('token');
|
||||
if (!token) {
|
||||
window.location.href = '/login.html';
|
||||
return;
|
||||
}
|
||||
|
||||
const response = await fetch(`/api/reservations/${id}`, {
|
||||
method: 'PUT',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': `Bearer ${token}`,
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({
|
||||
id,
|
||||
driverName,
|
||||
vehicle,
|
||||
start,
|
||||
end,
|
||||
startDate,
|
||||
startTime,
|
||||
endDate,
|
||||
endTime,
|
||||
purpose
|
||||
})
|
||||
});
|
||||
|
||||
const result = await response.json();
|
||||
|
||||
if (!response.ok) {
|
||||
const result = await response.json();
|
||||
throw new Error(result.error || 'Nepodařilo se uložit změny');
|
||||
}
|
||||
|
||||
@@ -4733,8 +4740,10 @@ async function saveReservation(event) {
|
||||
...window.allReservations[index],
|
||||
driverName,
|
||||
vehicle,
|
||||
start,
|
||||
end,
|
||||
startDate,
|
||||
startTime,
|
||||
endDate,
|
||||
endTime,
|
||||
purpose
|
||||
};
|
||||
|
||||
@@ -4792,7 +4801,6 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
|
||||
// Load reservations when page loads
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
// ...existing code...
|
||||
loadReservations();
|
||||
});
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user