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

{% load i18n static %}

{% block extrahead %}
{{ block.super }}
<link rel="stylesheet" href="{% static "mezzanine/css/admin/form_entries.css" %}">
<script src="{% static "mezzanine/js/admin/form_entries.js" %}"></script>
{% endblock %}

{% block breadcrumbs %}
<div class="breadcrumbs">
     <a href="../../../../">{% trans "Home" %}</a> &rsaquo;
     <a href="../../../">{{ opts.app_label|capfirst|escape }}</a> &rsaquo;
     <a href="../../">{{ opts.verbose_name_plural|capfirst }}</a> &rsaquo;
     <a href="../">{{ original|truncatewords:"18" }}</a> &rsaquo;
     {{ title }}
</div>
{% endblock %}

{% block content %}
<div id="content-main">
    <form method="post">
    {% csrf_token %}
    <table>
        <tr>
            <th>{% trans "Field" %}</th>
            <th>{% trans "Include" %}</th>
            <th class="last" colspan="2">{% trans "Filter by" %}</th>
        </tr>
        {% for include_field, filter_field, filter_option_fields in entries_form %}
        <tr class="{% cycle "on" "off" as row %}">
            <td class="field">{{ include_field.label_tag }}</td>
            <td class="include">{{ include_field }}</td>
            <td class="filter last">{{ filter_field }}</td>
            <td class="options last">
                <div class="options-div">
                    {% for option_field in filter_option_fields %}
                    {{ option_field.label_tag }} {{ option_field }}
                    {% endfor %}
                </div>
            </td>
        </tr>
        {% endfor %}
        <tr class="{% cycle row %}">
            <td class="field" style="text-align:right;">
                <label for="include-all">{% trans "All" %}</label>
            </td>
            <td class="include-all">
                <input type="checkbox" id="include-all" class="include-all" checked="checked" />
            </td>
            <td class="last" colspan="2">&nbsp;</td>
        </tr>
    </table>
    <input type="submit" name="back" class="button" value="{% trans "Back to form" %}" />
    <input type="submit" class="button default" value="{% trans "View entries" %}" />
    <input type="submit" class="button default" name="export" value="{% trans "Export CSV" %}" />
    {% if submitted %}
    <h1 id="entries-title">{% trans "Entries" %}</h1>
    {% for row in entries_form.rows %}
    {% if forloop.first %}
    <table id="entries-table">
        <tr>
            {% if can_delete_entries %}
            <th><input type="checkbox" class="include-all"></th>
            {% endif %}
            {% for column in entries_form.columns %}
            <th{% if forloop.last %} class="last"{% endif %}>{{ column }}</th>
            {% endfor %}
        </tr>
    {% endif %}
        <tr class="{% cycle "on" "off" %}">
            {% if can_delete_entries %}
            <td class="include">
                <input type="checkbox" name="selected" value="{{ row.0 }}">
            </td>
            {% endif %}
            {% for field in row %}
            {% if not forloop.first %}
            <td{% if forloop.last %} class="last"{% endif %}>{{ field }}</td>
            {% endif %}
            {% endfor %}
        </tr>
    {% if forloop.last %}
    </table>
    <!--
    count is injected into the title here with the :after selector
    to avoid calling the expensive "entries_form.rows" twice.
    -->
    <style>#entries-title:after {content: ' ({{ forloop.counter }})';}</style>
    {% if can_delete_entries %}
    <input type="submit" name="back" class="button" value="{% trans "Back to form" %}" />
    <input type="submit" name="delete" class="button default" value="{% trans "Delete selected" %}" />
    {% endif %}
    {% endif %}
    {% empty %}
    <p class="empty">{% trans "No entries to display" %}</p>
    {% endfor %}
    {% endif %}
    </form>
</div>
{% endblock %}
