{% extends "admin/base_site.html" %}
{% load i18n admin_urls admin_static admin_list custom %}
{% block  navbar-fixed %} navbar-fixed{% endblock %}
{% block extrastyle %}
    {{ block.super }}
    {% if cl.formset or action_form %}
        <script type="text/javascript" src="{% url 'admin:jsi18n' %}"></script>
    {% endif %}
    {% if not actions_on_top and not actions_on_bottom %}
        <style>
            #changelist table thead th:first-child {
                width: inherit
            }
        </style>
    {% endif %}
{% endblock %}

{% block extrahead %}
    {{ block.super }}
    {{ media.js }}
    {% if action_form %}{% if actions_on_top or actions_on_bottom %}
        <script type="text/javascript">
            (function ($) {
                $(document).ready(function ($) {
                    $("tr input.action-select").actions();
                });
            })(django.jQuery);
        </script>
    {% endif %}{% endif %}
{% endblock %}

{% block bodyclass %}{{ block.super }} app-{{ opts.app_label }} model-{{ opts.model_name }} change-list{% endblock %}

{% if not is_popup %}
    {% block breadcrumbs %}
        <div class="breadcrumbs">
        <nav class="{{ request.ADMIN_COLOR_THEME }}">
            <div class="nav-wrapper">
                <div class="col s12">
                    <a href="{% url 'admin:index' %}">{% trans 'Home' %}</a>
                    &rsaquo; <a href="{% url 'admin:app_list' app_label=cl.opts.app_label %}">{{ cl.opts.app_config.verbose_name }}</a>
                    &rsaquo; {{ title }}
                </div>
            </div>
        </nav>
    {% endblock %}
{% endif %}
{% block coltype %}flex{% endblock %}
{% block content %}
    <div class="card-panel">
        <div class="row">
            <div class="col l12">
                {% if cl.formset.errors %}
                    <p class="errornote">
                        {% if cl.formset.total_error_count == 1 %}{% trans "Please correct the error below." %}
                        {% else %}
                            {% trans "Please correct the errors below." %}{% endif %}
                    </p>
                    {{ cl.formset.non_form_errors }}
                {% endif %}
            </div>
        </div>
        <div class="module{% if cl.has_filters %} filtered{% endif %}" id="changelist">
            {% block search %}{% search_form cl %}{% endblock %}
            <form id="changelist-form" method="post"{% if cl.formset.is_multipart %}
                  enctype="multipart/form-data"{% endif %} novalidate>{% csrf_token %}
                {% if cl.formset %}
                    <div>{{ cl.formset.management_form }}</div>
                {% endif %}
                {% block result_list %}
                    <div class="row">
                    {% if action_form and actions_on_top and cl.show_admin_actions %}{% admin_actions %}{% endif %}
                    </div>
                    <div class="row">
                        <div class="s12">
                            {% if actions_selection_counter %}
                                <script type="text/javascript">var _actions_icnt = "{{ cl.result_list|length|default:"0" }}";</script>
                               <strong> <span class="action-counter" data-actions-icnt="{{ cl.result_list|length }}">{{ selection_note }}</span>
                                {% if cl.result_count != cl.result_list|length %}
                                <span class="all" style="display:none">{{ selection_note_all }}</span>
                                <span class="question" style="display:none">
                                    <a href="javascript:;" title="{% trans "Click here to select the objects across all pages" %}">{% blocktrans with cl.result_count as total_count %}Select all {{ total_count }} {{ module_name }}{% endblocktrans %}</a>
                                </span>
                                <span class="clear"  style="display:none"><a href="javascript:;">{% trans "Clear selection" %}</a></span>
                                {% endif %}
                                </strong>
                            {% endif %}
                        </div>
                     </div>
                    {% result_list cl %}
                    {% if action_form and actions_on_bottom and cl.show_admin_actions %}{% admin_actions %}{% endif %}
                {% endblock %}
                {% block pagination %}{% pagination cl %}{% endblock %}
            </form>
        </div>
        {% if has_add_permission %}
            {% url cl.opts|admin_urlname:'add' as add_url %}
            <div class="fixed-action-btn">
                <a class="btn-floating btn-large waves-effect waves-light {{ request.ADMIN_COLOR_THEME }} z-depth-2 tooltip"
                   href="{% add_preserved_filters add_url is_popup to_field %}" title="Add new {{ opts.verbose_name }}">
                    <i class="mdi-content-add"></i>Add {{ opts.verbose_name }}
                </a>
            </div>
        {% endif %}
    </div>
{% endblock %}
{% block sidebar %}
  {% block filters %}
{% if cl.has_filters %}
 <div class="card-panel">
        <h4 class="header2 {{ request.ADMIN_COLOR_THEME }}-text">{% trans 'Filter' %}</h4>
 {% for spec in cl.filter_specs %}
     {% admin_list_filter cl spec %}
 {% endfor %}
    </div>
      {% endif %}
    {% endblock %}
    {% block date_hierarchy %}{% date_hierarchy cl %}{% endblock %}
{% endblock %}
{% block extrajs %}
<script type="text/javascript">
(function($) {
  $(document).ready(function($) {
    /*
      Search form
     */
    $('#searchbar').keyup(function (e) {
      if(e.keyCode == 13) {
        $("#searchbar_hidden").attr('name', $('#searchbar').data('name'));
        $("#searchbar_hidden").val($('#searchbar').val());
        $("#changelist-search").submit();
      }
    });
    $("#changelist-search-button").click(function() {
      $("#searchbar_hidden").attr('name', $('#searchbar').data('name'));
      $("#searchbar_hidden").val($('#searchbar').val());
      $("#changelist-search").submit();
    });
    $(".admin-filter").change(function() {
      window.location.href = $(this).val();
    });
    $(".date_hierarchy").change(function() {
      window.location.href = $(this).val();
    });
  });
  })(jQuery);
</script>
{% endblock %}
