{% extends "request_base.html" %}

{% load url from future %}
{% load sekizai_tags %}
{% load editor %}

{% block breadcrumb %}
<p><a href="../">Tableau de bord</a> » Demande n&deg;{{ poly_request.request_number }}

<a class="btn pull-right print" href="javascript:window.print();"><i class="icon-print"></i> Imprimer ce bon</a>
</p>
{% endblock %}

{% block content %}
<div class="row-fluid">
	<div class="span6">
		<div class="well">
      <div class="only-print">
      {% include "detail_template.html" with value=poly_request.request_number name="Demande n&deg;" %}
      </div>
      {% if poly_request.history_set.last_show_in_details %}
        <p><strong>Valideur: {% with validateur=poly_request.history_set.last_show_in_details.user %}{{ validateur.get_full_name }} ({{ validateur.get_ldap_attributes.roomNumber.0 }} - {{ validateur.get_ldap_attributes.telephoneNumber.0 }}){% endwith %}</strong></p>
      {% endif %}
      {% if poly_request.sponsor_username == poly_request.user.username %}
        {% include "detail_template.html" with value=poly_request.user.display_name name="Utilisateur & Commanditaire" %}
      {% else %}
        {% include "detail_template.html" with value=poly_request.user.display_name name="Utilisateur" %}
        {% include "detail_template.html" with value=poly_request.sponsor name="Commanditaire" %}
      {% endif %}
      {% include "detail_template.html" with value=poly_request.status name="Statut" %}

      {% for caption, value in entities %}
        {% include "detail_template.html" with value=value name=caption %}
      {% endfor %}
      {% include "detail_template.html" with value=poly_request.entity.get_description|lower|capfirst name="Entité demandeur" %}
			{% if poly_request.history_set.latest.description %}
			<p><strong>Dernier commentaire de {{ poly_request.history_set.latest.user }} </strong>: « {{ poly_request.history_set.latest.description }} »</p>
			{% endif %}
			<p><a href="{% url 'request_history' pk=poly_request.pk %}">Historique</a></p>
			{% if poly_request.contact_telephone1 %}
			<p><strong>Téléphone</strong> {{ poly_request.contact_telephone1 }}</p>
			{% endif %}
			{% if poly_request.contact_telephone2 %}
			<p>{% if poly_request.contact_telephone1 %}Ature t{% else %}T{% endif %}éléphone: {{ poly_request.contact_telephone2 }}</p>
			{% endif %}
			{% if poly_request.contact_bureau %}
			<p><strong>Bureau</strong> {{ poly_request.contact_bureau }}</p>
			{% endif %}
			{% if poly_request.contact_email %}
			<p><strong>Email</strong> <em>{{ poly_request.contact_email }}</em></p>
			{% endif %}
		</div>
		<div class="well">
      <p><strong>Coût{% if poly_request.cost %}</strong> {{poly_request.cost|floatformat:"-2" }}{% else %} estimé</strong> {{ poly_request.estimated_cost|floatformat:"-2" }}{% endif %} €</p>
      {% include "detail_template.html" with value=poly_request.financial_code name="Code d'imputation" %}
      {% if creation or end %}<p>
         {% if creation %}<strong>Date de la demande</strong> {{creation.date}}{% endif %}
         {% if end %}<strong>- Achevée le</strong> {{end.date}}{% endif %}
      </p>{% endif %}
			<p><strong>Date de livraison souhaitée</strong> {{ poly_request.delivery_date}}</p>
			<p><strong>Lieu de livraison</strong> {{ poly_request.delivery_place }}</p>
		</div>
	</div>
	<div class="span6">
    <div class="well">
      {% include "detail_template.html" with value=poly_request.name name="Titre du document" %}
      {% if filename %}<a id="open" href="download/{{filename}}" class="btn pull-right">Ouvrir le document</a>
      {% else %}
      <p><strong>Document sous forme papier</strong></p>
      {% endif %}
      {% include "detail_template.html" with value=poly_request.nb_pages name="Nombre de pages" %}
      <p><strong>Nombre d'exemplaires souhaités</strong>  {{ poly_request.copies }}</p>
      <p><strong>Nombre total de pages</strong> {{poly_request.total_pages}}</p>
      {% include "detail_template.html" with value=poly_request.base_profile name="Profil d'impression" %}
      {% if poly_request.choices.all %}
      <p><strong>Options d'impression</strong>
      <ul>
      {% for choice in poly_request.choices.all %}
      {% if choice not in poly_request.base_profile.choices.all %}
      <li>{{ choice }}</li>
        {% endif %}
        {% endfor %}
        {% if poly_request.details %}
        <li>Prestations complémentaires: {{poly_request.details}}</li>
        {% endif %}
      </ul>
      </p>
      {% endif %}
    </div>
    {% editablecontent "_request_detail_end_block" %}
    {% endeditablecontent %}
	</div>
</div>
<div class="span11 form-actions well">
	<div class="pull-left">
		<a class="btn" href=".."><i class="icon-backward"></i> Retour</a>
	</div>
	<div class="pull-right">
    {% for workflow in workflows %}
    <a class="btn {% if workflow.warn %} btn-danger{% endif %}{% if workflow.default %} btn-success{% endif %}" href="{% url 'request_action' pk=poly_request.pk workflow_pk=workflow.pk %}">{{ workflow.name }}</a>
    {% endfor %}
</div>
</div>
<style type="text/css">
  #overlay {
  border: 1px solid black;
  display: none;
  position: absolute;
  top: 50px;
  left: 50px;
  background: white;
  }
</style>
<div id="overlay">
	<p><a href="download/{{filename}}">Télécharger</a> <a id="close">Fermer</a></p>
  <p id="pages"></p>
  <canvas id="canvas"></canvas>
</div>
{% addtoblock "endscripts" %}
{% if use_pdf_viewer %}
{% if filename %}
<script type="text/javascript" src="{{STATIC_URL}}pdf.js"></script>
<script type="text/javascript">
function show_document() {
    if (PDFJS == undefined) {
      return true;
    }
    PDFJS.disableWorker = true;
    PDFJS.getDocument("download/{{filename}}").then(function getPdf(pdf) {
        var j = 1;
        var canvas = document.getElementById("canvas");
        function showpage(i) {
          pdf.getPage(i).then(function getPage(page) {
            var scale = 1.5;
            var viewport = page.getViewport(scale);
            var context = canvas.getContext('2d');
            canvas.height = viewport.height;
            canvas.width = viewport.width;
            page.render({canvasContext: context, viewport: viewport});
            $('#overlay').show();
          });
        };
        showpage(j++);
        $('#pages *').remove();
        for (var k = 1; k < pdf.numPages; k++) {
          var a = $('<a href="#"> </a> ');
          a.data('page', k)
          a.append(k.toString());
          a.click(function (ev) {
            showpage($(this).data('page'));
          });
          $('#pages').append(a);
        }
        $(canvas).click(function () {
					showpage(j++);
        });
    });
    return false;
};
$(function () {
		$('#open').click(show_document);
		$('#close').click(function () {
			$('#overlay').hide();
		});
})
</script>
{% endif %}
{% endif %}
{% endaddtoblock %}
{% endblock %}
