diff --git a/frontend/main.ts b/frontend/main.ts index 6fa0a27..810d61d 100644 --- a/frontend/main.ts +++ b/frontend/main.ts @@ -49,10 +49,10 @@ function selectBoatChange() { )[0]; const rowers = Number(originalOption.dataset.amount_seats) - 1; - - setMaxAmountRowers(rowers); - - + const isShipmasterSteering = originalOption.dataset.default_shipmaster_only_steering; + + setMaxAmountRowers(rowers,isShipmasterSteering); + return opt; } } @@ -91,7 +91,7 @@ function reloadPage() { }); } -function setMaxAmountRowers(rowers: number){ +function setMaxAmountRowers(rowers: number, isShipmasterSteering='false') { let curSelection = choiceObjects['newrower'].getValue(true); let amount_to_delete = (curSelection).length - rowers; if (amount_to_delete > 0){ @@ -102,14 +102,24 @@ function setMaxAmountRowers(rowers: number){ } choiceObjects['newrower'].config.maxItemCount = rowers; - const only_steering = document.querySelector('#shipmaster_only_steering'); if (rowers === 0) { - choiceObjects['newrower'].disable() - only_steering.disabled = true; + choiceObjects['newrower'].disable() }else{ - choiceObjects['newrower'].enable() - only_steering.disabled = false; + choiceObjects['newrower'].enable() } + + let only_steering = document.querySelector('#shipmaster_only_steering'); + if(only_steering) { + if(isShipmasterSteering == 'true') { + only_steering.removeAttribute('disabled'); + only_steering.setAttribute('checked', 'true'); + only_steering.parentElement?.parentElement?.parentElement?.classList.remove('opacity-50'); + } else { + only_steering.setAttribute('disabled', 'disabled'); + only_steering.removeAttribute('checked'); + only_steering.parentElement?.parentElement?.parentElement?.classList.add('opacity-50'); + } + } } function initBoatActions() { @@ -119,20 +129,21 @@ function initBoatActions() { select.addEventListener('click', function() { if(select.dataset.seats) { const rowers = Number(select.dataset.seats) - 1; + const isShipmasterSteering = select.dataset.default_shipmaster_only_steering; - setMaxAmountRowers(rowers); - - if (select.dataset.id) { - choiceObjects['boat_id'].setChoiceByValue(select.dataset.id); - } + setMaxAmountRowers(rowers, isShipmasterSteering); + + if (select.dataset.id) { + choiceObjects['boat_id'].setChoiceByValue(select.dataset.id); + } - window.scrollTo(0, 0); + window.scrollTo(0, 0); - const inputElement = document.getElementById("departure") as HTMLInputElement; - const now = new Date(); - const formattedDateTime = `${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, '0')}-${String(now.getDate()).padStart(2, '0')}T${String(now.getHours()).padStart(2, '0')}:${String(now.getMinutes()).padStart(2, '0')}`; - - inputElement.value = formattedDateTime; + const inputElement = document.getElementById("departure") as HTMLInputElement; + const now = new Date(); + const formattedDateTime = `${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, '0')}-${String(now.getDate()).padStart(2, '0')}T${String(now.getHours()).padStart(2, '0')}:${String(now.getMinutes()).padStart(2, '0')}`; + + inputElement.value = formattedDateTime; } }); }); diff --git a/templates/includes/forms/log.html.tera b/templates/includes/forms/log.html.tera index 32d8a74..df88d4d 100644 --- a/templates/includes/forms/log.html.tera +++ b/templates/includes/forms/log.html.tera @@ -13,7 +13,7 @@ {{ amount_seats }}x {% for boat in grouped_boats %} -
+
{{ boat.name }} {% if boat.owner %} @@ -28,11 +28,11 @@ {# Shows the form for creating a new logbook entry. #} {% macro new(only_ones, allow_any_shipmaster, shipmaster) %} -
+ {{ log::boat_select(only_ones=only_ones) }} {% if allow_any_shipmaster %} -
+
{% endif %} {% if not only_ones %} - {{ macros::checkbox(label='handgesteuert', name='shipmaster_only_steering') }} +
+
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-2", init=true) }} + {{ log::rower_select(id="newrower", selected=[], class="col-span-4", init=true) }} {% endif %} - {{ macros::input(label='Abfahrtszeit', name='departure', type='datetime-local', required=true) }} - {{ macros::input(label='Ankunftszeit', name='arrival', type='datetime-local') }} + {{ 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') }} -
+
@@ -81,26 +86,26 @@
-
+
{{ 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-2") }} + {{ 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-2") }} + {{ macros::select(label="Typ", data=logtypes, name='logtype', default="Normal", wrapper_class="col-span-4") }} - + {% endmacro new %} {% macro boat_select(only_ones) %} {% if not only_ones %} - {{ macros::select(label="Boot", data=boats, name='boat_id', display=["name", " (","amount_seats", " x)"], extras=["default_shipmaster_only_steering", "amount_seats", "on_water"], wrapper_class="col-span-2") }} + {{ macros::select(label="Boot", data=boats, name='boat_id', display=["name", " (","amount_seats", " x)"], extras=["default_shipmaster_only_steering", "amount_seats", "on_water"], wrapper_class="col-span-4") }} {% else %} {% set ones = boats | filter(attribute="amount_seats", value=1) %} - {{ macros::select(label="Boot", data=ones, name='boat_id', display=["name", " (","amount_seats", " x)"], extras=["default_shipmaster_only_steering", "amount_seats", "on_water"], wrapper_class="col-span-2") }} + {{ macros::select(label="Boot", data=ones, name='boat_id', display=["name", " (","amount_seats", " x)"], extras=["default_shipmaster_only_steering", "amount_seats", "on_water"], wrapper_class="col-span-4") }} {% endif %} {% endmacro boat_select %} diff --git a/templates/includes/macros.html.tera b/templates/includes/macros.html.tera index 50e2bb0..742a084 100644 --- a/templates/includes/macros.html.tera +++ b/templates/includes/macros.html.tera @@ -67,9 +67,9 @@
{% endmacro input %} -{% macro checkbox(label, name, id='', checked=false, class='') %} +{% macro checkbox(label, name, id='', checked=false, class='', disabled=false) %} {% endmacro checkbox %}