{% extends "front/front_base.html" %}
{% load i18n %}
{% load thumbnail %}
{% load front_tags %}

{% block title %}Lignes de temps : {% trans 'search' %} ""{% endblock %}

{% block js_import %}
{{block.super}}
<script src="{{LDT_MEDIA_PREFIX}}js/jquery.min.js" type="text/javascript"/></script>
<script src="{{LDT_MEDIA_PREFIX}}js/jquery.sparkline.min.js" type="text/javascript"/></script>
{% endblock %}

{% block css_import %}
{{block.super}}
<link rel="stylesheet" href="{{LDT_MEDIA_PREFIX}}css/front_search.css" type="text/css"/>
{% endblock %}

{% block body %}
{{block.super}}
<script type="text/javascript">
    $(document).ready(function () {
        // We draw the annotation volume for each content
        /* Use 'html' instead of an array of values to pass options 
        to a sparkline with data in the tag */
        $('.graph_annotation').sparkline('html', {width: '340px',
        										  height:'25px',
        										  minSpotColor: false,
        										  maxSpotColor: false,
        										  spotColor: false,
        										  lineWidth: '0px',
        										  fillColor: '#adadad',
        										  lineColor: '#adadad'});
        
        // We put the annotations into an object
        var annots = [];
        width_max = 340;
        {% for res in results.object_list %}
        // We get the canvas
        var cnv = $('#{{ res.content.iri_id }}').children()[0];
        var ctx = cnv.getContext("2d");
        var content_dur = {{ res.content.duration }};
            {% for segment in res.list %}
            // We draw the segment in the canvas
		    ctx.fillStyle = 'rgba(244,154,245,0.5)';
            x = (width_max*{{segment.begin}})/content_dur;
            y = 0;
            w = (width_max*{{segment.duration}})/content_dur;;
            h = 25;
		    ctx.fillRect (x, y, w, h);
            {% endfor %}
        {% endfor %}
        // We draw
    });
</script>

{% if msg %}
{{ msg }}
{% else %}
  {% ifequal nb_results 0 %}
    {% blocktrans %} No results for <b>{{ search }}</b>.{% endblocktrans %}
  {% else %}
<!-- TABLE POUR ALIGNER À LA VERTICALE -->
    <table id="tbl_rech">
    <tr>
<!-- LISTE DES RÉSULTATS -->
        <td>
        <ul class="floatlist" id="liste_resultats">
    <!-- titre "Résultats de recherche" et options -->
            <li id="li_haut_resultats">
                <ul class="floatlist" id="ul_haut_resultats">
                    <li id="title_resultats">
                        <h2>{% trans "Search results for " %} <b> {{ search }}</b></h2>
                    </li>
                    <li>
                        <p id="p_nb_resultats">{{ nb_results }} {% trans "Result" %}{{ nb_results|pluralize }}</p>
                    </li>
                    <!--li id="resultats_options">options</li-->
                </ul>
            </li>
    <!-- Médias trouvés -->
    
        <!-- Média -->
        {% autoescape off %}
        {% for res in results.object_list %}
            <li class="li_result_media">
                <div class="titre_result_media">
                    <div class="h3_result_media">
                        <h3>{{res.content_title|capfirst}}</h3>
                    </div>
                    <div class="duree_result_media">
                        <p>{{res.content.duration|str_duration:"::"}}</p>
                    </div>
                    <div class="graphe_result_media">
                    	<span id="{{ res.content.iri_id }}" class="graph_annotation">
                    	{{ res.content.stat_annotation }}
                    	</span>
                    </div>
                </div>
        
            <!-- Segments du média -->
                <ul class="floatlist list_segments">
                {% for segment in res.list %}
                    <li class="li_segment">
                        <div class="left_segment">
                            <div class="color_zone" style="background: #f49af5;"></div>
                            <a href="{% url ldt.ldt_utils.views.lignesdetemps.index_segment segment.project_id segment.iri_id segment.ensemble_id segment.decoupage_id segment.element_id %}"><img src="{{LDT_MEDIA_PREFIX}}img/annot_icon_80x45.png" width="80" height="45" /></a>
                            <!--p class="duree_segment">{{ segment.duration|str_duration:"::" }}</p-->
                        </div>
                        <h4 class="title_segment"><a class="blue under" href="{% url ldt.ldt_utils.views.lignesdetemps.index_segment segment.project_id segment.iri_id segment.ensemble_id segment.decoupage_id segment.element_id %}">
                          {% if segment.title %}{{ segment.title }}{% else %}{% trans "No title" %}{% endif %}</a></h4>
                        <p class="text_segment">{% if segment.context %}{{ segment.context }}{% endif %}<br/>{% trans "Begin" %} : {{ segment.begin|str_duration:"::" }} - {% trans "duration" %} : {{ segment.duration|str_duration:"::" }}</h4>
                    </li>
	                <!--li class="segmentinfos" ><span  class="" title="{% trans 'open ldt' %}"><a class="ldt_link_open_ldt" href="{% url ldt.ldt_utils.views.lignesdetemps.index_segment segment.project_id segment.iri_id segment.ensemble_id segment.decoupage_id segment.element_id %}"-->
	                </li>
                {% endfor %}
                </ul>
            </li>
      {% endfor %}
      {% endautoescape %}
      <!-- Fin des médias -->
      <!-- Pagination -->
        <li id="result_pagination">
            <p>
            {% if results.has_previous %}
	            <a class="blue under" href="{% url ldt.ldt_utils.views.front.search_listing %}?page={{ results.previous_page_number }}">{% trans "previous" %}</a>
	            .
	        {% endif %}
	        {% if results.paginator.num_pages > 1 %}
	        <span class="current">
	            {% for i in results.paginator.num_pages|get_range %}
	            <span class="current">
	                {% if i|add:'1' == results.number %}
	                <span class="pink">{{i|add:'1'}}</span>
	                {% else %}
	                <a class="blue under" href="{% url ldt.ldt_utils.views.front.search_listing %}?page={{i|add:'1'}}">{{i|add:'1'}}</a>
	                {% endif %}
	                {% if i|add:'1' < results.paginator.num_pages and 1 < results.paginator.num_pages %}
	                .
                    {% endif %}
	            </span>
	            {% endfor %}
	        </span>
	        {% endif %}
	        {% if results.has_next %}
	            .
	            <a class="blue under" href="{% url ldt.ldt_utils.views.front.search_listing %}?page={{ results.next_page_number }}">{% trans "next" %}</a>
	        {% endif %}
            </p>
        </li>
      <!-- Fin Pagination -->
      </ul>
    

<!-- Right column -->
<!-- APERÇU DU RÉSULTAT -->
    <td id="result_preview">
        <h4>ICI PREVIEW ?</h4>
        <p class="bigmargin">Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem …</p>
    </td>
  </tr>
</table>

  {% endifequal %}
{% endif %}

{% endblock %}

