{% extends "authentic2/manager/role_common.html" %}
{% load i18n static django_tables2 %}

{% block breadcrumb %}
  {{ block.super }}
  <a href="#">{{ object }}</a>
{% endblock %}

{% block sidebar %}
<aside id="sidebar">
<p>{{ object.description }}</p>
{% include "authentic2/manager/search_form.html" %}
<div id="details">
  <dl>
    <dt>{% trans "UUID" %}</dt>
    <dd>{{ object.uuid }}</dd>
  </dl>
</div>
</aside>
{% endblock %}

{% block appbar %}
  {{ block.super }}
  <span class="actions">
    <a class="extra-actions-menu-opener"></a>
  {% if not object.is_internal and view.can_delete %}
    <a rel="popup" href="{% url "a2-manager-role-delete" pk=object.pk %}">{% trans "Delete" %}</a>
  {% else %}
    <a class="disabled" title="{% trans "This role is technical, you cannot delete it." %}" href="#">{% trans "Delete" %}</a>
  {% endif %}
  {% if view.can_change and not object.is_internal %}
    <a href="{% url "a2-manager-role-edit" pk=object.pk %}">{% trans "Edit" %}</a>
  {% else %}
    {% if not view.can_change %}
      <a class="disabled" title="{% trans "Permission denied" %}" href="#">{% trans "Edit" %}</a>
    {% else %}
      <a class="disabled" title="{% trans "This role is technical, you cannot edit it." %}" href="#">{% trans "Edit" %}</a>
    {% endif %}
  {% endif %}
  {% if perms.a2_rbac.admin_permission %}
    <a href="{% url "a2-manager-role-permissions" pk=object.pk %}">{% trans "Permissions" %}</a>
  {% endif %}
    <ul class="extra-actions-menu">
      <li><a href="{% url "a2-manager-role-journal" pk=object.pk %}">{% trans "Journal" %}</a></li>
    </ul>
  </span>
{% endblock %}


{% block extra_scripts %}
  {{ block.super }}
  {{ choose_user_form.media }}
{% endblock %}

{% block main %}
 {% if from_ldap %}
   <div class="infonotice">
     {% trans "This role is synchronised from LDAP, changing members is not allowed." %}
   </div>
 {% endif %}
 {% with row_link=1 url_name="a2-manager-user-detail" %}
   {% render_table table "authentic2/manager/role_members_table.html" %}
 {% endwith %}

 {% include "authentic2/manager/export_include.html" with export_view_name="a2-manager-role-members-export" %}

 {% if view.can_manage_members %}
   <form method="post" class="manager-m2m-add-form" id="add-user">
           {% csrf_token %}
           {{ form }}
           <button>{% trans "Add" %}</button>
   </form>
 {% endif %}
 <fieldset class="gadjo-foldable gadjo-folded" id="other-properties">
 <legend class="gadjo-foldable-widget">{% trans "Advanced parameters" %}</legend>
 <div class="role-inheritance gadjo-folding">
   {% trans "Is administered by users" %}
   {% for user in object.get_admin_role.all_members %}
     <a href="{% url "a2-manager-user-edit" pk=user.pk %}">{{ user.get_full_name }}</a>
     {% if user.direct %}
       <a rel="popup" href="{% url "a2-manager-role-remove-admin-user" pk=object.pk user_pk=user.pk %}" class="role-remove icon-minus-sign"></a>
     {% else %}
       <a title="{% trans "Indirect child role" %}" class="disabled role-remove icon-minus-sign"></a>
     {% endif %}
   {% endfor %}
  {% if view.can_change %}
    <a rel="popup" href="{% url "a2-manager-role-add-admin-user" pk=object.pk %}" class="role-add icon-add-sign"></a>
  {% else %}
    <a title="{% trans "Permission denied" %}" class="disabled role-add icon-add-sign"></a>
  {% endif %}
 </div>
 <div class="role-inheritance gadjo-folding">
   {% trans "Is administered by roles" %}
   {% for role in admin_roles %}
     <a href="{% url "a2-manager-role-members" pk=role.pk %}">{{ role }}</a>
     {% if role.direct %}
       <a rel="popup" href="{% url "a2-manager-role-remove-admin-role" pk=object.pk role_pk=role.pk %}" class="role-remove icon-minus-sign"></a>
     {% else %}
       <a title="{% trans "Indirect admin role" %}" class="disabled role-remove icon-minus-sign"></a>
     {% endif %}
   {% endfor %}
  {% if view.can_change %}
    <a rel="popup" href="{% url "a2-manager-role-add-admin-role" pk=object.pk %}" class="role-add icon-add-sign"></a>
  {% else %}
    <a title="{% trans "Permission denied" %}" class="disabled role-add icon-add-sign"></a>
  {% endif %}
 </div>
 <div class="role-inheritance gadjo-folding">
   {% trans "Child roles:" %}
   {% for child in children %}
     <a href="{% url "a2-manager-role-members" pk=child.pk %}">{{ child }}</a>
     {% if child.direct %}
       <a rel="popup" href="{% url "a2-manager-role-remove-child" pk=object.pk child_pk=child.pk %}" class="role-remove icon-minus-sign"></a>
     {% else %}
       <a title="{% trans "Indirect child role" %}" class="disabled role-remove icon-minus-sign"></a>
     {% endif %}
   {% endfor %}
  {% if view.can_manage_members %}
    <a rel="popup" href="{% url "a2-manager-role-add-child" pk=object.pk %}" class="role-add icon-add-sign"></a>
  {% else %}
    <a title="{% trans "Permission denied" %}" class="disabled role-add icon-add-sign"></a>
  {% endif %}
 </div>
 <div class="role-inheritance gadjo-folding">
   {% trans "Parent roles:" %}
   {% for parent in parents %}
     <a class="role" href="{% url "a2-manager-role-members" pk=parent.pk %}">
       {% if parent.ou and has_multiple_ou %}{{ parent.ou }} - {% endif %}{{ parent }}
     </a>
     {% if parent.direct %}
       {% if not object.is_internal %}
         <a rel="popup" href="{% url "a2-manager-role-remove-parent" pk=object.pk parent_pk=parent.pk %}" class="role-remove icon-minus-sign"></a>
       {% else %}
         <a title="{% trans "This role is technical, you cannot modify its permissions." %}" class="disabled role-add icon-minus-sign"></a>
       {% endif %}
     {% else %}
       <a title="{% trans "Indirect parent role" %}" class="disabled role-remove icon-minus-sign"></a>
     {% endif %}
   {% endfor %}
   {% if not object.is_internal %}
     <a rel="popup" href="{% url "a2-manager-role-add-parent" pk=object.pk %}" class="role-add icon-add-sign"></a>
   {% else %}
     <a title="{% trans "This role is technical, you cannot modify its permissions." %}" class="disabled role-add icon-add-sign"></a>
   {% endif %}
 </div>
 </fieldset>
{% endblock %}
