{% load i18n %}
{% load lfc_tags %}

<div id="permissions">
    {% ifhasperm manage_permissions %}
        <h2 class="first-heading">
        {% trans 'Workflow' %}
        </h2>

        <p>{% trans "The current workflow is" %}: <span style="font-weight:bold">{{ workflow }}</span></p>

        <h2 class="middle-heading">
            {% trans 'Permissions' %}
        </h2>

        <form action="{% url 'lfc_update_object_permissions' obj.id %}"
              method="post">

            <table class="lfs-manage-table full">
                <tr>
                    <th width="60px">{% trans "Inherit" %}</th>
                    <th class="middle">{% trans "Permission" %}</th>
                    {% for role in roles %}
                        <th class="middle">{% trans role.name %}</th>
                    {% endfor %}
                </tr>
                {% for permission in permissions %}
                    <tr {% if permission.is_wf_permission %}class="wf_permission"{% endif %}>
                        <td><input type="checkbox" name="inherit" value="{{ permission.codename }}" {% if permission.is_inherited %}checked="checked"{% endif %}/></td>
                        <td class="permission emphasized">{% trans permission.name %}</td>
                        {% for role in permission.roles %}
                            <td><input type="checkbox" name="permission" value="{{ role.id }}|{{ permission.codename }}" {% if role.has_permission %}checked="checked"{% endif %}/></td>
                        {% endfor %}
                    </tr>
                {% endfor %}
            </table>

            <input class="ajax-submit"
                   type="submit" name="paste" value="{% trans 'Save permissions' %}" />
        </form>

    {% else %}
        <h2 class="first-heading">
            {% trans 'Worflow' %}
        </h2>

        <p>{% trans "The current workflow is" %}: <span style="font-weight:bold">{{ workflow }}</span></p>

        <h2 class="middle-heading">
            {% trans 'Permissions' %}
        </h2>

        <table class="lfs-manage-table full">
            <tr>
                <th class="tiny padr">{% trans "Inherited" %}</th>
                <th class="middle">{% trans "Permission" %}</th>
                {% for role in roles %}
                    <th class="large">{% trans role.name %} </th>
                {% endfor %}
            </tr>
            {% for permission in permissions %}
                <tr {% if permission.is_wf_permission %}class="wf_permission"{% endif %}>
                    <td>
                        {% if permission.is_inherited %}
                            <img src="{{ STATIC_URL }}icons/tick.png" alt='{% trans "Yes" %}' title='{% trans "Yes" %}' />
                        {# {% else %} #}
                        {#     <img src="{{ STATIC_URL }}icons/cross.png" alt='{% trans "No" %}' title='{% trans "No" %}' /> #}
                        {% endif %}
                    </td>
                    <td class="permission emphasized">{% trans permission.name %}</td>
                    {% for role in permission.roles %}
                        <td>
                            {% if role.has_permission %}
                                <img src="{{ STATIC_URL }}icons/tick.png" alt='{% trans "Yes" %}' title='{% trans "Yes" %}'/>
                            {# {% else %} #}
                            {#     <img src="{{ STATIC_URL }}icons/cross.png" alt='{% trans "No" %}'  title='{% trans "No" %}' /> #}
                            {% endif %}
                        </td>
                    {% endfor %}
                </tr>
            {% endfor %}
        </table>
    {% endifhasperm %}

    <div id="local-roles">
        {{ local_roles|safe }}
    </div>
</div>
