{% extends "admin/base_site.html" %}

<!-- LOADING -->
{% load static admin_list i18n %}

<!-- STYLES -->
{% block extrastyle %}
    {{ block.super }}

    <link rel="stylesheet" type="text/css" href="{% static "grappelli/css/changelist.css" %}" />
    {% if not actions_on_top and not actions_on_bottom %}
    <style>#changelist table thead th:first-child {width: inherit}</style>
    {% endif %}
    <style>
    #changelist .actions {padding:7px;}
    #changelist .actions label {background:none; padding:0; margin:0;}
    </style>
{% endblock %}

<!-- JAVASCRIPTS -->
{% block extrahead %}
    {{ block.super }}
    <script src="{% static "grappelli/js/admin/Changelist.js" %}"></script>
    {% if is_popup %}
    <script>
        // HACK: REMOVE ACTIONS and LIST_EDITABLES FOR POPUPS
        jQuery(function($) {
            $('div.actions').hide();
            $('p.submit-row').hide();
            $('input.action-select').parent().hide();
            $('input#action-toggle').parent().hide();
        });
    </script>
    {% endif %}
    {% if action_form %}
    <script>
        django.jQuery(function($) {
            $("tr input.action-select").actions({
                allContainer: "div.actions li.all",
                acrossQuestions: "div.actions li.question",
                acrossClears: "div.actions li.clear-selection"
            });
        });
    </script>
    {% endif %}
{% endblock extrahead %}

<!-- COLTYPE/BODYCLASS-- >
{% block coltype %}flex{% endblock %}
{% block bodyclass %}change-list{% endblock %}

<!-- BREADCRUMBS -- >
{% block breadcrumbs %}
{% if not is_popup %}
    <div class="breadcrumbs">
        {% url "admin:index" as admin_index_url %}
        <a href="{{ admin_index_url }}">{% trans "Home" %}</a> &rsaquo;
        <a href="../">{{ app_label|capfirst }}</a> &rsaquo;
        {{ cl.opts.verbose_name_plural|capfirst }}
    </div>
{% endif %}
{% endblock %}

<!-- CONTENT -->
{% block content %}
    <div id="content-main">

        <!-- Object-Tools -->
        {% block object-tools %}
            {% if has_add_permission %}
                <ul class="object-tools">
                    {% block object-tools-items %}
                    <li>
                        <a href="add/{% if is_popup %}?_popup=1{% endif %}" class="focus">
                            {% blocktrans with cl.opts.verbose_name as name %}Add {{ name }}{% endblocktrans %}
                        </a>
                    </li>
                    {% endblock %}
                </ul>
            {% endif %}
        {% endblock %}

        <!-- Errors -->
        {% if cl.formset.errors %}
            <p class="errornote">
            {% blocktrans count cl.formset.errors|length as counter %}Please correct the error below.{% plural %}Please correct the errors below.{% endblocktrans %}
            </p>
            <ul class="errorlist">{% for error in cl.formset.non_field_errors %}<li>{{ error }}</li>{% endfor %}</ul>
        {% endif %}

        <!-- Changelist -->
        <div class="module{% if cl.has_filters or cl.search_fields or cl.date_hierarchy %} filtered{% endif %}" id="changelist">
            <div class="changelist-content">
                <form action="" method="post"{% if cl.formset.is_multipart %} enctype="multipart/form-data"{% endif %}>{% csrf_token %}

                <!-- Popup Hidden Field -->
                {% if is_popup %}<input type="hidden" name="_popup" value="1" />{% endif %}

                <!-- Management Form -->
                {% if cl.formset %}
                    {{ cl.formset.management_form }}
                {% endif %}

                <!-- Results -->
                <div class="result-list-container">
                    {% block result_list %}
                        {% if action_form and actions_on_top and cl.full_result_count and cl.result_count %}{% admin_actions %}{% endif %}
                        {% result_list cl %}
                        {% if action_form and actions_on_bottom and cl.full_result_count and cl.result_count %}{% admin_actions %}{% endif %}
                    {% endblock %}
                    {% block pagination %}{% pagination cl %}{% endblock %}
                </div>

                <!-- Submit-Row -->
                {% if cl.formset and cl.result_count %}
                    <p class="submit-row">
                        <input type="submit" name="_save" class="default" value="{% trans 'Save' %}"/>
                    </p>
                {% endif %}
                </form>
            </div>

            <!-- Sidebar -->
            {% block filters %}
                {% if cl.has_filters or cl.search_fields or cl.date_hierarchy %}
                    <div id="changelist-filter">

                        <!-- Results -->
                        {% if cl.result_count != cl.full_result_count %}
                        <div class="module results">
                            <h2>{% trans 'Results' %}</h2>
                            <div class="form-row">
                                <p>{% blocktrans with cl.result_count as counter %}{{ counter }} found{% endblocktrans %}</p>
                                <a href="?{% if cl.is_popup %}_popup=1{% endif %}">{% blocktrans with cl.full_result_count as full_result_count %}{{ full_result_count }} total{% endblocktrans %}</a>
                            </div>
                        </div>
                        {% endif %}

                        <!-- Search -->
                        {% block search %}{% search_form cl %}{% endblock %}

                        <!-- Date Hierarchy -->
                        {% block date_hierarchy %}{% date_hierarchy cl %}{% endblock %}

                        {% if cl.has_filters %}
                        <!-- Filter -->
                        <div class="module filter">
                            <h2>{% trans 'Filter' %}</h2>
                            {% for spec in cl.filter_specs %}{% admin_list_filter cl spec %}{% endfor %}
                        </div>
                        {% endif %}

                    </div>
                {% endif %}
            {% endblock %}
        </div>

    </div>
{% endblock %}
