Add booking type options and enhance booking logic in terminplan.html; create test for terminplan endpoint
This commit is contained in:
@@ -51,6 +51,8 @@
|
|||||||
<label for="booking-type">Reservierungstyp:</label>
|
<label for="booking-type">Reservierungstyp:</label>
|
||||||
<select id="booking-type" name="booking_type">
|
<select id="booking-type" name="booking_type">
|
||||||
<option value="single">Einzeltermin</option>
|
<option value="single">Einzeltermin</option>
|
||||||
|
<option value="range">Zeitraum</option>
|
||||||
|
<option value="recurring">Wiederkehrend</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -624,6 +626,7 @@ document.addEventListener('DOMContentLoaded', function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const userId = document.getElementById('user-id').value || 'Admin'; // Get user ID or use fallback
|
const userId = document.getElementById('user-id').value || 'Admin'; // Get user ID or use fallback
|
||||||
|
const bookingType = document.getElementById('booking-type').value;
|
||||||
|
|
||||||
// Convert JSON data to FormData
|
// Convert JSON data to FormData
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
@@ -631,16 +634,43 @@ document.addEventListener('DOMContentLoaded', function() {
|
|||||||
// Add all required fields with correct names the server expects
|
// Add all required fields with correct names the server expects
|
||||||
formData.append('item_id', itemId);
|
formData.append('item_id', itemId);
|
||||||
formData.append('booking_date', startDate);
|
formData.append('booking_date', startDate);
|
||||||
formData.append('booking_end_date', startDate); // For single bookings, end = start
|
|
||||||
formData.append('period_start', periodStart);
|
formData.append('period_start', periodStart);
|
||||||
formData.append('period_end', periodEnd);
|
formData.append('period_end', periodEnd);
|
||||||
formData.append('notes', document.getElementById('booking-notes').value || '');
|
formData.append('notes', document.getElementById('booking-notes').value || '');
|
||||||
formData.append('booking_type', document.getElementById('booking-type').value);
|
|
||||||
formData.append('user_id', userId);
|
formData.append('user_id', userId);
|
||||||
|
|
||||||
|
if (bookingType === 'range') {
|
||||||
|
const endDate = document.getElementById('booking-end-date').value;
|
||||||
|
if (!endDate) {
|
||||||
|
alert('Bitte wählen Sie ein Enddatum für den Zeitraum.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
formData.append('booking_end_date', endDate);
|
||||||
|
formData.append('booking_type', 'range');
|
||||||
|
} else if (bookingType === 'recurring') {
|
||||||
|
formData.append('booking_type', 'single'); // Server expects 'single' structure for these individually sent requests
|
||||||
|
const dates = calculateDates();
|
||||||
|
if (dates.length === 0) {
|
||||||
|
alert('Es konnten keine Termine berechnet werden. Bitte überprüfen Sie Ihre Eingaben.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (confirm(`Möchten Sie wirklich ${dates.length} Termine planen?`)) {
|
||||||
|
processMultipleDates(formData, dates, periodStart, periodEnd);
|
||||||
|
}
|
||||||
|
return; // Use processMultipleDates instead
|
||||||
|
} else {
|
||||||
|
formData.append('booking_end_date', startDate); // For single bookings, end = start
|
||||||
|
formData.append('booking_type', 'single');
|
||||||
|
}
|
||||||
|
|
||||||
|
const csrfToken = document.querySelector('meta[name="csrf-token"]') ? document.querySelector('meta[name="csrf-token"]').content : '';
|
||||||
|
|
||||||
// Submit with FormData instead of JSON
|
// Submit with FormData instead of JSON
|
||||||
fetch('/plan_booking', {
|
fetch('/plan_booking', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'X-CSRFToken': csrfToken
|
||||||
|
},
|
||||||
body: formData // Remove the Content-Type header and JSON.stringify
|
body: formData // Remove the Content-Type header and JSON.stringify
|
||||||
})
|
})
|
||||||
.then(response => {
|
.then(response => {
|
||||||
@@ -681,8 +711,12 @@ document.addEventListener('DOMContentLoaded', function() {
|
|||||||
// Cancel booking
|
// Cancel booking
|
||||||
document.getElementById('cancel-booking').addEventListener('click', function() {
|
document.getElementById('cancel-booking').addEventListener('click', function() {
|
||||||
if (confirm('Möchten Sie diese Ausleihe wirklich stornieren?')) {
|
if (confirm('Möchten Sie diese Ausleihe wirklich stornieren?')) {
|
||||||
|
const csrfToken = document.querySelector('meta[name="csrf-token"]') ? document.querySelector('meta[name="csrf-token"]').content : '';
|
||||||
fetch('/cancel_booking/' + currentEventId, {
|
fetch('/cancel_booking/' + currentEventId, {
|
||||||
method: 'POST'
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'X-CSRFToken': csrfToken
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(data => {
|
.then(data => {
|
||||||
@@ -1131,8 +1165,12 @@ document.addEventListener('DOMContentLoaded', function() {
|
|||||||
newFormData.get('end_date'));
|
newFormData.get('end_date'));
|
||||||
|
|
||||||
// Submit this booking
|
// Submit this booking
|
||||||
|
const csrfToken = document.querySelector('meta[name="csrf-token"]') ? document.querySelector('meta[name="csrf-token"]').content : '';
|
||||||
fetch('/plan_booking', {
|
fetch('/plan_booking', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'X-CSRFToken': csrfToken
|
||||||
|
},
|
||||||
body: newFormData
|
body: newFormData
|
||||||
})
|
})
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
from app import app
|
||||||
|
with app.test_client() as client:
|
||||||
|
with client.session_transaction() as sess:
|
||||||
|
sess['username'] = 'admin'
|
||||||
|
sess['admin'] = True
|
||||||
|
resp = client.get('/terminplan')
|
||||||
|
print("Status:", resp.status_code)
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
from Web.app import app
|
||||||
|
with app.test_client() as client:
|
||||||
|
resp = client.get('/terminplan')
|
||||||
|
print(resp.status_code)
|
||||||
|
# print(resp.data.decode('utf-8')[:200])
|
||||||
Reference in New Issue
Block a user