{% extends "projector/project/detail.html" %}

{% load i18n %}
{% load pagination_tags %}
{% load sorting_tags %}
{% load guardian_tags %}

{% block col-single-extra %}

{% autosort memberships %}
{% autopaginate memberships %}

<div class="richtemplates-panel">
    <h5>{% trans "Project's members" %}</h5>
    <div class="richtemplates-panel-content">
    {% block members-menu %}
    {% get_obj_perms request.user for project as "project_perms" %}

    <ul class="nav-inline">
        <li class="richbuttonset">
            <a  class="button-link" href="{{ project.get_members_url }}">{% trans "Members" %}</a>
            {% if "can_add_member" in project_perms %}
            <a  class="button-link" href="{{ project.get_members_add_url }}">{% trans "Add member" %}</a>
            {% endif %}
        </li>
    </ul>
    {% endblock %}
    <table class="datatable">
        <thead class="datatable-thead">
            <tr class="datatable-thead-subheader">
                <th>{% anchor member "Username" %}</th>
                <th>{% anchor joined_at "Joined at" %}</th>
                <th>{% trans "Permissions" %}</th>
                <th>{% trans "Remove" %}</th>
            </tr>
        </thead>
        <tbody class="datatable-tbody">
            {% for membership in memberships %}
            <tr class="{% cycle "odd" "even" %} hoverable">
                <td><a class="block-link" href="{{ membership.member.get_absolute_url }}">{{ membership.member }}</a></td>
                <td>{{ membership.joined_at }}</td>
                <td>
                    {% if project.author == membership.member %}
                    {% trans "Owner has all permissions" %}
                    {% else %}
                    <a class="block-link" href="{{ membership.get_absolute_url }}">{% trans "Manage" %}</a>
                    {% endif %}
                </td>
                <td>
                    {% if project.author == membership.member %}
                    -
                    {% else %}
                    <a href="{{ membership.get_delete_url }}"
                       class="block-link deletelink">{% trans "Delete" %}</a>
                    {% endif %}
                </td>
            </tr>
            {% endfor %}
        </tbody>
    </table>
    {% paginate %}

</div>
</div>
{% endblock %}

