{% extends "layout.html" %}

{% block content_header %}
  {{ build_breadcrumbs([
    { 'name': _('Groups'), 'link': url_for('.GroupView:index'), 'icon': 'users' }
  ]) }}
{% endblock %}

{% block content %}
  <section class="content">
    {% call build_list_containers(_('Group'), 'users') %}
      {% call build_list_table() %}
        {% call build_list_table_headers(get=url_for('.GroupView:get', id=''), delete=url_for('.GroupView:delete', id='')) %}
          <th>{{ _('Label') }}</th>
          <th>{{ _('Name') }}</th>
          <th>{{ _('Extension') }}</th>
        {% endcall %}
        {% call(group) build_list_table_rows(resource_list['items']) %}
          <td>{{ group.label }}</td>
          <td>{{ group.name }}</td>
          <td>
            {% for extension in group.extensions %}
              <strong>{{ _('internal') }}:</strong> {{ extension.exten }}
            {% endfor %}
            {% for extensions in group.incalls %}
              {% for extension in extensions.extensions %}
                <strong>{{ _('incall') }}:</strong> {{ extension.exten }}
              {% endfor %}
            {% endfor %}
            {{ '-' if not group.extensions and not group.incalls }}
          </td>
        {% endcall %}
      {% endcall %}
    {% endcall %}

    {% call build_hidden_add_containers(_('Add Group')) %}
      {% call build_form() %}
        {% call add_default_fields(form=form, submit_value=_('Add')) %}
          {{ render_field(form.label) }}
          {{ render_field(form.extensions[0].context,
                          label='Extension',
                          inputclass='ui-helper-clearfix',
                          divclass='col-sm-4',
                          class_='group-context',
                          placeholder=_('Choose Context'),
                          data_listing_href=url_for(listing_urls['context_by_type'], type_='internal')) }}
          {{ render_field(form.extensions[0].exten,
                          with_label=False,
                          data_allow_custom_values=True,
                          data_allow_clear='true',
                          divclass='col-sm-4',
                          class_='group-exten',
                          data_listing_href=url_for(listing_urls['available_extension_group'])) }}
          {{ render_field(form.members.user_uuids, data_listing_href=url_for(listing_urls['uuid_user'])) }}
        {% endcall %}
      {% endcall %}
    {% endcall %}
  </section>
{% endblock %}

{% block additional_js %}
  <script src="{{ url_for('.static', filename='js/group.js') }}"></script>
{% endblock %}
