{% extends "agenda/base.html" %}

{% block body-class %}{{ block.super }} no-left-column{% endblock %}

{% block appbar %}
<h2>Tous les agendas des intervenants du {{ service_name }} - {{ date|date:"DATE_FORMAT"|title }}</h2>
<a href="..">Retourner à l'agenda</a>
{% endblock %}


{% block agenda-content %}
<div id="activity" class="screen-only">
  <span class="actions screen-only"><button id='print-button-therapeutes-activity' class="icon-print screen-only">Imprimer</button></span>
  <br class="clear" />
  <span class="header"><strong>{{ service_name }}:</strong> {{ date|date:"DATE_FORMAT"|title }}</span>
  <h3>Liste des présences</h4>
<table>
  <thead>
    <tr>
      <th>Nom</th><th>Arrivée</th><th>Premier rendez-vous</th>
      <th>Dernier rendez-vous</th><th>Départ</th><th>Absences</th>
    </tr>
  </thead>
  <tbody>
{% for worker_agenda in workers_agenda %}
<tr>
  <td>{{ worker_agenda.worker.first_name}} <span class="lastname">{{ worker_agenda.worker.last_name }}</span></td>
  <td>{{ worker_agenda.activity.arrival }}</td><td>{{ worker_agenda.activity.first_appointment }}</td>
  <td>{{ worker_agenda.activity.last_appointment }}</td><td>{{ worker_agenda.activity.departure }}</td>
  <td>{% for absence in worker_agenda.activity.absences %}
    {{ absence }}<br />
    {% endfor %}
  </td>
</tr>
{% endfor %}
  </tbody>
</table>
</div>
<br class="clear" />
<span class="actions screen-only">
  <button id="uncheck-all" type="button" class="icon-uncheck screen-only">Tout décocher</button>
  <button id="check-all" type="button" style="display: none" class="icon-check screen-only">Tout cocher</button>
  <button class="print-button-therapeutes icon-print screen-only">Imprimer</button>
</span>
{% for worker_agenda in workers_agenda %}
{% if worker_agenda.appointments %}
<div class="worker-agenda">
    <h2>
        <strong>{{ service_name }}</strong> - Planning de {{ worker_agenda.worker.first_name }} <span class="lastname">{{ worker_agenda.worker.last_name }}</span>
        <input type="checkbox" class="printable" {% if worker_agenda.has_events %}checked{% endif %}>
    </h2>
    <h3>{{ date|date:"DATE_FORMAT"|title }}</h3>

    <!--<span class="remarque">Remarque :</span>-->

    <table>
        <thead>
            <tr> <th>Heure</th> <th>Durée</th> <th>N°</th> <th>Libellé</th><th>Présence</th>
                <th>Absence</th>
                <th>Type d'acte</th> <th>Commentaire</th> <th>Intervenants</th></tr>
        </thead>
        <tbody>
            {% for appointment in worker_agenda.appointments %}
            <tr data-event-id="{{ appointment.event_id }}">
                <td class="col-time">
                  {{ appointment.begin_hour }}
                </td>
                {% if not CURRENT_SERVICE_EVENTS_ONLY and not appointment.holiday and appointment.type != 'info' and appointment.services_names and service not in appointment.services_names %}
                <td colspan=8 class="col-record-id">
                  {% if appointment.event %}Evenement{% else %}Rendez-vous{% endif %}
                  {% with services=appointment.other_services_names|length %}
                  dans le{{ services|pluralize }} service{{ services|pluralize }}
                  {% endwith %}
                  {% for service in appointment.other_services_names %}
                  {{ service|upper }}{% if not forloop.last %}, {% endif %}
                  {% endfor %}
                </td>
                {% else %}
                <td class="col-duration">{% if appointment.length %}{{ appointment.length }}min{% endif %}</td>
                <td class="col-record-id">
                    {% if appointment.patient_record_id %}
                    {% if appointment.patient_record_paper_id %}
                    {{ appointment.patient_record_paper_id }}
                    {% else %}
                    Pas de numéro papier.
                    {% endif %}
                    {% endif %}
                </td>
                <td> {% if appointment.title %}{{ appointment.title }}{% endif %}</td>
                <td/>
                <td> {% if appointment.act_absence %}<strong>{{ appointment.act_absence }}</strong>{% endif %}</td>
                <td> {% if appointment.act_type %}{{ appointment.act_type }}{% endif %}</td>
                <td> {% if appointment.description %}{{ appointment.description }}{% endif %}</td>
                <td>
                    {% if appointment.workers and appointment.workers|length > 10 %}
                    {{ appointment.workers|length }} intervenants
                    {% else %}
                    {% for worker in appointment.workers %}
                    <span class="lastname">{{ worker.last_name }}</span> {{ worker.first_name }}<br/>
                    {% endfor %}
                    {% endif %}
                </td>
                {% endif %}
            </tr>
            {% endfor %}
        </tbody>
    </table>
</div> <!-- .worker-agenda -->

{% endif %}
{% endfor %}
    <script>
        $(function () {
            /* Control page break on last printed page */
            function update_page_break() {
                $('.pagebreak').css('page-break-after', 'always');
                $('.pagebreak').not('.screen-only').last().css('page-break-before', 'avoid');
            }
            update_page_break();

            $('button.print-button-therapeutes').click(function() {
              $('div#activity').addClass('screen-only');
              $.each($(".printable"), function(k, v) {
                if ($(v).is(':checked')) {
                    $(v).parents('.worker-agenda').removeClass('screen-only');
                } else {
                    $(v).parents('.worker-agenda').addClass('screen-only');
                }
                });
              update_page_break();
              window.print();
              });

            $('button#print-button-therapeutes-activity').click(function() {
                $('div#activity').removeClass('screen-only');
                $.each($('.content div:not(#activity)'), function(k, v) {
                  $(v).addClass('screen-only');
                });
              update_page_break();
              window.print();
              });

            $('#uncheck-all').on('click', function () {
                $('.printable').attr('checked', false);
                $('.printable').trigger('change');
                $('#uncheck-all').hide();
                $('#check-all').show();
                update_page_break();
            });
            $('#check-all').on('click', function () {
                $('.printable').attr('checked', true);
                $('.printable').trigger('change');
                $('#check-all').hide();
                $('#uncheck-all').show();
                update_page_break();
            });
        });
    </script>

    <button class="print-button-therapeutes icon-print screen-only">Imprimer</button>
{% endblock %}
