{% extends "ajax_forms/base_site.html" %}
{% load i18n admin_static admin_list %}
{% load admin_urls %}
{% load daf_help %}

{% block extrastyle %}
  {{ block.super }}
  {#<link rel="stylesheet" type="text/css" href="{% static "admin/css/changelists.css" %}" />#}
  {% if cl.formset %}
    {#<link rel="stylesheet" type="text/css" href="{% static "admin/css/forms.css" %}" />#}
  {% endif %}
  {% if cl.formset or action_form %}
    <script type="text/javascript" src="{% url 'admin:jsi18n' %}"></script>
  {% endif %}
  {{ media.css }}
  {% 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();
        $("tr input.action-select").daf_actions({
            actionContainer: "div.pagination",
	        //counterContainer: "span.action-counter",
	        allContainer: "div.pagination span.all",
	        acrossInput: ".actions input.select-across",
	        acrossQuestions: "div.pagination .question",
	        acrossClears: "div.pagination .clear",
	        //allToggle: "#action-toggle",
	        //selectedClass: "selected"
	    });
    });
})(django.jQuery);
</script>
{% endif %}{% endif %}
{% endblock %}

{% block bodyclass %}{{ block.super }} change-list{% endblock %}

{% block header %}
    <h2>
        {% if title %}
            {{ title|safe }}
        {% else %}
            {% for breadcrumb in breadcrumbs %}{% if not forloop.first %} &rsaquo; {% endif %}{{ breadcrumb }}{% endfor %}
        {% endif %}
        
    {% block object-tools %}
      {% if has_add_permission %}
        <ul class="object-tools">
          {% block object-tools-items %}{% if show_add_button %}
            <li>
              <a href="{% url cl.opts|admin_urlname:'add' %}{% if is_popup %}?_popup=1{% endif %}" class="addlink btn btn-default btn-xs">
                {{ add_button_name }}
              </a>
            </li>
          {% endif %}{% endblock %}
        </ul>
      {% endif %}
    {% endblock %}
    
    </h2>
{% endblock %}

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

{% block coltype %}flex{% endblock %}

{% block content %}
  <div class="row-fluid">
    {% 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>
        {{ cl.formset.non_form_errors }}
    {% endif %}
    <div class="module{% if cl.has_filters %} filtered{% endif %}" id="changelist">
    
        {% block search %}
            {% if cl.search_fields %}
                <div id="toolbar" style="display:none;">
                    <form id="changelist-search" action="" method="get">
                        <div style="float:left;"><!-- DIV needed for valid HTML -->
                            <input
                            type="text" size="40" name="{{ search_var }}" placeholder="keywords" value="{{ cl.query }}" id="searchbar" style="display:inline; vertical-align:top;" />&nbsp;<input
                            type="submit" class="btn" value="{% trans 'Search' %}" id="searchgo" style="display:inline;" />
                            {% if show_result_count %}&nbsp;<span
                                class="small quiet">{% blocktrans count counter=cl.result_count %}{{ counter }} result{% plural %}{{ counter }} results{% endblocktrans %} (<a href="?{% if cl.is_popup %}pop=1{% endif %}">{% blocktrans with full_result_count=cl.full_result_count %}{{ full_result_count }} total{% endblocktrans %}</a>)</span>
                            {% endif %}
                            {% for pair in cl.params.items %}
                                {% ifnotequal pair.0 search_var %}<input type="hidden" name="{{ pair.0 }}" value="{{ pair.1 }}"/>{% endifnotequal %}
                            {% endfor %}
                        </div>
                    </form>
                </div>
            {% endif %}
        {% endblock %}
        
        {% block date_hierarchy %}{% date_hierarchy cl %}{% endblock %}

        <form id="changelist-form" action="" method="post"{% if cl.formset.is_multipart %} enctype="multipart/form-data"{% endif %}>{% csrf_token %}
            <div class="row-fluid top-toolbar">
                {% if cl.search_fields %}
                    <div class="row-span">
                        <input
                            type="text" size="40" name="{{ search_var }}" placeholder="keywords" value="{{ cl.query }}" id="searchbar-fake" style="display:inline; vertical-align:top;" />&nbsp;<input
                            type="submit" class="btn" value="{% trans 'Search' %}" id="searchgo-fake" style="display:inline;" />
                            {% if show_result_count %}&nbsp;<span
                                class="small quiet">{% blocktrans count counter=cl.result_count %}{{ counter }} result{% plural %}{{ counter }} results{% endblocktrans %} (<a href="?{% if cl.is_popup %}pop=1{% endif %}">{% blocktrans with full_result_count=cl.full_result_count %}{{ full_result_count }} total{% endblocktrans %}</a>)</span>
                            {% endif %}
                    </div>
                    <script type="text/javascript">
                    (function($){
                        $('#searchbar-fake').blur(function(){
                            var el = $(this);
                            $('#searchbar').val(el.val());
                        });
                        $('#searchbar-fake').keypress(function (e) {
                            if(e.which == 13){
                                $('#searchbar').val($('#searchbar-fake').val());
                                $('#searchgo').click();
                                //console.log('enter');
                                return false;
                            }
                        });
                        $('#searchgo-fake').click(function(){
                            $('#searchgo').click();
                            return false;
                        });
                    })(django.jQuery);
                    </script>
                    <script type="text/javascript">document.getElementById("searchbar-fake").focus();</script>
                {% endif %}
                <div class="row-span">
                    {% if action_form and actions_on_top and cl.full_result_count %}{% daf_admin_actions %}{% endif %}
                </div>
            </div>
            {% if pagination_required %}
                <div class="row-fluid">
                    <div class="span12">{% pagination cl %}</div>
                </div>
            {% endif %}
            <div class="row-fluid">
                <div class="span10">
                    {% if cl.formset %}
                        <div>{{ cl.formset.management_form }}</div>
                    {% endif %}
                    {% block result_list %}
                        {% daf_result_list cl %}
                    {% endblock %}
           
                    {% if action_form and actions_on_bottom and cl.full_result_count %}{% admin_actions %}{% endif %}
               
                    {% if pagination_required %}{% pagination cl %}{% endif %}
                </div>
                <div class="span2">
                    {% block filters %}
                        {% if cl.has_filters %}
                        <div id="changelist-filter" class="well sidebar-nav">
                            <h2>{% trans 'Filter' %}</h2>
                            {% for spec in cl.filter_specs %}
                                {% admin_list_filter cl spec %}
                            {% endfor %}
                        </div>
                        {% endif %}
                    {% endblock %}
                </div>
            </div>
        </form>
    </div>
  </div>
{% endblock %}
