{% extends "base.html" %}

{% block title %}
	&raquo; Users
{% endblock %}

{% block inside_head %}
	<style type="text/css">
		label {
			width: 10em;
		}
	</style>
{% endblock %}

{% block nav %}
	Users
{% endblock %}

{% block content %}
	{% if current_user is defined %}
		<p>Current user: <a href="/users/{{current_user.id}}">Me</a></p>
	{% endif %}

	{% if users|length > 0 %}
		<table>
			<caption>Users</caption>
			<thead>
				<tr>
					<th></th>
					<th>Username</th>
					<th>Role</th>
					<th>Party</th>
				</tr>
			</thead>
			<tbody>
				{% for user in users %}
					<tr>
						<td><a href="/users/{{user.id}}">view</a></td>
						<td>{{ user.email_address }}</td>
						<td>{{ user.user_role.code }}</td>
						<td>{{ user.party.name }}</td>
					</tr>
				{% endfor %}
			</tbody>
		</table>
	{% endif %}
	<br>
	<br>
	<form method="post">
		<fieldset>
			<legend>Add new user</legend>	

			<label>Username</label>
			{{input_text('email_address')}}
			{% if not ad_auth_on %}
				<label>Password</label>
				<input type="password" name="password">
			{% endif %}
			<fieldset>
				<legend>Role</legend>
				<label>Editor</label>
				<input type="radio" name="user_role_code" value="editor"
						{% if request.values.user_role_code %}
							{% if request.values.user_role_code == 'editor' %}
								checked
							{% endif %}
						{% else %}
							checked
						{% endif %}
				>
				<label>Viewer</label>
				<input type="radio" name="user_role_code" value="viewer"
					{% if request.values.user_role_code == 'viewer' %}
						checked
					{% endif %}
				>
				<label>Party Viewer</label>
				<input type="radio" name="user_role_code" value="party-viewer"
					{% if request.values.user_role_code == 'party-viewer' %}
						checked
					{% endif %}
				>
				<label>Party Viewer Party</label>
				<select name="party_id">
					{% for party in parties %}
						<option value="{{ party.id }}"
							{%- if request.values.user_role_id == party.id -%}
								selected
							{% endif %}
						>{{ party.name }} {{ party.participant.code }}
							{{ party.market_role.description }}
						</option>
					{% endfor %}
				</select>
			</fieldset>
			<input type="submit" value="Add">
		</fieldset>
	</form>
{% endblock %}
