{% extends "p4l/base.html" %}
{% load static %}
{% load i18n %}
{% load p4lstringfilters %}

{% block page_title %}{% trans 'Record List' %} - {% trans 'Page' %} {{ page.number }}{% endblock %}

{% block js_page %}
<script type="text/javascript" src="{% static 'p4l/lib/jquery-1.9.1.js' %}"></script>
<script type="text/javascript" src="{% static 'p4l/js/p4l_home.js' %}"></script>
{% endblock %}

{% block content %}
<div class="row">
	<h3 class="col-md-6">{% trans 'Record List' %}</h3>
	<div class="col-md-6 text-right">
	  <form method="GET" class="form-inline" role="form">
	    <div class="form-group">
	        <input id="search-input" class="form-control" type="search" placeholder="{% trans 'Query' %}" name="q" value="{{query}}"></input><span id="search-input-cancel" class="glyphicon glyphicon-remove" {% if not query %}style="display: none;"{% endif %}></span>
	    </div>
	    <div class="form-group">
	      <button type="submit" class="btn btn-default"><i class="glyphicon glyphicon-search"></i></button>
	    </div>
      - <a class="btn btn-default" href="{% url 'p4l_record_new' %}?previous={{request.get_full_path|urlencode}}">{% trans 'New record' %} <i class="glyphicon glyphicon-plus-sign"></i></a>
	  </form>
	</div>
</div>
<div class="pagination pull-right">
  {% if page.has_previous or page.has_next %}
    <ul class="pagination">
        <li class="{% if page.number == 1 %}disabled{% endif %}"><a {% if page.number != 1 %}href="?page=1&q={{query}}"{% endif %}>&lt;&lt;</a></li>
        <li class="{% if not page.has_previous %}disabled{% endif %}"><a {% if page.has_previous %}href="?page={{ page.previous_page_number }}&q={{query}}"{% endif %}>&lt;</a></li>
        {% for p in page.visible_page_range %}
        {% if p == 0 %}
        <li class="disabled"><a>&hellip;</a></li>
        {% elif p == page.number %}
        <li class="active"><a>{{ page.number }}</a></li>
        {% else %}
        <li><a href="?page={{ p }}&q={{query}}">{{ p }}</a></li>
        {% endif %}
        {% endfor %}
        <li class="{% if not page.has_next %}disabled{% endif %}"><a {% if page.has_next %}href="?page={{ page.next_page_number }}&q={{query}}"{% endif %}>&gt;</a></li>
        <li class="{% if not page.has_next or page.number == paginator.num_pages %}disabled{% endif %}"><a {% if page.has_next and page.number != paginator.num_pages %}href="?page={{ paginator.num_pages }}&q={{query}}"{% endif %} >&gt;&gt;</a></li>
    </ul>
{% else %}
    <span>&nbsp;</span>
{% endif %}    
</div>

<table class="table">
  <thead>
    <tr><td>{% trans 'identifier' %}</td><td>{% trans 'titles' %}</td><td>{% trans 'dates' %}</td><td class="two_buttons">{% trans 'actions' %}</td></tr>
  </thead>
  <tbody>
  {% for result in page.object_list %}
    <tr>
      <td>{{ result.get_stored_fields.identifier }}</td>
      <td><ul>{% for t in result.get_stored_fields.titles_src %}
          <li>{{ t }}</li>
          {% endfor %}</ul></td>
      <td>{{ result.get_stored_fields.years|join:", "}}</td>
      <td>
        <a class="btn btn-default" href="{% url 'p4l_record_view' slug=result.get_stored_fields.identifier %}?previous={{request.get_full_path|urlencode}}"><i class="glyphicon glyphicon-eye-open"></i></a>
        <a class="btn btn-default" href="{% url 'p4l_record_edit' slug=result.get_stored_fields.identifier %}?previous={{request.get_full_path|urlencode}}"><i class="glyphicon glyphicon-pencil"></i></a>
      </td>
    </tr>
  {% empty %}
    <tr><td>{% trans 'No record' %}</td></tr>
  {% endfor %}
  </tbody>
</table>
{% if is_paginated %}
<div class="pagination pull-right">
    <span class="page-links">
        {% if page.has_previous %}
            <a href="?page={{ page.previous_page_number }}{% for k,v in filter_params.items %}&{{k}}={{v}}{% endfor %}">{% trans 'Previous' %}</a>
        {% endif %}
        <span class="page-current">
            {% trans 'Page' %} {{ page.number }} {% trans 'on' %} {{ page.paginator.num_pages }}
        </span>
        {% if page.has_next %}
            <a href="?page={{ page.next_page_number }}{% for k,v in filter_params.items %}&{{k}}={{v}}{% endfor %}">{% trans 'Next' %}</a>
        {% endif %}
    </span>
</div>
{% endif %}
{% endblock %}