{% extends 'base.html' %}

{% block body %}
<div class="row">
	<div class="col">
		<p class="text-right">
			<a class="btn btn-primary" href="{{ url_for("user.show") }}">
				<i class="fa fa-plus" aria-hidden="true"></i> {{_("New")}}
			</a>
			<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#csvimport">
				<i class="fa fa-file-csv" aria-hidden="true"></i> {{_("CSV import")}}
			</button>
		</p>
		<table class="table table-striped table-sm">
			<thead>
				<tr>
					<th scope="col">{{_("UID")}}</th>
					<th scope="col">{{_("Login Name")}}</th>
					<th scope="col">{{_("Display Name")}}</th>
					<th scope="col">{{_("Roles")}}</th>
				</tr>
			</thead>
			<tbody>
				{% for user in users|sort(attribute="uid") %}
				<tr id="user-{{ user.uid }}">
					<th scope="row">
						{{ user.uid }}
					</th>
					<td>
						<a href="{{ url_for("user.show", uid=user.uid) }}">
							{{ user.loginname }}
						</a>
						{% if user.is_service_user %}
						<span class="badge badge-secondary">{{_('service')}}</span>
						{% endif %}
					</td>
					<td>
						{{ user.displayname }}
					</td>
					<td>
					{% for role in user.roles|sort(attribute="name") %}
						<a href="{{ url_for("role.show", roleid=role.id) }}">{{ role.name }}</a>{% if not loop.last %}, {% endif %}
					{% endfor %}
					</td>
				</tr>
				{% endfor %}
			</tbody>
		</table>
	</div>
</div>

<div class="modal fade" id="csvimport" tabindex="-1" role="dialog" aria-hidden="true">
	<form action="{{ url_for("user.csvimport") }}" method="POST">
	<div class="modal-dialog" role="document">
		<div class="modal-content">
			<div class="modal-header">
				<h5 class="modal-title" id="exampleModalLabel">{{_("Import a csv formated list of users")}}</h5>
				<button type="button" class="close" data-dismiss="modal" aria-label="{{_('Close')}}">
					<span aria-hidden="true">&times;</span>
				</button>
			</div>
			<div class="modal-body">
				<p>
					{{_('The format should be "loginname,mailaddres,roleid1;roleid2". Neither setting the display name nor setting passwords is supported (yet). Example:')}}
				</p>
				<pre>
testuser1,foobar@example.com,5;2;6
testuser5,foobsdfar@example.com,
testuser5,foobadfar@example.com,0;5;2
testuser2,foobaadsfr@example.com,5;2
				</pre>
				<textarea rows="10" class="form-control" name="csv"></textarea>
				<div class="form-check mt-2">
					<input class="form-check-input" type="checkbox" id="ignore-loginname-blocklist" name="ignore-loginname-blocklist" value="1" aria-label="enabled">
					<label class="form-check-label" for="ignore-loginname-blocklist">{{_("Ignore login name blocklist")}}</label>
				</div>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-secondary" data-dismiss="modal">{{_("Close")}}</button>
				<button type="submit" class="btn btn-primary">{{_("Import")}}</button>
			</div>
		</div>
	</div>
	</form>
</div>
{% endblock %}
