{% extends 'admin/base_site.html' %}
{% load i18n admin_urls admin_static %}

{% block extrahead %}
    {{ block.super }}
    <script src="{% static "admin/js/vendor/jquery/jquery.min.js" %}"></script>
    <script src="{% static "admin/js/jquery.init.js" %}"></script>
    <script type="text/javascript">
        (function ($) {
            window.show_fields = function (event, model_ct, field, path) {
                var check_default = $("#check_all").is(':checked');
                $(event.target.parentNode).load(location.pathname, $.param({
                    related: 1,
                    model_ct: model_ct,
                    field: field,
                    path: path,
                    check_default: check_default
                }));
            };
            $(function () {
                $("#check_all").click(function () {
                    var checked = !!this.checked;
                    $('.check_field').prop('checked', checked);
                });
            });
        }(django.jQuery));

    </script>
{% endblock %}

{% block breadcrumbs %}
    <div class="breadcrumbs">
        <a href="{% url 'admin:index' %}">{% trans 'Home' %}</a>
        &rsaquo; <a href="{% url 'admin:app_list' app_label=opts.app_label %}">{{ opts.app_config.verbose_name }}</a>
        &rsaquo; {% if has_change_permission %}
        <a href="{% url opts|admin_urlname:'changelist' %}">{{ opts.verbose_name_plural|capfirst }}</a>{% else %}
        {{ opts.verbose_name_plural|capfirst }}{% endif %}
        &rsaquo; {% trans 'Export' %}
    </div>
{% endblock %}


{% block content %}
    <h2> {% trans "Export" %} {{ opts.verbose_name_plural }} ({{ queryset.count }}) </h2>
    <p>
        {% for object in queryset|slice:":10" %}
            {{ object }}
            {% if not forloop.last %},{% endif %}
        {% endfor %}
        {% if queryset.count > 10 %}...{% endif %}
    </p>

    <br/>
    <div>
        <form method="post" action="">
            {% csrf_token %}
            <table>
                <tr class="export_table">
                    <th class="export_table">
                        <input type="checkbox" id="check_all">
                    </th>
                    <th class="export_table">
                        <label for="check_all">{% trans "Select all" %}</label>
                    </th>
                </tr>

                {% include "export_action/fields.html" %}
            </table>
            <br/>
            <hr/>
            <br/>
            <label for="__format">{% trans "Format" %}
                <select name="__format">
                    <option value="xlsx">XLSX</option>
                    <option value="html">HTML</option>
                    <option value="csv">CSV</option>
                </select>
            </label>
            <input type="submit" value="{% trans "Export" %}"/>
        </form>
    </div>

{% endblock %}
