{% extends "template.html" %}
{% block content %}
  
  <div class="row">
    <div class="span7">
      <h2>{{class_name}}</h2>
    </div>
    <div class="span5">
      {% if sortable %}
      <div class="btn-group pull-right">
        <a href="#" class="btn"><i class="icon-filter"></i>Order</a>
        <a href="#" data-toggle="dropdown" class="btn dropdown-toggle"><span class="caret"></span></a>
        <ul class="dropdown-menu">
          {% for field in fields %}
            <li>
              <a href="?order={{field}}">{{field}}</a>
            </li>
          {% endfor%}
          <li class="divider"></li>
          <li><a href="?">No order</a></li>
        </ul>
      </div>
      {% endif %}
      {% if editable %}
      <a class="btn pull-right" href="/new/{{class_name}}">
        <i class="icon-plus-sign"></i>New Item
      </a>
      {% endif %}
    </div>

  </div>
  {% if index_chart %}
    <div>
      {{index_chart|safe}}
    </div>
  {% endif %}
  {{ pagination.info|safe }}
  {{ pagination.links|safe }}
  <table class="table table-bordered table-striped table-hover">
    <thead>
      <tr>
          <td></td>
          {% for field in fields%} 
              <th>{{field}}</th>
          {% endfor %}
      </tr>
    <thead>
    <tbody>
        {% for item in items %} 
            <tr>
                {% for col in item %} 
                    <td>
                      {% if loop.index == 1 %}
                        <a href="/{{class_name}}/{{col.1}}">{{col.0}}</a>
                      {% else %}
                        {% if col.3 %}
                            <a href="{{ col.3 }}">{{ col.1 }}</a>
                        {% else %}
                            {{ col.1|safe }}
                        {% endif %}
                      {% endif %}
                    </td>
                {% endfor %}
            </tr>
        {% endfor %}
    </tbody>
  </table>
  {{ pagination.links|safe }}
    <ul class="pager">
      <li class="previous">
        <a href="..">← Back</a>
      </li>
    </ul>
{% endblock %}  
