{% extends "base.html" %}

{% block bodydata %} data-project-id="{{grouping.project.id}}" data-view-id="{{grouping.id}}"{% endblock %}
{% block title %} | Create new filter rule{% endblock %}

{% block main %}
        <div class="page-header">
            <div class="container">
                <div class="row">
                    <div class="col-sm-6">
                        <h1 class="smaller"><a href="{% url 'admin:project_overview' grouping.project.id %}">{{grouping.project.name}}</a></h1>
                        <a href="{% url 'admin:project_overview' grouping.project.id %}"><span class="glyphicon glyphicon-arrow-left"></span> Project home page</a>
                    </div>
                    <ul class="header-nav">
                        <li><a href="{% url 'admin:category_list' grouping.project.id %}">Categories <span class="badge">{{ grouping.project.categories.count }}</span></a></li>
                        <li class="active"><a href="{% url 'admin:grouping_list' grouping.project.id %}">Data groupings <span class="badge">{{ grouping.project.groupings.count }}</span></a></li>
                        <li><a href="#">User groups <span class="badge">{{ grouping.project.usergroups.count }}</span></a></li>
                    </ul>
                </div>
            </div>
        </div>

        <div class="container">
            <div class="row">
                <div class="col-sm-4">
                    <div class="panel panel-default">
                        <div class="panel-heading">
                            <h6 class="item-info">Data grouping</h6>
                            <h3>{{ grouping.name }}</h3>
                            {% if grouping.description %}<p>{{ grouping.description|linebreaksbr }}</p>{% endif %}
                        </div>
                        <div class="list-group">
                            <a href="{% url 'admin:grouping_overview' grouping.project.id grouping.id %}" class="list-group-item active">Filters</a>
                            <a href="{% url 'admin:grouping_permissions' grouping.project.id grouping.id %}" class="list-group-item">Permissions</a>
                            <a href="{% url 'admin:grouping_settings' grouping.project.id grouping.id %}" class="list-group-item">Settings</a>
                        </div>
                    </div>
                </div>
                <form id="rule-form" role="form" class="col-sm-8" method="POST" action="{% url 'admin:rule_create' grouping.project.id grouping.id %}" novalidate>
                    <h3 class="header">Create new filter</h3>
                    {% csrf_token %}
                    <div class="form-group">
                        <label for="category" class="control-label">Select category</label>
                        <select name="category" id="category" class="form-control">
                            <option value="-1"></option>
                            {% for type in grouping.project.categories.all %}
                                <option value="{{type.id}}">{{type.name}}</option>
                            {% endfor %}
                        </select>
                        <input type="hidden" name="rules" value="{}">
                    </div>
                    <div id="field-options"></div>
                    <div class="form-group">
                        <button type="submit" class="btn btn-primary">Save</button>
                        <a href="{% url 'admin:grouping_overview' grouping.project.id grouping.id %}" class="btn btn-link" role="button">Cancel</a>
                    </div>
                </form>
            </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.grouping.rules.js"></script>
            <script src="/static/js/admin.ui.forms.validate.js"></script>
            <script src="/static/js/admin.control.ajax.js"></script>
{% endblock %}
