{#
    Display a table of all item names with permissions for a selected user.
    Provide a link to modify the ACL of each item (modify item link).

    Uses jquery TableSort to initialize table sorted by columns 0 and 1,
    with empty cells always on top.

    TODO: emptyMin is a better choice than empty-top but requires TableSorter
    version >= 2.16.2. Current version: XStatic_JQuery.TableSorter-2.14.5.1
    See https://mottie.github.io/tablesorter/docs/example-option-sort-empty.html
#}

{% extends theme("layout.html") %}
{% import "utils.html" as utils with context %}
{% block content %}
    <h1>{{ _("User ACL Report") }}</h1>
    <h2>{{ _("User Names") }}: {{ user_names|join(', ') }}</h2>
    <table class="zebra moin-sortable" data-sortlist="[[0,0], [1,0]]">
        <thead>
            <tr>
                <th class="empty-top">{{ _("Namespace") }}</th>
                <th>{{ _("Item Names") }}</th>
                <th>{{ _("read") }}</th>
                <th>{{ _("write") }}</th>
                <th>{{ _("create") }}</th>
                <th>{{ _("destroy") }}</th>
                <th>{{ _("admin") }}</th>
            </tr>
        </thead>
        <tbody>
            {% for item in itemwise_acl %}
                <tr>
                    <td>{{ item['namespace'] }}</td>
                    <td>
                        <a href="{{ url_for('frontend.modify_item', item_name=item['fqname']) }}">
                            {%- if item['name'] -%}
                                {{ item['name']|join(', ') }}
                            {%- else -%}
                                Item Id: {{ item['itemid'] }}
                            {%- endif -%}
                        </a>
                    </td>
                    <td>{% if item['read'] %}{{ _("read") }}{% endif %}</td>
                    <td>{% if item['write'] %}{{ _("write") }}{% endif %}</td>
                    <td>{% if item['create'] %}{{ _("create") }}{% endif %}</td>
                    <td>{% if item['destroy'] %}{{ _("destroy") }}{% endif %}</td>
                    <td>{% if item['admin'] %}{{ _("admin") }}{% endif %}</td>
                </tr>
            {% endfor %}
        </tbody>
    </table>
{% endblock %}
