{% extends "base.html" %}
{% load i18n %}
{% load translations %}
{% load crispy_forms_tags %}
{% load permissions %}

{% block breadcrumbs %}
<li><a href="{{ object.get_absolute_url }}">{{ object }}</a></li>
<li><a href="{% url 'manage-access' project=object.slug %}">{% trans "Manage users" %}</a></li>
{% endblock %}

{% block content %}

{% if object.access_control != object.ACCESS_CUSTOM %}
<div class="panel panel-primary">
  <div class="panel-heading"><h4 class="panel-title">
    {% documentation_icon 'admin/access' 'groups' right=True %}
  {% trans "Users" %}
  </h4></div>
  <table class="table table-striped">
  <thead>
  <tr>
  <th>{% trans "Username" %}</th>
  <th>{% trans "Full name" %}</th>
  <th>{% trans "E-mail" %}</th>
  {% for group in groups %}
  <th>{{ group.1 }}</th>
  {% endfor %}
  </tr>
  </thead>
  <tbody>
{% for user in object.all_users %}
  <tr>
  <td>{{ user.username }}</td>
  <td>{{ user.first_name }}</td>
  <td>{{ user.email }}</td>
  {% user_permissions user groups %}
  <td>
<form action="{% url "delete-user" project=object.slug %}" method="post">
{% csrf_token %}
<input type="hidden" name="user" value="{{ user.username }}" />
<button type="submit" class="btn btn-danger">
<i class="fa fa-trash"></i>
{% trans "Remove" %}
</button>
</form>
  </td>
  </tr>
{% endfor %}
  </tbody>
  </table>
  <div class="panel-body">
  <p class="helptext">{% trans "The user will be removed from the project once all user permissions are removed." %}</p>
  </div>
</div>

<form action="{% url "set-groups" project=object.slug %}" method="post" id="set_groups_form">
{% csrf_token %}
</form>

<form action="{% url "add-user" project=object.slug %}" method="post">
{% csrf_token %}
<div class="panel panel-primary">
  <div class="panel-heading"><h4 class="panel-title">
  {% trans "Add new user" %}
  </h4></div>
  <div class="panel-body">
    {{ add_user_form|crispy }}
  </div>
  <div class="panel-footer">
  <input type="submit" class="btn btn-default" value="{% trans "Add" %}" />
  </div>
</div>
</form>
{% else %}
<div class="panel panel-primary">
  <div class="panel-heading"><h4 class="panel-title">
    {% documentation_icon 'admin/access' 'groups' right=True %}
  {% trans "Users" %}
  </h4></div>
  <div class="panel-body">
  <p class="helptext">{% trans "The user management in Weblate is disabled, you can change permissions in the Django admin interface." %}</p>
  </div>
</div>
{% endif %}

{% can_edit_access_control user object as user_can_edit_access_control %}

<form action="{% url "change-access" project=object.slug %}" method="post">
{% csrf_token %}
<div class="panel panel-primary">
  <div class="panel-heading"><h4 class="panel-title">
    {% documentation_icon 'admin/access' 'acl' right=True %}
  {% trans "Project access control" %}
  </h4></div>
  <div class="panel-body">
  {% crispy access_form %}
  </div>
  <div class="panel-footer">
{% if user_can_edit_access_control %}
  <input type="submit" class="btn btn-default" value="{% trans "Change" %}" />
{% else %}
    <p class="helptext">{% trans "You do not have permission to change project access control." %}</p>
{% endif %}
  </div>
</div>
</form>
{% endblock %}
