{% extends "base.html" %}
{% import "macros.html" as macros with context %}

{% block content %}
<div class="row">
  <div class="col-xs-12">
    <h2>{{ division.name }}</h2>
  </div>
  <div class="col-md-3 col-md-push-9">
    <h3>Attribute Transformers</h3>
    <form method="post">
      {{ transformer_form.form_id(value='transformer') }}
      {{ macros.render_input(transformer_form.attribute) }}
      {{ macros.render_input(transformer_form.transformer, disabled=True) }}
      {{ transformer_form.csrf_token }}
    </form>
  </div>
  <div class="col-md-9 col-md-pull-3">
  {% for permission in (PermissionType.submit, PermissionType.review, PermissionType.pay, PermissionType.admin) %}
  <div class="row permission" id="{{ permission.name }}">
    <div class="col-xs-12">
      <h3>{{ permission }}s</h3>
    </div>
    <div class="col-lg-8">
      <table class="table table-condensed">
        <tr>
          <th>Name</th>
          <th>Type</th>
          <th>Authentication Source</th>
          <th>Remove</th>
        </tr>
        {% for entity in division.permissions[permission]|map(attribute='entity') %}
        <tr>
          <td>{{ entity.name }}</td>
          {% if entity.users is defined %}
          <td>Group ({{ entity.users|length }})</td>
          {% else %}
          <td>User</td>
          {% endif %}
          <td>{{ entity.authmethod }}</td>
          <td>
            <form method="post">
              {{ entity_form.csrf_token() }}
              {{ entity_form.id_(value=entity.id) }}
              {{ entity_form.permission(value=permission.value) }}
              {{ entity_form.action(value='delete') }}
              {{ entity_form.form_id }}
              <button class="close" type="submit">&times;</button>
            </form>
          </td>
        </tr>
        {% endfor %}
      </table>
    </div>
    <div class="col-lg-4">
      <form class="form-horizontal" role="form" method="post" autocomplete="off">
        <div class="input-group">
          <input type="text" class="form-control entity-typeahead typeahead" id="add-{{ permission.value }}-name" name="name" autocomplete="off" placeholder="Name">
          <span class="input-group-btn">
            <button class="btn btn-default" type="submit">Add</button>
          </span>
        </div>
        {{ entity_form.csrf_token() }}
        {{ entity_form.action(value="add") }}
        {{ entity_form.permission(value=permission.name) }}
        {{ entity_form.id_() }}
        {{ entity_form.form_id }}
      </form>
    </div>
  </div>
  {% endfor %}
</div>
{% endblock content %}
