{% extends "base.html" %}
{% import '_macros.html' as macros %}

{% block title %}Administration | {{ super() }}{% endblock %}

{% block content %}


<h3>Propriétés du graphe</h3>

<form role="form" method="post" class="form-inline">
    <input type="hidden" name="formname" value="graphprops" />
    {{ graphprops_form.hidden_tag() }}

    {{ macros.render_field_p(graphprops_form.name, class="input-sm") }}
    {{ macros.render_field_p(graphprops_form.center_id, class="form-control input-sm") }}
    {{ macros.render_field_p(graphprops_form.anonymous, class="form-control input-sm") }}
    <p><button type="submit" class="btn btn-primary">Modifier</button></p>

</form>

<hr />

<h3>Types de relation</h3>

<form role="form" method="post" class="form-table"
      action="{{ url_for('admin', graph_id=graph.id) }}">
{{ reltypes_form.hidden_tag() }}
<input type="hidden" name="formname" value="reltypes" />
<table class="table table-centered">
    <thead>
        <tr>
            <th>Nom</th>
            <th>Couleur</th>
            <th>Quantité</th>
            <th></th>
        </tr>
    </thead>
    <tbody>
        <tr>
            {{ macros.render_field_table(reltypes_form.name) }}
            {{ macros.render_field_table(reltypes_form.color, class="color") }}
            <td></td>
            <td>
                <button type="submit" name="action" value="add"
                        class="btn btn-sm btn-primary">
                    <span class="glyphicon glyphicon-plus"></span>
                </button>
            </td>
        </tr>
        {% for reltype in rel_types %}
        <tr>
            <td>
                <input type="hidden" name="origname" value="{{ reltype.name }}" />
                <input type="text" name="name" class="form-control input-sm" value="{{ reltype.name }}" />
            </td>
            <td>
                <input type="color" name="color" class="form-control input-sm color" value="{{ reltype.color }}" />
            </td>
            <td class="text-center">
                {{ reltype.rel_count }}
            </td>
            <td>
                <button name="action" value="edit" data-loading-text="..."
                        class="btn btn-sm btn-info" title="Mettre à jour">
                    <span class="glyphicon glyphicon-edit"></span>
                </button>
                <button name="action" value="delete" data-loading-text="..."
                        class="btn btn-sm btn-warning" title="Supprimer"
                        {% if reltype.rel_count != 0 %}
                        data-confirm="Vous allez supprimer {{ reltype.rel_count }} relations"
                        {% endif %}
                        >
                    <span class="glyphicon glyphicon-remove"></span>
                </button>
            </td>
        </tr>
        {% endfor %}
    </tbody>
</table>
</form>


<hr />

<h3>Droits d'accès</h3>

<form role="form" method="post" class="form-table"
      action="{{ url_for('admin', graph_id=graph.id) }}">
{{ newaccess_form.hidden_tag() }}
<input type="hidden" name="formname" value="permissions" />
<table class="table table-centered">
    <thead>
        <tr>
            <th>Nom</th>
            <th>Email de connexion</th>
            <th>Niveau d'accès</th>
            <th></th>
        </tr>
    </thead>
    <tbody>
        <tr>
            {{ macros.render_field_table(newaccess_form.name) }}
            {{ macros.render_field_table(newaccess_form.email) }}
            {{ macros.render_field_table(newaccess_form.level, class="form-control input-sm") }}
            <td>
                <button type="submit" name="action" value="add" title="Ajouter"
                        class="btn btn-sm btn-primary">
                    <span class="glyphicon glyphicon-plus"></span>
                </button>
            </td>
        </tr>
        {% for perm in permissions %}
        <tr>
            <td>
                <input type="text" name="name" class="form-control input-sm" value="{{ perm.user.name }}" />
            </td>
            <td>{{ perm.user_email }}</td>
            <td>
                <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>
            </td>
            <td>
                <input type="hidden" name="email" value="{{ perm.user_email }}" />
                <button name="action" value="edit" data-loading-text="..."
                        class="btn btn-sm btn-info" title="Mettre à jour">
                    <span class="glyphicon glyphicon-edit"></span>
                </button>
                <button name="action" value="delete" data-loading-text="..."
                        class="btn btn-sm btn-warning" title="Supprimer">
                    <span class="glyphicon glyphicon-remove"></span>
                </button>
            </td>
        </tr>
        {% endfor %}
    </tbody>
</table>
</form>


<hr />

<p>
    <form role="form" method="post" class="form-delete"
          action="{{ url_for('admin', graph_id=graph.id) }}">
    <input type="hidden" name="formname" value="graphdel" />
    <button type="submit" class="btn btn-danger"
        data-confirm="Pas d'annulation possible. Continuer ?"
        >Supprimer le graphe</button>
    </form>
</p>

{% endblock %}


{% block more_headers %}
<link rel="stylesheet" href="{{ url_for('static', filename='spectrum/spectrum.css') }}" />
{% endblock %}
{% block more_js %}
<script src="{{ url_for('static', filename='spectrum/spectrum.js') }}"></script>
<script>
    $(function() {
        $("form.form-delete button").click(function(e) {
            var response = confirm($(this).attr("data-confirm"));
            if (!response) {
                e.preventDefault();
            }
        });
    });
</script>
{% endblock %}
