{% from 'include/input_macros.html' import input, checkbox %}
{% if not adding %}
<table class="overview" id="ajax-users">
	<thead>
		<tr class="overviewHead">
			<th class="padding10 first-collumn" id="user-login-th">{{lang.words.login|title()}}</th>
			<th style="width: 10%">{{lang.words.password|title()}}</th>
			<th style="width: 10%" class="checkbox-head" id="user-active-th">{{lang.words.active|title()}}</th>
			<th style="width: 20%">{{lang.words.email|title()}}</th>
			{% if page == "servers.py" %}
			<th style="width: 10%" id="user-role-th">{{lang.words.role|title()}}</th>
			{% else %}
				<th style="width: 10%" id="user-group-role-th">{{lang.words.groups|title()}} {{lang.words.and}} {{lang.words.roles|title()}}</th>
			{% endif %}
			<th style="width: 100%" id="user-services-th">{{lang.words.services|title()}}</th>
			<th></th>
			<th></th>
		</tr>
	</thead>
	<tbody>
	{% endif %}
	{% for user in users %}
	{% if user.role == '1' and page == "servers.py" %}
	{% set disable_superAdmin = "disabled" %}
	{% endif %}
		<tr id="user-{{user.user_id}}" class="{{ loop.cycle('odd', 'even') }} {% if adding %}newuser{% endif %}">
			<td class="padding10 first-collumn">
				{% set login_id = 'login-' + user.user_id|string() %}
				{% if user.6 == 1%}
					{{ input(login_id, value=user.username, readonly='readonly') }}
				{% else %}
					{{ input(login_id, value=user.username) }}
				{% endif %}
			</td>
			<td>
				{% if user.6 != 1%}
				<span title="{{lang.words.change|title()}} {{lang.words.password}}" style="cursor: pointer; margin-left: 15px;" class="div-pic" onclick="openChangeUserPasswordDialog('{{user.user_id}}')">
				</span>
				{% endif %}
			</td>
			<td class="checkbox">
				{% set activeuser_id = 'activeuser-' + user.user_id|string() %}
				{% if user.activeuser == 1 %}
					{{ checkbox(activeuser_id, checked='checked', disabled=disable_superAdmin) }}
				{% else %}
					{{ checkbox(activeuser_id, disable_superAdmin) }}
				{% endif %}
			</td>
			<td>
				{% set email_id = 'email-' + user.user_id|string() %}
				{% if user.ldap_user == 1%}
					{{ input(email_id, value=user.email, readonly='readonly') }}
				{% else %}
					{{ input(email_id, value=user.email, type='email') }}
				{% endif %}
			</td>
			<td>
				{% if page == "servers.py" %}
				<select id="role-{{user.user_id}}" name="role-{{user.user_id}}" {{disable_superAdmin}}>
					<option disabled selected>Select a role</option>
					{% for r in roles %}
						{% for user_role in user_roles %}
							{% if r.role_id|int() != 1 and user.user_id == user_role.user_id %}
								{% if user_role.user_role_id == r.role_id %}
								<option value="{{ r.role_id }}" selected>{{ r.name }}</option>
								{% else %}
								<option value="{{ r.role_id }}">{{ r.name }}</option>
								{% endif %}
							{% endif %}
						{% endfor %}
					{% endfor %}
				</select>
				{% else %}
				<span title="{{lang.words.change2|title()}} {{lang.words.user3}} {{lang.words.groups}} {{lang.words.and}} {{lang.words.roles}}" style="cursor: pointer; margin-left: 40px;" class="div-pic" onclick="confirmChangeGroupsAndRoles('{{user.user_id}}')"></span>
				{% endif %}
			</td>
			<td>
				<span title="{{lang.words.change2|title()}} {{lang.words.user3}} {{lang.words.services}}" style="cursor: pointer; margin-left: 15px;" class="div-pic" onclick="openChangeUserServiceDialog('{{user.user_id}}')"></span>
			</td>
			<td>
				<a href="/app/history/user/{{user.user_id}}" title="{{lang.words.view|title()}} {{lang.words.history}} {{lang.words.for}} {{lang.words.user2}}" class="history"></a>
			</td>
			<td>
				<a class="delete" onclick="confirmDeleteUser({{user.user_id}})" title="{{lang.words.delete|title()}} {{user.username}}" style="cursor: pointer;"></a>
			</td>
		</tr>
	{% endfor %}
	{% if not adding %}
	<tbody>
</table>
<br /><span class="add-button" title="{{lang.words.add|title()}} {{lang.words.new}} {{lang.words.user2}}" id="add-user-button">+ {{lang.words.add|title()}}</span>
<br /><br />
{% endif %}
