{% import '_macros.html' as macros %}

<div class="form-table">
    <div class="form-table-head">
        <div class="form-table-cell">{{ _("Name") }}</div>
        <div class="form-table-cell">{{ _("Connection email") }}</div>
        <div class="form-table-cell">{{ _("Access level") }}</div>
        <div class="form-table-cell"></div>
    </div>
    <form role="form" method="post" class="form-inline"
          action="{{ url_for('api_access', graph=graph.id, _method='POST') }}">
        {{ newaccess_form.hidden_tag() }}
        <div class="form-group"></div>
        {{ macros.render_field_table(newaccess_form.email) }}
        {{ macros.render_field_table(newaccess_form.level, class="form-control input-sm") }}
        <div class="form-group">
            <button name="_method" value="POST" data-loading-text="..."
                    class="btn btn-sm btn-primary" title="{{ _("Add") }}">
                <span class="glyphicon glyphicon-plus"></span>
            </button>
        </div>
    </form>
    {% for perm in permissions %}
    <form role="form" method="post" class="form-inline"
          action="{{ url_for('api_access', graph=graph.id, email=perm.user_email, _method='PUT') }}">
        <input type="hidden" name="csrf_token" value="{{ csrf_token() }}" />
        <div class="form-group">
            {% if perm.user.name %}
            <p class="form-control-static">{{ perm.user.name }}</p>
            {% endif %}
        </div>
        <div class="form-group">
            <p class="form-control-static">{{ perm.user_email }}</p>
        </div>
        <div class="form-group">
            <select name="level" class="form-control input-sm">
                {% for level in perm_choices %}
                <option value="{{ level[0] }}"
                    {% if level[0] == perm.level %} selected {% endif %}
                    >{{ level[1] }}</option>
                {% endfor %}
            </select>
        </div>
        <div class="form-group">
            <button name="_method" value="PUT" data-loading-text="..."
                    class="btn btn-sm btn-info" title="{{ _("Update") }}">
                <span class="glyphicon glyphicon-edit"></span>
            </button>
            <button name="_method" value="DELETE" data-loading-text="..."
                    class="btn btn-sm btn-warning" title="{{ _("Delete") }}">
                <span class="glyphicon glyphicon-remove"></span>
            </button>
        </div>
    </form>
    {% endfor %}
</div>
