{% load i18n %}
<form action="{{ acl.url }}" method="post">{% csrf_token %}
    <table class="table table-striped table-with-form-fields acl-table" id="{{table_id}}">
    <thead>
        <tr>
        <th></th>
        <th>{% trans "Who" %}</th>
        <th>{% trans "What" %}</th>
        <th><i id="manage-access-select-all" class="fa fa-times"></i></th>
        </tr>
    </thead>
    <tbody>
        {% for i in acl.users %}
        <tr>
        <td>
          <img class="profile-avatar" src="{{ i.user.profile.get_avatar_url }}"/>
        </td>
        <td>
            <a href="{% url "dashboard.views.profile" username=i.user.username %}"
            title="{{ i.user.username }}">
            {% include "dashboard/_display-name.html" with user=i.user show_org=True %}
            </a>
        </td>
        <td>
            <select class="form-control" name="perm-u-{{i.user.id}}"{% if i.level not in acl.allowed_levels %} disabled{% endif %}>
            {% for id, name in acl.levels %}
            <option{%if id == i.level%} selected="selected"{%endif%}
            {% if id not in acl.allowed_levels %} disabled{% endif %}
                value="{{id}}">{{name}}</option>
            {% endfor %}
            </select>
        </td>
        <td>
            <input type="checkbox" name="remove-u-{{i.user.id}}" title="{% trans "Remove" %}"/>
        </td>
        </tr>
        {% endfor %}
        {% for i in acl.groups %}
        <tr>
        <td><i class="fa fa-group"></i></td>
        <td>
            <a href="{% url "dashboard.views.group-detail" pk=i.group.pk %}">
            {{i.group}}
            </a>
        </td>
        <td>
            <select class="form-control" name="perm-g-{{i.group.id}}{% if i.level not in acl.allowed_levels %} disabled{% endif %}">
            {% for id, name in acl.levels %}
            <option{%if id == i.level%} selected="selected"{%endif%}
            {% if id not in acl.allowed_levels %} disabled{% endif %}
                value="{{id}}">{{name}}</option>
            {% endfor %}
            </select>
        </td>
        <td>
            <input type="checkbox" name="remove-g-{{i.group.id}}" title="{% trans "Remove" %}"/>
        </td>
        </tr>
        {% endfor %}
        <tr><td><i class="fa fa-plus"></i></td>
            <td>{{aclform.name }}</td>
            <td><select class="form-control" name="level">
                    {% for id, name in acl.levels %}
                    {% if id in acl.allowed_levels %}
                    <option value="{{id}}">{{name}}</option>
                    {% endif %}
                    {% endfor %}
            </select></td><td></td>
        </tr>
    </tbody>
    </table>
    <div class="form-actions">
    <button type="submit" class="btn btn-success">{% trans "Save" %}</button>
    </div>
</form>
