diff --git a/Web/modules/terminplaner/blueprint.py b/Web/modules/terminplaner/blueprint.py index 3a965ac..70af9dd 100644 --- a/Web/modules/terminplaner/blueprint.py +++ b/Web/modules/terminplaner/blueprint.py @@ -37,7 +37,7 @@ def _current_tenant_id(): @appoint_bp.route('/client/', methods=['POST', 'GET']) def client(appointment_id): """ - The Route for the terminplaner to work with the client + The Route for the terminplaner to work with the client and allow owners to manage it. """ guard = _require_module_enabled() if guard: @@ -74,35 +74,60 @@ def client(appointment_id): available_for_view['slots_booked'] = sanitized_bookings if request.method == 'POST': - start_daytime = request.form.get('start_day_time') - username = request.form.get('client_name') - - custom_answers = request.form.getlist('custom_answers') + action = request.form.get('action', 'book') - if not start_daytime or not username: - flash('Bitte Name und gewünschte Uhrzeit angeben.', 'error') - return render_template( - 'termin_client.html', - appointment_id=appointment_id, - available=available_for_view, - current_user=session.get('username', ''), - tenant_id=_current_tenant_id(), - can_view_booking_names=can_view_booking_names, - custom_fields=custom_fields - ) + # Fall 1: ADMIN/AUTOR storniert einen Termin + if action == 'delete' and can_view_booking_names: + slot_time = request.form.get('slot_time') + client_name = request.form.get('target_client_name') + + # Aktuelle Buchungen direkt aus dem DB-Item holen + current_slots = appointment_item.get('slots_booked', []) or [] + + # Filtere den zu löschenden Slot heraus (Prüfung auf Zeit und Name) + updated_slots = [ + slot for slot in current_slots + if not (isinstance(slot, (list, tuple)) and slot[0] == slot_time and slot[1] == client_name) + ] + + # In DB schreiben via deiner existierenden termin.update() Funktion + if termin.update(appointment_id, updated_slots): + flash('Buchung wurde erfolgreich gelöscht.', 'success') + else: + flash('Fehler beim Löschen der Buchung.', 'error') + + return redirect(url_for('terminplaner.client', appointment_id=appointment_id, tenant=_current_tenant_id() or None)) - if appointment_service.book_slot(appointment_id, start_daytime, username, custom=custom_answers): - return redirect( - url_for( - 'terminplaner.client_success', + # Fall 2: NORMALER CLIENT bucht einen Termin + elif action == 'book': + start_daytime = request.form.get('start_day_time') + username = request.form.get('client_name') + custom_answers = request.form.getlist('custom_answers') + + if not start_daytime or not username: + flash('Bitte Name und gewünschte Uhrzeit angeben.', 'error') + return render_template( + 'termin_client.html', appointment_id=appointment_id, - tenant=_current_tenant_id() or None, - start=start_daytime, - name=username, + available=available_for_view, + current_user=session.get('username', ''), + tenant_id=_current_tenant_id(), + can_view_booking_names=can_view_booking_names, + custom_fields=custom_fields ) - ) - flash('Der Termin konnte nicht gespeichert werden.', 'error') + if appointment_service.book_slot(appointment_id, start_daytime, username, custom=custom_answers): + return redirect( + url_for( + 'terminplaner.client_success', + appointment_id=appointment_id, + tenant=_current_tenant_id() or None, + start=start_daytime, + name=username, + ) + ) + + flash('Der Termin konnte nicht gespeichert werden.', 'error') return render_template( 'termin_client.html', diff --git a/Web/templates/termin_client.html b/Web/templates/termin_client.html index ff374d7..64ef825 100644 --- a/Web/templates/termin_client.html +++ b/Web/templates/termin_client.html @@ -39,13 +39,14 @@
+

Terminplaner

- {% if 'username' in session %} + {% if can_view_booking_names %}

Termin Übersicht - {{ available.title }}

-

Hier können sie alle Buchungen die Bereits eingegenagen sind verwalten.

+

Hier können Sie alle Buchungen, die bereits eingegangen sind, einsehen und verwalten.

{% else %}

Termin buchen - {{ available.title }}

Wählen Sie im Kalender einen freien Slot aus. Den gewählten Termin können Sie danach direkt wie in einem Kalender-Block verschieben.

@@ -64,7 +65,7 @@
{{ available.slot_lenght }} Minuten
- {% if 'username' in session %} + {% if not can_view_booking_names %}
Gewählter Termin
Noch kein Slot ausgewählt.
@@ -74,14 +75,13 @@ {% if available.slots_booked %}
Bereits gebucht
-
    +
      {% for booking in available.slots_booked %}
    • - {{ booking.start }} - {% if can_view_booking_names and booking.name %} - - {{ booking.name }} + {% if booking is mapping %} + {{ booking.get('start', '') }} - Belegt {% else %} - - Belegt + {{ booking[0] }} - {% if can_view_booking_names %}{{ booking[1] }}{% else %}Belegt{% endif %} {% endif %}
    • {% endfor %} @@ -91,60 +91,90 @@
+
{% if can_view_booking_names %} - -
-

Eingegangene Buchungen

- - {{ available.slots_total - available.slots_left }} Gebucht +
+
+

Eingegangene Buchungen

+
Verwalten Sie die Termine Ihrer Klienten
+
+ + {{ available.slots_total - available.slots_left }} von {{ available.slots_total }} belegt
+
+
+
+ + +
+
+ +
+
+
+ {% if available.slots_booked %}
- +
- {% for field_label in custom_fields %} {% endfor %} + - + {% for booking in available.slots_booked %} - - - - - {% if booking|length > 2 and booking[2] %} - {% for answer in booking[2] %} - - {% endfor %} - {% else %} - - {% for field in custom_fields %} - - {% endfor %} + {% if booking is not mapping %} + + + + + {% if booking|length > 2 and booking[2] %} + {% for answer in booking[2] %} + + {% endfor %} + {% else %} + {% for field in custom_fields %} + + {% endfor %} + {% endif %} + + + {% endif %} - {% endfor %}
Zeitpunkt Name{{ field_label }}Aktion
- {{ booking[0] }} - - {{ booking[1] }} - {{ answer if answer else '-'|safe }}-
+ {{ booking[0] }} + + {{ booking[1] }} + {{ answer if answer else '-'|safe }}- +
+ + + + +
+
+ +
+ Keine Buchungen entsprechen Ihrem Filter. +
{% else %}
-

Bisher sind noch keine Buchungen für diesen Terminplaner eingegangen.

{% endif %} @@ -154,7 +184,6 @@
{% else %} -

Termin im Kalender auswählen

@@ -188,6 +217,7 @@ {% endif %}
+ Zur Übersicht
@@ -197,6 +227,7 @@
+
@@ -222,6 +253,52 @@
+