{% extends "MapbenderManagerBundle::manager.html.twig" %}

{% block manager_content %}

{% if is_granted('CREATE', oid) %}
<a class="iconAdd iconBig right" href="{{path('fom_user_user_create')}}" title="{{"fom.user.user.index.add_new_user"|trans}}"></a>
{% endif %}

{% if users|length > 0 %}
  {% set _group_view_grant = is_granted('VIEW', group_oid) %}
  <label for="inputFilterUsers" class="labelInput left">{{"fom.user.user.index.filter"|trans}}</label>
  <input id="inputFilterUsers" type="text" class="input left listFilterInput"/>

  <div class="clearContainer"></div>
  <table id="listFilterUsers" class="table userControlTable listFilterContainer">
    <thead id="usersHead">
      <tr class="doNotFilter">
        <th>{{ "fom.user.user.index.name" | trans }}</th>
        <th>{{ "fom.user.user.index.email" | trans }}</th>
        {% if _group_view_grant %}
        <th>{{ "fom.user.user.index.groups" | trans }}</th>
        {% endif %}
        <th></th>
      </tr>
    </thead>
    <tbody id="usersBody">
      {% for user in users %}
        <tr id="app-{{ user.id }}" class="filterItem">
          <td class="smallText">
            {% if is_granted('EDIT', user) %}
            <a class="labelText" href="{{ path('fom_user_user_edit', {'id': user.id}) }}" title="{{ 'fom.user.user.index.edit_user' | trans }}">{{ user.username }}</a>
            {% else %}
            <span class="labelText">{{ user.username }}</span>
            {% endif %}
          </td>
          <td class="smallText"><a href="mailto:{{ user.email }}" title="{{ 'fom.user.user.index.contact_user' | trans }}">{{ user.email }}</a></td>
          {% if _group_view_grant %}
          <td class="smallText">
            <ul class="list-unstyled">
              {% for group in user.groups %}
              <li class='doNotFilter'>
                {% if is_granted('EDIT', group) %}
                  <a href="{{ path('fom_user_group_edit', { 'id': group.id }) }}" title="{{ 'fom.user.user.index.edit_group' | trans }}">{{ group.title }}</a></li>
                {% else %}
                  <span>{{ group.title }}</span>
                {% endif %}
              {% endfor %}
            </ul>
          </td>
          {% endif %}
          <td class="iconColumn">
            {% if is_granted('EDIT', user) %}
              <a class="iconEdit iconSmall" href="{{ path('fom_user_user_edit',  {'id': user.id }) }}" title="{{ 'fom.user.user.index.edit_user' | trans }}"></a>
            {% endif %}
            {% if user.id != 1 and is_granted('DELETE', user) %}
              <span class="iconRemove iconSmall"
                title="{{"fom.user.user.index.delete_user" | trans}}"
                data-url="{{ path('fom_user_user_delete', { 'id': user.id}) }}"
                data-id="{{ user.id }}"
              ></span>
            {% endif %}
          </td>
        </tr>
      {% endfor %}
    </tbody>
  </table>
{% else %}
  <div class="clearContainer"></div>
  <p class="description">{{"fom.user.user.index.no_users_available"|trans}}</p>
{% endif %}
<div class="clearContainer"></div>
{% endblock %}

{% block js %}
  {{parent()}}
  <script type="text/javascript" src="{{ asset('bundles/mapbendermanager/js/user-control.js') }}"></script>
{% endblock %}
