{% extends 'iconolab_base.html' %}

{% load thumbnail %}
{% load iconolab_tags %}

{% block content %}

  <h2>Recherche</h2>

  <form method="get" class="form-inline" action="{% if collection_name %}{% url 'search_indexes:collection_search' collection_name %}{% else %}{% url 'search_indexes:global_search' %}{% endif %}">
    <div class="form-group">
      <div class="input-group">
        <div class="input-group-addon">Chercher</div>
        <input id="id_{{form.q.name}}" type="text" class="form-control" name="{{form.q.name}}" placeholder="...">
        <div class="input-group-addon">dans les </div>
        <select class="form-control" id="id_{{form.model_type.name}}" name="{{form.model_type.name}}">
          {% for val, label in form.fields.model_type.choices %}
              <option value="{{ val }}"{% if label == 'Images' %} selected{% endif %}>{{ label }}</option>
          {% endfor %}
        </select>
        {% if collection %}
          <div class="input-group-addon">du fonds {{collection.verbose_name}}</div>
        {% else %}
          <div class="input-group-addon">du site</div>
        {% endif %}
      </div>
    </div>
    <input type="submit" class="search-submit btn btn-primary" value="Rechercher" style="margin-left: 10px;">
  </form>
  <h3><strong>{{ page_obj.paginator.count }}</strong> image(s)</h3>
  <div class="row">
    <div id="list-items" class="col-md-12">
      <ul class="search-image-list-wrapper list-unstyled">
        {% for item in page_obj.object_list %}
          <li class="search-image-list-li container panel panel-default col-md-12">
            <div class=" pull-left search-image-container row search-image-list-image-container col-md-5" style="vertical-align:middle; display: inline-block; padding-top:10px; padding-bottom:10px;">
              {% include "partials/item_images_preview.html" with item=item.object %}
            </div>
            <div class="search-item-info text-left col-md-7" style="display:inline-block; margin: 10px 0px;">
              <h1 class="search-title" style="display:inline-block; margin-top: 0px;"><small>Métadonnées de l'objet</small></h1>
               <a class="btn btn-default btn-xs pull-right collection-home-item-btn" href="{% url 'item_detail' item.object.collection.name item.object.item_guid %}" style="display:inline-block;"><i class="fa fa-eye"></i> Détail de l'objet</a>
              {% if item.object.metadatas.designation %}<h3>Désignation : <small>{{item.object.metadatas.designation}}</small></h3>{% endif %}
              {% if item.object.metadatas.authors %}<h4>Auteur(s) : <small>{{item.object.metadatas.designation}}</small></h4>{% endif %}
              {% if item.object.metadatas.conservation_location %}<h4>Conservé à : <small>{{item.object.metadatas.conservation_location}}</small></h4>{% endif %}
              {% if item.object.metadatas.datation %}<h4>Datation : <small>{{item.object.metadatas.datation}}</small></h4>{% endif %}
              {% if item.object.metadatas.technics %}<h5>Techniques : <small>{{item.object.metadatas.technics}}</small></h5>{% endif %}
              {% if item.object.metadatas.measurements %}<h5>Mesures : {{item.object.metadatas.measurements}}</h5>{% endif %}
              {% if item.object.metadatas.create_or_usage_location %}<h5>Lieu de création/utilisation : <small>{{item.object.metadatas.create_or_usage_location}}</small></h5>{% endif %}
              {% if item.object.metadatas.discovery_context %}<h5>Contexte de découverte : <small>{{item.object.metadatas.discovery_context}}</small></h5>{% endif %}
              {% if item.object.metadatas.photo_credits %}<h5>Crédits photographiques : <small>{{item.object.metadatas.photo_credits}}</small></h5>{% endif %}
              {% if item.object.metadatas.inventory_number %}<h5>Numéro d'inventaire : <small>{{item.object.metadatas.inventory_number}}</small></h5>{% endif %}
            </div>
          </li>
        {% endfor %}
      </ul>
      <ul class="pagination pull-right items-perpage" style="margin-left: 15px;">
        <li class="active pagination-label"><a>Objets par page : </a></li>
        <li class="{% if page_obj.paginator.per_page == 5 %}active{% endif %}">
        <a href="?q={{ query }}&perpage=5">5</a>
        </li>
        <li class="{% if page_obj.paginator.per_page == 10 %}active{% endif %}">
        <a href="?q={{ query }}&perpage=10">10</a>
        </li>
        <li class="{% if page_obj.paginator.per_page == 25 %}active{% endif %}">
        <a href="?q={{ query }}&perpage=25">25</a>
        </li>
        <li class="{% if page_obj.paginator.per_page == 100 %}active{% endif %}">
        <a href="?q={{ query }}&perpage=100">100</a>
        </li>
      </ul>
      {% if page_obj.has_previous or page_obj.has_next %}
        <ul class="pagination pull-right items-pagination">
          {% if page_obj.has_previous %}
          <li>
            <a href="?page={{page_obj.previous_page_number}}&perpage={{page_obj.paginator.per_page}}" aria-label="Précédent">
              <span aria-hidden="true">&laquo;</span>
            </a>
          </li>
          {% endif %}

          {% for page in page_obj.paginator.page_range %}
            <li id="page-link-{{page}}" class="pagination-link {% if page == page_obj.number %}active{% endif %}">
              <a {% if page != page_obj.number %}href="?q={{query}}&page={{page}}&perpage={{page_obj.paginator.per_page}}"{% endif %}>{{page}}</a>
            </li>
          {% endfor %}

          {% if page_obj.has_next %}
          <li>
             <a href="?page={{page_obj.next_page_number}}&perpage={{page_obj.paginator.per_page}}" aria-label="Précédent">
              <span aria-hidden="true">&raquo;</span>
             </a>
          </li>
          {% endif %}
        </ul>
      {% endif %}
    </div>
  </div>
{% endblock %}
