169 lines
7.8 KiB
Plaintext
169 lines
7.8 KiB
Plaintext
{% macro new(only_ones, allow_any_shipmaster, shipmaster) %}
|
|
<form action="/log" method="post" id="form">
|
|
{% if not only_ones %}
|
|
{{ macros::select(data=boats, select_name='boat_id', display=["name", " (","amount_seats", " x)"], extras=["default_shipmaster_only_steering", "amount_seats"]) }}
|
|
{% else %}
|
|
{% set ones = boats | filter(attribute="amount_seats", value=1) %}
|
|
{{ macros::select(data=ones, select_name='boat_id', display=["name", " (","amount_seats", " x)"], extras=["default_shipmaster_only_steering", "amount_seats"]) }}
|
|
{% endif %}
|
|
<script>
|
|
function updateElementsBasedOnSelectedOption() {
|
|
var selectElement = document.getElementById('boat_id');
|
|
var selectedOption = selectElement.selectedOptions[0];
|
|
var shipmaster_only_steering = selectedOption.getAttribute("extra-default_shipmaster_only_steering") === 'true';
|
|
document.getElementById('shipmaster_only_steering').checked = shipmaster_only_steering;
|
|
document.getElementById('newrower-max_rower_allowed').innerHTML = selectedOption.getAttribute("extra-amount_seats");
|
|
}
|
|
|
|
document.getElementById('boat_id').addEventListener('change', updateElementsBasedOnSelectedOption);
|
|
document.addEventListener('DOMContentLoaded', updateElementsBasedOnSelectedOption);
|
|
</script>
|
|
{% if allow_any_shipmaster %}
|
|
<select name="shipmaster" id="shipmaster" class="input rounded-md h-10">
|
|
<optgroup label="Steuerpersonen">
|
|
{% for cox in coxes %}
|
|
<option value="{{ cox.id }}" {% if cox.id == shipmaster%} selected {% endif %}>{{ cox.name }}</option>
|
|
{% endfor %}
|
|
</optgroup>
|
|
<optgroup label="Restliche Mitglieder">
|
|
{% for user in users | filter(attribute="is_cox", value=false) %}
|
|
<option value="{{ user.id }}" {% if user.id == shipmaster%} selected {% endif %}>{{ user.name }}</option>
|
|
{% endfor %}
|
|
</optgroup>
|
|
</select>
|
|
{% else %}
|
|
<input type="hidden" name="shipmaster" value="{{shipmaster}}" />
|
|
{% endif %}
|
|
{% if not only_ones %}
|
|
{{ macros::checkbox(label='shipmaster_only_steering', name='shipmaster_only_steering') }}
|
|
{% endif %}
|
|
Departure: <input type="datetime-local" id="datetime-dep" name="departure" required/>
|
|
Arrival: <input type="datetime-local" id="datetime-arr" name="arrival" />
|
|
Destination: <input type="search" list="destinations" placeholder="Destination" name="destination" id="destination" oninput="var inputElement = document.getElementById('destination');
|
|
var dataList = document.getElementById('destinations');
|
|
var selectedValue = inputElement.value;
|
|
for (var i = 0; i < dataList.options.length; i++) {
|
|
if (dataList.options[i].value === selectedValue) {
|
|
var distance = dataList.options[i].getAttribute('distance');
|
|
document.getElementById('distance_in_km').value = distance;
|
|
break;
|
|
}
|
|
}">
|
|
<datalist id="destinations">
|
|
{% for distance in distances %}
|
|
<option value="{{ distance.0 }}" distance={{ distance.1 }} />
|
|
{% endfor %}
|
|
</datalist>
|
|
{{ macros::input(label="Distanz", name="distance_in_km", type="number", min=0) }}
|
|
{{ macros::input(label="Kommentar", name="comments", type="text") }}
|
|
{{ macros::select(data=logtypes, select_name='logtype', default="Normal") }}
|
|
{% if not only_ones %}
|
|
{{ log::rower_select(id="newrower", selected=[]) }}
|
|
{% endif %}
|
|
<input type="submit" />
|
|
|
|
<script>
|
|
const currentDate = new Date();
|
|
const localTime = new Date(currentDate.getTime() - (currentDate.getTimezoneOffset() * 60000));
|
|
const formattedDate = localTime.toISOString().slice(0, 16);
|
|
|
|
// Set the formatted string as the value of the input field
|
|
document.getElementById("datetime-dep").value = formattedDate;
|
|
</script>
|
|
</form>
|
|
<script>
|
|
document.getElementById('form').addEventListener('submit', function(e) {
|
|
e.preventDefault();
|
|
for(let optional_elem of ["datetime-arr", "distance_in_km", "comments", "logtype"]){
|
|
let myInput = document.getElementById(optional_elem);
|
|
if (myInput.value === '') {
|
|
myInput.removeAttribute('name');
|
|
}
|
|
}
|
|
this.submit();
|
|
});
|
|
</script>
|
|
{% endmacro new %}
|
|
|
|
|
|
{% macro show(log, state, allowed_to_close=false, only_ones) %}
|
|
Bootsname: {{ log.boat.name }}<br />
|
|
Schiffsführer: {{ log.shipmaster_user.name }}<br />
|
|
{% if log.shipmaster_only_steering %}
|
|
Schiffsführer steuert nur
|
|
{% endif %}
|
|
Weggefahren: {{ log.departure }}<br />
|
|
{% if state == "completed" %}
|
|
Angekommen: {{ log.arrival}}<br />
|
|
{% endif %}
|
|
{% set amount_rowers = log.rowers | length %}
|
|
{% set amount_guests = log.boat.amount_seats - amount_rowers -1 %}
|
|
{% if allowed_to_close and state == "on_water" %}
|
|
{{ log::home(log=log, only_ones=only_ones) }}
|
|
{% else %}
|
|
Ziel: {{ log.destination }}<br />
|
|
{% if state == "completed" %}
|
|
Km: {{ log.distance_in_km }}<br />
|
|
{% endif %}
|
|
{% if log.comments %}
|
|
Kommentare: {{ log.comments }}<br />
|
|
{% endif %}
|
|
{% if log.logtype %}
|
|
Logtype: {{ log.logtype }}<br />
|
|
{% endif %}
|
|
{% if amount_guests > 0 or log.rowers | length > 0 %}
|
|
Ruderer:
|
|
{% endif %}
|
|
{% if amount_guests > 0 %}
|
|
{{ amount_guests }} Gäste (ohne Account)
|
|
{% endif %}
|
|
{% for rower in log.rowers %}
|
|
{{ rower.name }}
|
|
{% endfor %}
|
|
{% endif %}
|
|
{% endmacro show %}
|
|
|
|
{% macro home(log, only_ones) %}
|
|
<form action="/log/{{log.id}}" method="post">
|
|
Destination: <input type="search" list="destinations" placeholder="Destination" required="required", id="destination-home" name="destination" value="{{log.destination}}" oninput="var inputElement = document.getElementById('destination-home');
|
|
var dataList = document.getElementById('destinations');
|
|
var selectedValue = inputElement.value;
|
|
for (var i = 0; i < dataList.options.length; i++) {
|
|
if (dataList.options[i].value === selectedValue) {
|
|
var distance = dataList.options[i].getAttribute('distance');
|
|
document.getElementById('distance_in_km_home').value = distance;
|
|
break;
|
|
}
|
|
}">
|
|
{{ macros::input(label="Distanz", name="distance_in_km", id="distance_in_km_home", type="number", min=0, value=log.distance_in_km, required=true) }}
|
|
{{ macros::input(label="Kommentar", name="comments", type="text", value=log.comments) }}
|
|
{{ macros::select(data=logtypes, select_name='logtype', default="Normal", selected_id=log.logtype) }}
|
|
{% if not only_ones %}
|
|
{{ log::rower_select(id="rowers"~log.id, selected=log.rowers, amount_seats=log.boat.amount_seats) }}
|
|
{% endif %}
|
|
<input type="submit" value="AUSFAHRT BEENDEN"/>
|
|
</form>
|
|
{% endmacro home %}
|
|
|
|
|
|
{% macro rower_select(id, selected, amount_seats='') %}
|
|
<select multiple="multiple" name="rower[]" id="{{id}}" onclick="updateSelectedRowersCount{{id}}()" onblur="updateSelectedRowersCount{{id}}()">
|
|
{% for user in users %}
|
|
{% set_global sel = false %}
|
|
{% for rower in selected %}
|
|
{% if rower.id == user.id %}
|
|
{% set_global sel = true %}
|
|
{% endif %}
|
|
{% endfor %}
|
|
<option value="{{ user.id }}" {% if sel %}selected{% endif %} onmousedown="event.preventDefault();this.selected = !this.selected; return false;">{{user.name}}</option>
|
|
{% endfor %}
|
|
</select>
|
|
<script>
|
|
function updateSelectedRowersCount{{id}}() {
|
|
document.getElementById('{{id}}-amount_rower_selected').textContent = document.getElementById('{{id}}').selectedOptions.length+1;
|
|
}
|
|
document.addEventListener('DOMContentLoaded', updateSelectedRowersCount{{id}});
|
|
</script>
|
|
<span id="{{id}}-amount_rower_selected"></span>/<span id="{{id}}-max_rower_allowed">{{amount_seats}}</span> Ruderer ausgewählt
|
|
{% endmacro rower_select %}
|