{#
    Display a table of item names with current ACL rules; allow superusers to update ACL rules.
    ACL rule updates will fail downstream if superuser lacks admin permission.

    This template uses DIVs styled as TABLE parts so a FORM can span "table cells".
#}

{% extends theme("layout.html") %}

{% block content %}
    <h1>{{ _("Item ACLs") }}</h1>
    {# javascript will toggle show/hide views below #}
    <div class="moin-show-hide-acls">
        {% set button_text = _("Showing all items") %}
        <input value="{{ button_text }}" class="moin-button" type="button">
        <div class="moin-acl-count">{{ _("Number items:") }} {{ number_items }}</div>
    </div>
    <div class="moin-show-hide-acls hidden">
        {% set button_alt_text = _("Showing items with modified ACLs") %}
        <input value="{{ button_alt_text }}" class="moin-button" type="button">
        <div class="moin-acl-count">{{ _("Number items:") }} {{ number_modified_acls }}</div>
    </div>

    <div class="moin-acl-report">
        <div class="moin-acl-heading">
            <div>{{ _("Item Names") }}</div>
            <div>{{ _("ACL") }}</div>
        </div>
        {% for item in items_acls %}
            {# we mark items using default ACLs with a special class so we can show/hide same with the click of a button #}
            {% if item['acl_default'] %}
                {% set default_style = "moin-acl-default" %}
            {% else %}
                {% set default_style = "" %}
            {% endif %}
            <form class="{{ default_style }} moin-acl-form" action="{{ url_for('admin.modify_acl', item_name=item['fqname']) }}" method="POST">
                <div class="moin-acl-name-cell">
                    {{ utils.item_moniker(item, item.fqnames) }}
                    <input class="moin-button" type="submit" value="{{ _("Save") }}"/>
                </div>
                <div class="moin-acl-rule-cell">
                    <textarea class="moin-acl-string" name="{{ item['fqname'] }}">{{ item['acl'] }}</textarea>
                </div>
            </form>
        {% endfor %}
    </div>
{% endblock %}
