<script type="text/javascript">
    warning_on_unsave_change();
</script>
{% extends 'dossiers/patientrecord_tab.html' %}
{% load dossiers %}
{% block content %}
<div id="tabs-3">
  <form method="post" action="tab3" id="policyholder-form" class="patientrecordform">{% csrf_token %}
    <p>
    {% if nb_place_of_lifes == 1 %}
    <span>Un lieu de vie unique est indiqué</span>
    {% elif nb_place_of_lifes > 1 %}
    <span class="highlight">Il y a {{ nb_place_of_lifes }} lieux de vie d'indiqués</span>
    {% else %}
    <span class="highlight">Aucun lieu de vie n'est indiqué.</span>
    {% endif %}
    </p>
    <p>
    <label>Commentaire <button class="save enable-on-change btn-maj">✔</button></label>
    {{ forms.policyholder.contact_comment }}
    </p>
    <p>
    <button type="button" id="new-address-btn" class="icon-home-space">Nouvelle adresse</button>
    <button type="button" id="new-contact-btn" class="icon-user-space">Nouveau contact</button>
    </p>

    <div class="contact patient">
      <h4 class="icon-user-space">Patient</h4>
      <div class="right">Assuré
        <input type="radio"
        {% if object.policyholder.id == object.id %} checked="checked" {% endif %}
        id="id_policyholder-policyholder_{{ object.id }}"
        value="{{ object.id }}"
        class="autosubmit"
        name="policyholder-policyholder">
        <button type="button" data-id="{{ object.id }}" class="update-contact-btn icon-edit" title="Modifier"></button>
      </div>
      <div>
        {% include "dossiers/patientrecord_tab3_contact.html" with contact=object %}
      </div>
    </div>

    {% for contact in object.contacts.all %}
    {% if not contact.addresses.all %}
    <div class="contact">
      <h4>{% if contact.gender == 1 %}M.{% elif contact.gender == 2 %}Mme{% endif %}
        {{ contact.first_name }} <span class="lastname">{{ contact.last_name }}</span> {% if contact.id == object.id %} (PATIENT){% endif %}</h4>
      <div class="right">Assuré
        <input type="radio"
        {% if object.policyholder.id == contact.id %} checked="checked" {% endif %}
        id="id_policyholder-policyholder_{{ contact.id }}"
        value="{{ contact.id }}"
        class="autosubmit"
        name="policyholder-policyholder">
        <button type="button" data-id="{{ contact.id }}" data-address-id="{{ address.id }}" class="del-contact icon-minus" title="Supprimer"></button>
        <button type="button" data-id="{{ contact.id }}" class="update-contact-btn icon-edit" title="Modifier"></button>
      </div>
      <div>
        {% include "dossiers/patientrecord_tab3_contact.html" %}
      </div>
    </div>
    {% endif %}
    {% endfor %}
    {% for address in addresses %}
    <div class="frame {% if address.place_of_life %}orange{% endif %}">
      <h3 class="icon-home-space">{{ address }}</h3>
      <div class="buttons">
        <button type="button" data-id="{{ address.id }}" class="del-address icon-minus" title="Supprimer"></button>
        <button type="button" data-id="{{ address.id }}" class="update-address-btn icon-edit" title="Modifier"></button>
      </div>
      <div class="right">
        <ul class="ajax_messages" style="display: none;"></ul>
        <input type="checkbox" data-id="{{ address.id }}" class="place_of_life" {% if address.place_of_life %}checked{% endif %}>Lieu de vie</input>
      </div>
      {% if address.phone %}<p><span class="icon-phone">{{ address.phone|phone }}</span></p>{% endif %}
      {% if address.comment %}<p><label>Commentaire :</label>{{ address.comment }}</p>{% endif %}
      {% if not address.phone and not address.comment %}<p>&nbsp;<!-- intentionaly empty --></p>{% endif %}
      {% for contact in address.patientcontact_set.all  %}
      {% if contact.id != object.id %}
      <div class="contact">
        <h4 class="icon-user-space">{% if contact.gender == 1 %}M.{% elif contact.gender == 2 %}Mme{% endif %}
          {{ contact.first_name }} <span class="lastname">{{ contact.last_name }}</span> {% if contact.id == object.id %} (PATIENT){% endif %}</h4>
        <div class="right">Assuré
          <input type="radio"
          {% if object.policyholder.id == contact.id %} checked="checked" {% endif %}
          id="id_policyholder-policyholder_{{ contact.id }}"
          value="{{ contact.id }}"
          class="autosubmit"
          name="policyholder-policyholder">
          <button type="button" data-id="{{ contact.id }}" data-address-id="{{ address.id }}" class="del-contact icon-minus" title="Supprimer"></button>
          <button type="button" data-id="{{ contact.id }}" class="update-contact-btn icon-edit" title="Modifier"></button>
        </div>
        <div>
          {% include "dossiers/patientrecord_tab3_contact.html" %}
        </div>
      </ul>
    </span>
  </div>
  {% endif %}
  {% endfor %}
</div>
{% endfor %}
  </form>
</div>
{% endblock %}
