{% extends "cvkbrnobase.html" %}
{% load i18n %}
{% load staticfiles %}
{% load rowerfilters %}
{% load tz %}

{% block title %}{% trans "Going Rowing" %} {% endblock %}

{% block content %}
{% localtime on %}
<script type="text/JavaScript">
	var themembers = {{ jsonmembers|safe }};

	function getformfields(nrseat) {
		var s = "<table>"
		for (i=2;i<=nrseat;i++) {
			s+='<tr><td>'
			s+=i
			s+=': </td><td><select id="idcrew'
			s+=i
			s+='" name="crew'
			s+=i
			s+='"><option disabled selected value> -- </option>'
			for (var id in themembers) {
				s+= "<option value="
				s+= id
				s+= ">"+themembers[id]+"</option>"
			}
			s+= '</select></td></tr>'
		}	
		s+= "</table>"
		return s
	}
</script>

<div id="workouts" class="grid_6 alpha">

    {% if form.errors %}
        <p style="color: red;">
            Please correct the error{{ form.errors|pluralize }} below.
        </p>
    {% endif %}

	<h1>{% trans "Going Rowing" %}</h1>


    <form enctype="multipart/form-data" action="" method="post" content="text/html;charset=UTF-8">
        <table width=100%>
            {{ form.as_table }}
	<tr><th><label for="id_boat">{% trans "Boat" %}:</label></th>
		<td><select id="id_boat" name="boat" 
onchange="document.getElementById('crew').innerHTML = 
getformfields(this.options[this.selectedIndex].getAttribute('data-nrseat'));"
onload="document.getElementById('crew').innerHTML = 
getformfields(this.options[this.selectedIndex].getAttribute('data-nrseat'));">


		{% if selectedboat %}
		<option value="{{ selectedboat.id }}" data-nrseat="{{ selectedboat.nrseats }}" selected="selected">
		{{ selectedboat.boatcode }} {{ selectedboat.boatname }}
		 ({{ selectedboat.nrseats }})</option>
		{% else %}
		<option value="" selected="selected">---------</option>
		{% endif %}
		{% for boat in theboats %}
			<option value="{{ boat.id }}" data-nrseat="{{ boat.nrseats }}">{{ boat.boatcode }} {{ boat.boatname }} ({{ boat.nrseats }})</option>
		{% endfor %}
		</select></td></tr>
        </table>
<p>&nbsp;</p>

<p>1: {{ user.first_name }} {{ user.last_name }}</p>
<p id="crew"></p>
        {% csrf_token %}
   <div id="formbutton" class="grid_1 prefix_4 suffix_1">
        <input class="button green" type="submit" value="{% trans 'Save' %}">
   </div>
    </form>


</div>
<div id="reservations" class="grid_6 omega">
<h1>{% trans "Reservations" %}</h1>

<table class="listtable" width=100%>
<thead>
	<tr>
	<th>{% trans "Boat" %}</th>
	<th>{% trans "Departure time" %}</th>
	<th>{% trans "Reserved by" %}</th>
	<th>{% trans "Delete" %}
	</tr>
</thead>
<tbody>
	{% for outing in reservations %}
	<tr>
		<td> {{ outing.boat.boatname }} </td>
		<td> {{ outing.starttime }} </td>
		<td> {{ outing.rower.user.first_name }} {{ outing.rower.user.last_name }} </td>
		{% if user == outing.rower.user or thisclub_admin %}
		<td><a href="/cvkbrno/outing/{{ outing.id }}/delete">D</a></td>
		{% else %}
		<td>&nbsp;</td<
		{% endif %}
		<td>

	</tr>
	{% endfor %}
	
</tbody>
</table>

</div>

<div id="damaged" class="grid_6 omega">
{% if damagedboats %}
<h1>{% trans "Temporarily Unavailable" %}</h1>
<table class="listtable" width=100%>
<tbody>
	{% for boat in damagedboats %}
	<tr>
		<td> {{ boat.boatname }} </td>
	</tr>
	{% endfor %}
	

</tbody>
</table>
{% endif %}

{% if races %}
<h1>{% trans "Upcoming Races" %}</h1>
<table class="listtable" width=100%>
	<thead>
		<tr>	
		<th>{% trans "Name" %}</th>
		<th>{% trans "Start Date" %}</th>
		<th>{% trans "End Date" %}</th>
		</tr>
	</thead>
	<tbody>
		{% for race in races %}
		<tr>
		<td>{{ race.name }}</td>
		<td>{{ race.startdatetime }}</td>
		<td>{{ race.enddatetime }}</td>
		</tr>
		{% endfor %}
	<tbody>
</table>
{% endif %}
</div>

<div id="plannedwork" class="grid_6 omega">
{% if plannedwork %}
<h1>{% trans "Upcoming Members Work" %}</h1>
<table class="listtable" width=100%>
	<thead>
		<tr>	
		<th>{% trans "Name" %}</th>
		<th>{% trans "Date" %}</th>
		<th>{% trans "Action" %}</th>
		</tr>
	</thead>
	<tbody>
		{% for w in plannedwork %}
		<tr>
		<td>{{ w.name }}</td>
		<td>{{ w.date }}</td>
		{% if member in w.worker.all %}
		<td><a class="button red small" href="/cvkbrno/memberswork/{{ w.id }}/removeme">{% trans "Remove me" %}</a></td>
		{% else %}
		<td><a class="button green small" href="/cvkbrno/memberswork/{{ w.id }}/addme">{% trans "Add me" %}</a></td>
		{% endif %}
		</tr>
		{% endfor %}
	<tbody>
</table>
{% endif %}
</div>
{% endlocaltime %}
{% endblock %}
