{% extends base_template %}
{% load i18n staticfiles crud_tags bootstrap3 %}
{% block extrastyle %}
{{ media }}
{% endblock %}
{% block content %}
{% if actions|length or item_actions|length %}<form id="id_form_action" role="form" action="" method="post">{% csrf_token %}{% endif %}
<script>
function addNewItemThunk() {
{% if add_item_custom_url|length %}
    window.location = "{{ add_item_custom_url }}";
{% else %}
    addNewItem();
{% endif %}
}
function editItemThunk(itemId) {
{% if edit_item_custom_url|length %}
    var editURL = "{{ edit_item_custom_url }}";
    editURL += "?item="+itemId.toString();
    window.location = editURL;
{% else %}
    editItem(itemId);
{% endif %}
}
function deleteItemThunk(itemId) {
{% if edit_item_custom_url|length %}
    var deleteURL = "{{ delete_item_custom_url }}";
    deleteURL += "?item="+itemId.toString();
    window.location = deleteURL;
{% else %}
    deleteItem(itemId);
{% endif %}
}
</script>
<div class="form-group" style="margin-bottom: 5px;">
    {% if allow_create %}
    <button id="addItem" type="button" class="btn btn-primary" title="{{ create_button_text }}" onclick="addNewItemThunk();">{{ create_button_text }}</button>
    {% else %}
    {% if disallowed_create_message %}
    {% bootstrap_alert disallowed_create_message 'info' %}
    {%endif%}
    {% endif %}
    {% if object_list|length > 0 and actions|length %}
    <div class="btn-group" id="id_action_dropdown">
        <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">{% trans "Actions" %}&nbsp;<span class="caret"></span></button>
        <ul class="dropdown-menu" role="menu">
            {% for label, handler in actions %}
            <li><a href="javascript:void(0);" onclick="invokeAction('{{ handler }}');">{{ label }}</a></li>
            {% endfor %}
        </ul>
    </div>
    {% endif %}
</div>
{% if object_list|length > 0 %}
<table class="{{ table_css_classes }}">
<thead>
    <tr>
        {% for name in list_display %}
        <th>{% if actions|length %}{% if forloop.first %}<input class="item-selection-checkbox-header" type="checkbox" id="id_select_all"></input>&nbsp;&nbsp;{% endif %}{% endif %}{% field_label view name %}</th>
        {% endfor %}
        {% if allow_edit or allow_delete or item_actions|length %}
        <th width="{{ action_col_width }}">{% trans "Action" %}</th>
        {% endif %}
    </tr>
</thead>
<tbody>
{% for object in object_list %}
    {% render_item object forloop.counter0 item_template %}
    {% if forloop.last %}
        <script type="text/javascript" charset="utf-8">
            totalItems = {{ forloop.counter }};
        </script>
    {% endif %}
{% endfor %}
</tbody>
</table>
<div class="row">
    {% if is_paginated %}
    {# bootstrap ul has margin-top set to 20px, remove it #}
    <ul class="pagination pull-right" style="margin-top: -10px; margin-right: 15px;">
        {% if page_obj.has_previous %}
        <li><a href="?{{ page_obj.previous_page_number.querystring }}">&laquo;</a></li>
        {% else %}
        <li class="disabled"><a href="">&laquo;</a></li>
        {% endif %}
        {% comment %}
        {% for p in paginator.page_range %}
            {% if page_obj.number == p %}
            <li class="disabled"><a href="javascript:void(0);">{{p}}</a></li>
            {%else%}
            <li><a href="?page={{p}}">{{ p }}</a></li>
            {%endif%}
        {% endfor %}
        {% endcomment %}
        {% for page in page_obj.pages %}
            {% if page %}
                {% ifequal page page_obj.number %}
                <li class="disabled"><a href="javascript:void(0);">{{ page }}</a></li>
                {% else %}
                <li><a href="?{{page.querystring}}">{{ page }}</a></li>
                {% endifequal %}
            {% else %}
            <li class="disabled"><a href="javascript:void(0);">...</a></li>
            {% endif %}
        {% endfor %}
        <li><a href="?page=all">{% trans 'All' %}</a></li>
        {% if page_obj.has_next %}
        <li><a href="?{{ page_obj.next_page_number.querystring }}">&raquo;</a></li>
        {% else %}
        <li class="disabled"><a href="#">&raquo;</a></li>
        {% endif %}
    </ul>
    {% endif %}
</div>
{% else %}
{% trans "No items" %}
{% endif %}
{% if actions|length %}</form>{% endif %}
{% endblock content %}
