[TASK] improve rower select
This commit is contained in:
		@@ -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 = (<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() {
 | 
			
		||||
  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());
 | 
			
		||||
        }
 | 
			
		||||
      });
 | 
			
		||||
    });
 | 
			
		||||
 
 | 
			
		||||
@@ -104,19 +104,21 @@
 | 
			
		||||
{% endmacro boat_select %}
 | 
			
		||||
 | 
			
		||||
{% macro rower_select(id, selected, amount_seats='', class='', init='false') %}
 | 
			
		||||
	<div class="{{ class }}">
 | 
			
		||||
		<select style="width: 100%;" multiple name="rowers[]" id="{{id}}" class="w-full" data-seats="{{amount_seats}}" data-init={{init}}>
 | 
			
		||||
			{% 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 %}>{{user.name}}</option>
 | 
			
		||||
			{% endfor %}
 | 
			
		||||
		</select>
 | 
			
		||||
	</div>
 | 
			
		||||
  {% if not amount_seats or amount_seats > 1 %} 
 | 
			
		||||
    <div class="{{ class }}">
 | 
			
		||||
      <select style="width: 100%;" multiple name="rowers[]" id="{{id}}" class="w-full" data-seats="{{amount_seats}}" data-init={{init}}>
 | 
			
		||||
        {% 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 %}>{{user.name}}</option>
 | 
			
		||||
        {% endfor %}
 | 
			
		||||
      </select>
 | 
			
		||||
    </div>
 | 
			
		||||
  {% 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 %}
 | 
			
		||||
								<p>
 | 
			
		||||
									<strong>{{ cox.name }}</strong>
 | 
			
		||||
									<strong>{{ user.name }}</strong>
 | 
			
		||||
								</p>
 | 
			
		||||
							{% endif %}
 | 
			
		||||
						{% endfor %}
 | 
			
		||||
@@ -222,6 +224,13 @@
 | 
			
		||||
 | 
			
		||||
{% macro home(log, only_ones) %}
 | 
			
		||||
	<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 %}
 | 
			
		||||
			{{ log::rower_select(id="rowers"~log.id, selected=log.rowers, amount_seats=log.boat.amount_seats) }}
 | 
			
		||||
		{% endif %}
 | 
			
		||||
 
 | 
			
		||||
@@ -83,7 +83,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 %} 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 -%}
 | 
			
		||||
					{%- if d[displa] -%}
 | 
			
		||||
						{{- d[displa] -}}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user