{% extends "mongonaut/base.html" %}
{% load mongonaut_tags %}

{% block breadcrumbs %}
<li><a href="{% url index %}">Mongonaut</a> <span class="divider">/</span></li>
<li><a href="">{{ document_name }}s</a></li>
{% endblock %}


{% block content %}

<h1>{{ document_name }} List</h1>

{% if search_field %}
    <form action="" method="get">
        <input type="text" name="q">
        <input type="submit" class="btn small info" value="search">
    </form>
{% endif %}
{% if has_add_permission %}
    <a href="{% url document_detail_add_form app_label document_name %}">Add</a>
{% endif %}
{% if request.user.is_superuser %}
    <form action="" method="post">
    {% csrf_token %}
    {% include "mongonaut/actions/action_buttons.html" %}
{% endif %}
<table class="bordered-table zebra-striped">
    <thead>
        <tr>
            {% if request.user.is_superuser %}<th><input type="checkbox" name="check_all" /></th>{% endif %}
            {% for key in keys %}
                <th>{{ key }}</th>
            {% endfor %}
        </tr>
    </thead>
        
    {% for obj in object_list %}
        <tr>
            {% if request.user.is_superuser %}<td><input type="checkbox" name="mongo_id" value="{{ obj.id }}" /></td>{% endif %}
            {% for key in keys %}
                {% if key == 'id' %}
                    <td><a href="{% url document_detail app_label document_name obj.id %}">{{ obj.id }}</a></td>                                
                {% else %}
                    <td>{% get_document_value obj key %}</td>                
                {% endif %}

            {% endfor %}
        </tr>
    {% endfor %}
</table>    
{% if request.user.is_superuser %}
    {% include "mongonaut/actions/action_buttons.html" %}
{% endif %}
</form>

<div class="pagination">
  <ul>
        {# TODO {% if object_list.has_previus %} #}
        <li class="prev"><a href="?page={{ previous_page_number }}">&larr; Previous</a></li>
        <li class="active"><a href="#">{{ page }} of {{ total_pages }}</a></li>
        {# TODO {% if object_list.has_next %} #}    
        <li class="next"><a href="?page={{ next_page_number }}">Next &rarr;</a></li>
  </ul>
</div>


{% endblock %}

{% block extrajs %}
<script type="text/javascript">
$(function() {
    $('input[name="check_all"]').click ( function() {
        if ($(this).is(":checked" )){
            $('input[name="mongo_id"]').prop("checked", true);
        }       
        else
         {
            $('input[name="mongo_id"]').prop("checked", false);
         }
    });
});
</script>
{% endblock %}