From f5ad37a0bb736b7974b2b0663884e74e33b694a8 Mon Sep 17 00:00:00 2001
From: philipp <philipp@hofer.link>
Date: Thu, 2 Nov 2023 19:50:19 +0100
Subject: [PATCH] auto select owner as rower of private boat, Fixes #46

---
 frontend/main.ts                    | 6 +++++-
 templates/includes/macros.html.tera | 2 +-
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/frontend/main.ts b/frontend/main.ts
index 625abd6..3d4fcf2 100644
--- a/frontend/main.ts
+++ b/frontend/main.ts
@@ -35,6 +35,7 @@ interface ChoiceBoatEvent extends Event{
     label: string,
     customProperties: {
 	amount_seats: number,
+	owner: number,
     }
   };
 }
@@ -55,6 +56,10 @@ function selectBoatChange() {
 	const amount_seats = event.detail.customProperties.amount_seats;
 	setMaxAmountRowers("newrower", amount_seats);
 
+	if (event.detail.customProperties.owner){
+		choiceObjects["newrower"].setChoiceByValue(event.detail.customProperties.owner+"");
+	}
+
         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')}`;
@@ -201,7 +206,6 @@ function initNewChoice(select: HTMLInputElement) {
   if (select.dataset && select.dataset.seats) {
     seats = +select.dataset.seats;
   }
-  console.log(seats);
 
     let shipmaster = <HTMLElement>document.querySelector('#shipmaster-'+select.id+'js');
     let steering_person = <HTMLElement>document.querySelector('#steering_person-'+select.id+'js');
diff --git a/templates/includes/macros.html.tera b/templates/includes/macros.html.tera
index 1781a53..7d53179 100644
--- a/templates/includes/macros.html.tera
+++ b/templates/includes/macros.html.tera
@@ -151,7 +151,7 @@
 				<option selected value>{{ default }}</option>
 			{% endif %}
 			{% for d in data %}
-				<option value="{{ d.id }}" {% if d.id == selected_id %} selected {% endif %} {% if extras != '' %} {% for extra in extras %} {% if extra != 'on_water' %} data- {{extra}}={{d[extra]}} {% else %} {% if d[extra] %} disabled {% endif %} {% endif %} {% endfor %} {% endif %} {% if show_seats %} data-custom-properties='{"amount_seats": {{ d["amount_seats"] }}}'{% endif %}>
+				<option value="{{ d.id }}" {% if d.id == selected_id %} selected {% endif %} {% if extras != '' %} {% for extra in extras %} {% if extra != 'on_water' %} data- {{extra}}={{d[extra]}} {% else %} {% if d[extra] %} disabled {% endif %} {% endif %} {% endfor %} {% endif %} {% if show_seats %} data-custom-properties='{"amount_seats": {{ d["amount_seats"] }}, "owner": {{ d["owner"] }}}'{% endif %}>
 					{% for displa in display -%}
 						{%- if d[displa] -%}
 							{{- d[displa] -}}