From ccc9f76691e177bb023d078949159f35a364d613 Mon Sep 17 00:00:00 2001 From: philipp Date: Mon, 30 Oct 2023 09:21:35 +0100 Subject: [PATCH] do proper things in ui @ new log --- frontend/main.ts | 65 ++++++++++++++++++++------ templates/includes/forms/log.html.tera | 54 +++++---------------- 2 files changed, 63 insertions(+), 56 deletions(-) diff --git a/frontend/main.ts b/frontend/main.ts index f65bfe0..30c14ac 100644 --- a/frontend/main.ts +++ b/frontend/main.ts @@ -62,20 +62,8 @@ function selectBoatChange() { } } } as any); - - choiceObjects[boatSelect.id] = boatChoice; - } - const shipmasterSelect = document.querySelector('#shipmaster'); - if(shipmasterSelect) { - const shipmasterChoice = new Choices(shipmasterSelect, { - loadingText: 'Wird geladen...', - noResultsText: 'Keine Ergebnisse gefunden', - noChoicesText: 'Keine Ergebnisse gefunden', - itemSelectText: 'Zum Auswählen klicken', - }); - - choiceObjects[shipmasterSelect.id] = shipmasterChoice; + choiceObjects[boatSelect.id] = boatChoice; } } @@ -180,6 +168,16 @@ function initChoices() { } } +interface ChoiceEvent extends Event{ + detail: { + value: string; + label: string, + customProperties: { + is_cox: boolean, + } + }; +} + function initNewChoice(select: HTMLInputElement) { const choice = new Choices(select, { removeItemButton: true, @@ -194,9 +192,50 @@ function initNewChoice(select: HTMLInputElement) { }, }); + select.addEventListener('addItem', function(e) { + const event = e as ChoiceEvent; + const user_id = event.detail.value; + const name = event.detail.label; + + if (event.detail.customProperties.is_cox) { + const coxSelect = document.querySelector('#cox'); + if (coxSelect){ + coxSelect.add(new Option(name, user_id)); + } + } + + const steeringSelect = document.querySelector('#steering_person'); + if (steeringSelect) { + steeringSelect.add(new Option(name, user_id)); + } + },false); + + select.addEventListener('removeItem', function(e) { + const event = e as ChoiceEvent; + + const user_id = event.detail.value; + + const coxSelect = document.querySelector('#cox'); + if (coxSelect) { + for (var i=0; idocument.querySelector('#steering_person'); + if (steeringSelect) { + for (var i=0; i>document.querySelectorAll('.filter-trips-js'); diff --git a/templates/includes/forms/log.html.tera b/templates/includes/forms/log.html.tera index f9c802a..c2e8ce7 100644 --- a/templates/includes/forms/log.html.tera +++ b/templates/includes/forms/log.html.tera @@ -30,67 +30,35 @@ {% macro new(only_ones, shipmaster) %}
{{ log::boat_select(only_ones=only_ones) }} - -
- - - -
{% if not only_ones %} -
-
Bootssteuerung
-
- {{ macros::checkbox(label='handgesteuert', name='shipmaster_only_steering', disabled=true) }} -
-
+
+
Bootssteuerung
+
+ {{ macros::checkbox(label='handgesteuert', name='shipmaster_only_steering', disabled=true) }} +
+
{% endif %} - {% if not only_ones %} {{ log::rower_select(id="newrower", selected=[], class="col-span-4", init=true) }} {% endif %} - + {{ macros::select(label="Schiffsführer", data=[], name='cox', wrapper_class="col-span-2") }} + {{ macros::select(label="Steuerperson", data=[], name='steering_person', wrapper_class="col-span-2") }} {{ macros::input(label='Abfahrtszeit', name='departure', type='datetime-local', required=true, wrapper_class='col-span-2') }} {{ macros::input(label='Ankunftszeit', name='arrival', type='datetime-local', wrapper_class='col-span-2') }} -
- - {% for distance in distances %} -
-
{{ macros::input(label="Distanz", name="distance_in_km", id="distance_in_km" , type="number", min=0, value='', class="rounded-md") }} km
- {{ macros::input(label="Kommentar", name="comments", type="text", wrapper_class="col-span-4") }} - {{ macros::select(label="Typ", data=logtypes, name='logtype', default="Normal", wrapper_class="col-span-4") }} -
{% endmacro new %} @@ -108,7 +76,7 @@ {% macro rower_select(id, selected, amount_seats='', class='', init='false') %} {% if not amount_seats or amount_seats > 1 %}
- +