{% extends "isearch/sidebar.html" %}

{% block title %}Эксперименты {{ active_user or active_group_name }} {% endblock %}

{% block features_active %}active{% endblock %}

{% block sidebar %}
<ul class="nav nav-list">
    <li class="nav-header">Пользователи</li>
    {% for user in active_users %}
    <li>
        <a href="{{ url('features_user', user) }}">
            {% if user == active_user %}
            <b>{{ user }}</b>
            {% else %}
            {{ user }}
            {% endif %}
        </a>
    </li>
    {% endfor %}
    <li class="nav-header">Группы</li>
    {% for group in active_groups %}
    <li>
        <a href="{{ url('features_group', group) }}">
            {% if group == active_group_name %}
            <b>{{ group }}</b>
            {% else %}
            {{ group }}
            {% endif %}
        </a>
    </li>
    {% endfor %}
</ul>
{% endblock %}

{% macro features_list(data, show_delete=True) %}
<table>
    {% for feature in data %}
    <tr>
    <td width="200px">
        {{ feature.name }}
    </td>
    <td>
        <div>
            <form method="POST" action="{{ url('add_feature') }}"
                  style="display:inline-block">
                <input type="hidden" name="user" value="{{ active_user }}" />
                <input type="hidden" name="group_id" value="{{ active_group_id }}" />
                <input type="hidden" name="name" value="{{ feature.name }}" />
                <input name="value" value="{{ feature.value }}" placeholder="Значение"/>
                <input class="btn" type="submit" value="Сохранить" />
            </form>
            {% if show_delete %}
            <form method="POST" action="{{ url('del_feature') }}"
                  style="display:inline">
                <input type="hidden" name="id" value="{{ feature.id }}" />
                <input type="hidden" name="user" value="{{ active_user }}" />
                <input type="hidden" name="group_id" value="{{ active_group_id }}" />
                <input class ="btn" type="submit" value="Удалить" />
            </form>
            {% endif %}
        </div>
    </td>
    </tr>
    {% endfor %}
</table>
{% endmacro %}

{% block content %}
<h2>{{ active_user or active_group_name }}</h2>
<div>
    <h3>Активные эксперименты</h3>
    {{ features_list(features) }}

    <h3>Неактивные эксперименты</h3>
    {{ features_list(not_active, False) }}

</div>
{% endblock %}
