[TASK] improve rower select
This commit is contained in:
parent
c0366edbe1
commit
33cb5e025b
@ -14,8 +14,24 @@ document.addEventListener('DOMContentLoaded', function() {
|
|||||||
replaceStrings();
|
replaceStrings();
|
||||||
initChoices();
|
initChoices();
|
||||||
initBoatActions();
|
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 = (<HTMLOptionElement>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() {
|
function initBoatActions() {
|
||||||
const boatSelects = document.querySelectorAll('.boats-js[data-onclick="true"]');
|
const boatSelects = document.querySelectorAll('.boats-js[data-onclick="true"]');
|
||||||
if(boatSelects) {
|
if(boatSelects) {
|
||||||
@ -25,6 +41,7 @@ function initBoatActions() {
|
|||||||
const rowers = Number(select.dataset.seats) - 1;
|
const rowers = Number(select.dataset.seats) - 1;
|
||||||
choiceObjects['newrower'].config.maxItemCount = rowers;
|
choiceObjects['newrower'].config.maxItemCount = rowers;
|
||||||
choiceObjects['newrower'].removeActiveItems(rowers);
|
choiceObjects['newrower'].removeActiveItems(rowers);
|
||||||
|
(rowers === 0 ? choiceObjects['newrower'].disable() : choiceObjects['newrower'].enable());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -104,19 +104,21 @@
|
|||||||
{% endmacro boat_select %}
|
{% endmacro boat_select %}
|
||||||
|
|
||||||
{% macro rower_select(id, selected, amount_seats='', class='', init='false') %}
|
{% macro rower_select(id, selected, amount_seats='', class='', init='false') %}
|
||||||
<div class="{{ class }}">
|
{% if not amount_seats or amount_seats > 1 %}
|
||||||
<select style="width: 100%;" multiple name="rowers[]" id="{{id}}" class="w-full" data-seats="{{amount_seats}}" data-init={{init}}>
|
<div class="{{ class }}">
|
||||||
{% for user in users %}
|
<select style="width: 100%;" multiple name="rowers[]" id="{{id}}" class="w-full" data-seats="{{amount_seats}}" data-init={{init}}>
|
||||||
{% set_global sel = false %}
|
{% for user in users %}
|
||||||
{% for rower in selected %}
|
{% set_global sel = false %}
|
||||||
{% if rower.id == user.id %}
|
{% for rower in selected %}
|
||||||
{% set_global sel = true %}
|
{% if rower.id == user.id %}
|
||||||
{% endif %}
|
{% set_global sel = true %}
|
||||||
{% endfor %}
|
{% endif %}
|
||||||
<option value="{{ user.id }}" {% if sel %} selected {% endif %}>{{user.name}}</option>
|
{% endfor %}
|
||||||
{% endfor %}
|
<option value="{{ user.id }}" {% if sel %} selected {% endif %}>{{user.name}}</option>
|
||||||
</select>
|
{% endfor %}
|
||||||
</div>
|
</select>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
{% endmacro rower_select %}
|
{% endmacro rower_select %}
|
||||||
|
|
||||||
{% macro show(log, state, allowed_to_close=false, only_ones) %}
|
{% macro show(log, state, allowed_to_close=false, only_ones) %}
|
||||||
@ -156,10 +158,10 @@
|
|||||||
{{ log.destination }}
|
{{ log.destination }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% for cox in coxes %}
|
{% for user in users %}
|
||||||
{% if cox.id == log.shipmaster %}
|
{% if user.id == log.shipmaster %}
|
||||||
<p>
|
<p>
|
||||||
<strong>{{ cox.name }}</strong>
|
<strong>{{ user.name }}</strong>
|
||||||
</p>
|
</p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
@ -222,6 +224,13 @@
|
|||||||
|
|
||||||
{% macro home(log, only_ones) %}
|
{% macro home(log, only_ones) %}
|
||||||
<form class="grid grid-cols-1 gap-3" action="/log/{{log.id}}" method="post">
|
<form class="grid grid-cols-1 gap-3" action="/log/{{log.id}}" method="post">
|
||||||
|
{% for user in users %}
|
||||||
|
{% if user.id == log.shipmaster %}
|
||||||
|
<p>
|
||||||
|
<strong>{{ user.name }}</strong>
|
||||||
|
</p>
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
{% if not only_ones %}
|
{% if not only_ones %}
|
||||||
{{ log::rower_select(id="rowers"~log.id, selected=log.rowers, amount_seats=log.boat.amount_seats) }}
|
{{ log::rower_select(id="rowers"~log.id, selected=log.rowers, amount_seats=log.boat.amount_seats) }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@ -83,7 +83,7 @@
|
|||||||
<option selected value>{{ default }}</option>
|
<option selected value>{{ default }}</option>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% for d in data %}
|
{% for d in data %}
|
||||||
<option value="{{ d.id }}" {% if d.id == selected_id %} selected {% endif %} {% if extras != '' %} {% for extra in extras %} extra- {{extra}}={{d[extra]}} {% endfor %} {% endif %}>
|
<option value="{{ d.id }}" {% if d.id == selected_id %} selected {% endif %} {% if extras != '' %} {% for extra in extras %} data-{{extra}}={{d[extra]}} {% endfor %} {% endif %}>
|
||||||
{% for displa in display -%}
|
{% for displa in display -%}
|
||||||
{%- if d[displa] -%}
|
{%- if d[displa] -%}
|
||||||
{{- d[displa] -}}
|
{{- d[displa] -}}
|
||||||
|
Loading…
Reference in New Issue
Block a user