From 17422a78a00595ec6d7c33580b43748d102cb10e Mon Sep 17 00:00:00 2001 From: Marie Birner Date: Sat, 23 Sep 2023 21:51:00 +0200 Subject: [PATCH] [TASK] improve rower select --- frontend/main.ts | 17 +++++++++++ templates/includes/forms/log.html.tera | 41 ++++++++++++++++---------- templates/includes/macros.html.tera | 2 +- 3 files changed, 43 insertions(+), 17 deletions(-) diff --git a/frontend/main.ts b/frontend/main.ts index 4c1f938..c141f05 100644 --- a/frontend/main.ts +++ b/frontend/main.ts @@ -14,8 +14,24 @@ document.addEventListener('DOMContentLoaded', function() { replaceStrings(); initChoices(); initBoatActions(); + selectBoatChange(); }); +function selectBoatChange() { + const boatSelect = document.querySelector('#boat_id'); + if(boatSelect) { + boatSelect.addEventListener('change', function() { + const selectedElement = boatSelect as HTMLSelectElement; + const opt = selectedElement.options[selectedElement.selectedIndex]; + const selectedValue = (opt).dataset.amount_seats; + const rowers = Number(selectedValue) - 1; + choiceObjects['newrower'].config.maxItemCount = rowers; + choiceObjects['newrower'].removeActiveItems(rowers); + (rowers === 0 ? choiceObjects['newrower'].disable() : choiceObjects['newrower'].enable()) + }); + } +} + function initBoatActions() { const boatSelects = document.querySelectorAll('.boats-js[data-onclick="true"]'); if(boatSelects) { @@ -25,6 +41,7 @@ function initBoatActions() { const rowers = Number(select.dataset.seats) - 1; choiceObjects['newrower'].config.maxItemCount = rowers; choiceObjects['newrower'].removeActiveItems(rowers); + (rowers === 0 ? choiceObjects['newrower'].disable() : choiceObjects['newrower'].enable()); } }); }); diff --git a/templates/includes/forms/log.html.tera b/templates/includes/forms/log.html.tera index 3e37f7c..e60b5bb 100644 --- a/templates/includes/forms/log.html.tera +++ b/templates/includes/forms/log.html.tera @@ -104,19 +104,21 @@ {% endmacro boat_select %} {% macro rower_select(id, selected, amount_seats='', class='', init='false') %} -
- -
+ {% if not amount_seats or amount_seats > 1 %} +
+ +
+ {% endif %} {% endmacro rower_select %} {% macro show(log, state, allowed_to_close=false, only_ones) %} @@ -156,10 +158,10 @@ {{ log.destination }} {% endif %} - {% for cox in coxes %} - {% if cox.id == log.shipmaster %} + {% for user in users %} + {% if user.id == log.shipmaster %}

- {{ cox.name }} + {{ user.name }}

{% endif %} {% endfor %} @@ -222,6 +224,13 @@ {% macro home(log, only_ones) %}
+ {% for user in users %} + {% if user.id == log.shipmaster %} +

+ {{ user.name }} +

+ {% endif %} + {% endfor %} {% if not only_ones %} {{ log::rower_select(id="rowers"~log.id, selected=log.rowers, amount_seats=log.boat.amount_seats) }} {% endif %} diff --git a/templates/includes/macros.html.tera b/templates/includes/macros.html.tera index 585be2c..f1cbddf 100644 --- a/templates/includes/macros.html.tera +++ b/templates/includes/macros.html.tera @@ -83,7 +83,7 @@ {% endif %} {% for d in data %} -