{% extends "base.html" %}

{% block title %} | Subsets{% endblock %}
{% block bodydata %} data-project-id="{{subset.project.id}}"{% endblock %}

{% load filter_tags %}

{% block main %}
        <div class="page-header">
            <div class="container">
                <h1 class="smaller"><a href="{% url 'admin:project_overview' subset.project.id %}">{{subset.project.name}}</a></h1>
                <ul class="nav nav-tabs header-nav">
                    <li role="presentation"><a href="{% url 'admin:project_overview' subset.project.id %}">Project home</a></li>
                    <li role="presentation"><a href="{% url 'admin:category_list' subset.project.id %}">Categories</a></li>
                    <li role="presentation"><a href="{% url 'admin:usergroup_list' subset.project.id %}">User groups</a></li>
                    <li role="presentation" class="active"><a href="{% url 'admin:subset_list' subset.project.id %}">Subsets</a></li>
                    <li role="presentation"><a href="{% url 'admin:project_extend' subset.project.id %}">Geographic extent</a></li>
                    <li role="presentation"><a href="{% url 'admin:project_settings' subset.project.id %}">Settings</a></li>
                </ul>
            </div>
        </div>

        <div class="container">
            {% include 'snippets/messages.html' %}

            <div class="row">
                <div class="col-sm-4">
                    <div class="panel panel-default">
                        <div class="panel-heading">
                            <h6 class="item-info">Subset</h6>
                            <h3>{{ subset.name }}</h3>
                            {% if subset.description %}<p>{{ subset.description|linebreaksbr }}</p>{% endif %}
                        </div>
                        <div class="list-group">
                            <a href="{% url 'admin:subset_data' subset.project.id subset.id %}" class="list-group-item active">Data</a>
                            <a href="{% url 'admin:subset_settings' subset.project.id subset.id %}" class="list-group-item">Settings</a>
                        </div>
                    </div>
                </div>
                <div class="col-sm-8">
                    <h3 class="header">Subset data</h3>
                    <form id="data-access" method="POST" action="{% url 'admin:subset_data' subset.project.id subset.id %}" novalidate>
                        {% csrf_token %}
                        <input type="hidden" name="filters" value="-1">

                        <fieldset id="filter">
                            <legend>Select the categories that will be accessible in the subset</legend>

                            {% for category in subset.project.categories.all %}
                            <div class="category checkbox">
                                <label>
                                    <input type="checkbox" name="category" class="cat" value="{{ category.id }}" {% if subset.filters|is_in:category.id %}checked="checked"{% endif%}> {{ category.name }} {% show_restrict subset.filters category %}
                                </label>
                                {% if subset.filters|is_in:category.id %}
                                        {% show_fields subset.filters category %}
                                {% endif%}
                            </div>
                            {% endfor %}
                        </fieldset>

                        <button type="submit" class="btn btn-primary">Save</button>
                    </form>
                </div>
            </div>
        </div>
{% endblock %}

{% block libraries %}
            <link rel="stylesheet" href="/static/lib/bootstrap-datetime/css/bootstrap-datetimepicker.min.css">
            <script src="/static/lib/handlebars/handlebars.js"></script>
            <script src="/static/js/templates.js"></script>
            <script src="/static/lib/moment/moment.min.js"></script>
            <script src="/static/lib/bootstrap-datetime/js/bootstrap-datetimepicker.min.js"></script>

            <script src="/static/js/admin.ui.filters.data.js"></script>
            <script src="/static/js/admin.ui.forms.validate.js"></script>
            <script src="/static/js/admin.control.ajax.js"></script>
{% endblock %}
