{% load combo %}

{% if json.data %}
{% with user=json.data %}

<!-- un individu s'affiche : on cache la barre de recherche -->
<script> $(function() { $('div.searchcell.rsu-adult').hide(); }); </script>

<!-- si union : on cache la recherche d'un conjoint -->
{% if user.union %}
<script> $(function() { $('div.rsu-spoose').hide(); }); </script>
{% endif %}

<!-- si individu mineur : on cache la barre latérale (ni conjoint ni enfant) -->
{% if user.statut_legal == "mineur" %}
<!-- script> $(function() { $('aside#sidebar').hide(); }); </script -->
<script> $(function() { $('div.rsu-qf').hide(); }); </script>
<script> $(function() { $('div.rsu-child').hide(); }); </script>
<script> $(function() { $('div.rsu-spoose').hide(); }); </script>
{% endif %}

<!-- pas de droit de gestion du réseau : ni conjoint ni enfant -->
{% if not request.user|has_role:parameters.role_gestion_reseau %}
<script> $(function() { $('div.rsu-child').hide(); }); </script>
<script> $(function() { $('div.rsu-spoose').hide(); }); </script>
{% endif %}


<div class="grid-5-6">
<h2>
  <strong>{{ user.nom_de_naissance }}
  {% if user.nom_d_usage %}({{ user.nom_d_usage }}){% endif %}
  </strong> {{ user.prenoms }}
  <small>— individu {{ user.statut_legal }}</small>
  <small>— RSU #{{ user.id }}</small>
  {% if user.date_de_deces %}— décès le {{ user.date_de_deces|strptime:"%Y-%m-%d"|date:"j F Y" }}{% endif %}
</h2>
</div>
<div class="grid-1-6">
  {% if request.user|has_role:parameters.role_journal %}
  <a class="mini-ts" href="/journal/?rsu_adult={{ rsu_adult }}&cookie=">Journal</a>
  {% endif %}
  <a class="mini-ts" href="./">Autre recherche</a>
</div>


<div class="grid-1-2 bloc-rsu">
  <h3>Identité</h3>
  {% include "rsu/identite.html" with user=user %}

  {% if request.user|has_role:parameters.role_modification %}
  <a class="mini-ts" href="{{ eservices_url }}backoffice/submission/mise-a-jour-d-identite-bo/?session_var_rsu_adult={{ request.GET.rsu_adult }}&cancelurl={{ portal_agent_url }}?rsu_adult={{ request.GET.rsu_adult }}">Modifier</a>
  {% endif %}

  {% if not user.date_de_deces and request.user|has_role:parameters.role_deces %}
  <a class="mini-ts" href="{{ eservices_url }}backoffice/submission/declaration-d-un-deces-bo/?session_var_rsu_adult={{ request.GET.rsu_adult }}&cancelurl={{ portal_agent_url }}?rsu_adult={{ request.GET.rsu_adult }}">Déclarer le décès</a>
  {% endif %}
</div>


<div class="grid-1-2 bloc-rsu">
  <h3>Adresse</h3>
  {% include "rsu/adresses.html" with adresses=user.adresses %}

  {% if user.statut_legal == 'majeur' %}
    {% if request.user|has_role:parameters.role_modification %}
    <a class="mini-ts" href="{{ eservices_url }}backoffice/submission/mise-a-jour-de-l-adresse-bo/?session_var_rsu_adult={{ request.GET.rsu_adult }}&cancelurl={{ portal_agent_url }}?rsu_adult={{ request.GET.rsu_adult }}">Modifier</a>
    {% endif %}
  {% elif user.adresses|length > 1 %}
    {% if request.user|has_role:parameters.role_separation %}
    <a class="mini-ts" href="{{ eservices_url }}backoffice/submission/mise-a-jour-de-la-residence-d-un-enfant-bo/?session_var_rsu_adult={{ request.GET.rsu_adult }}&cancelurl={{ portal_agent_url }}?rsu_adult={{ request.GET.rsu_adult }}">Choisir l'adresse principale</a>
    {% endif %}
  {% endif %}
</div>


<div class="grid-1-2 newline bloc-rsu">
  <h3>Informations de contact</h3>
  {% include "rsu/contacts.html" with email=user.email telephones=user.telephones %}

  {% if request.user|has_role:parameters.role_modification %}
  {% if user.statut_legal == 'majeur' or request.user|has_role:parameters.role_contact_mineur %}
  <a class="mini-ts" href="{{ eservices_url }}backoffice/submission/mise-a-jour-des-informations-de-contact-bo/?session_var_rsu_adult={{ request.GET.rsu_adult }}&cancelurl={{ portal_agent_url }}?rsu_adult={{ request.GET.rsu_adult }}">Modifier</a>
  {% endif %}
  {% endif %}
</div>


<div class="grid-1-2 bloc-rsu">
  <h3>Fédérations</h3>

  <table><tbody>

    {% if request.user|has_role:parameters.role_visualisation_federation_technocarte %}
    <tr>
      <td>Technocarte (Famille) :</td>
      <td class="federation-key" title="{{ user.cles_de_federation.technocarte }}">{{ user.cles_de_federation.technocarte|default:"×" }}</td>
      <td>
        {% if request.user|has_role:parameters.role_gestion_manuelle_federation_technocarte %}
        <a class="mini-ts" href="{{ eservices_url }}backoffice/submission/modification-manuelle-de-federation-technocarte/?session_var_rsu_adult={{ request.GET.rsu_adult }}&cancelurl={{ portal_agent_url }}?rsu_adult={{ request.GET.rsu_adult }}">✎</a>
        {% endif %}
        {% if request.user|has_role:parameters.role_gestion_federation_technocarte %}
          {% if user.cles_de_federation.technocarte %}
            <a class="mini-ts" href="{{ eservices_url }}backoffice/submission/synchronisation-technocarte/?session_var_rsu_adult={{ request.GET.rsu_adult }}&cancelurl={{ portal_agent_url }}?rsu_adult={{ request.GET.rsu_adult }}">⟳</a>
          {% else %}
            <a class="mini-ts" href="{{ eservices_url }}backoffice/submission/gestion-de-federation-technocarte/?session_var_rsu_adult={{ request.GET.rsu_adult }}&cancelurl={{ portal_agent_url }}?rsu_adult={{ request.GET.rsu_adult }}">Créer</a>
          {% endif %}
        {% endif %}
      </td>
    </tr>
    {% endif %}

    {% if request.user|has_role:parameters.role_visualisation_federation_implicit %}
    <tr>
      <td>Implicit (QF) :</td>
      <td class="federation-key" title="{{ user.cles_de_federation.implicit }}">{{ user.cles_de_federation.implicit|default:"×" }}</td>
      <td>
        {% if request.user|has_role:parameters.role_gestion_manuelle_federation_implicit %}
        <a class="mini-ts" href="{{ eservices_url }}backoffice/submission/modification-manuelle-de-federation-implicit/?session_var_rsu_adult={{ request.GET.rsu_adult }}&cancelurl={{ portal_agent_url }}?rsu_adult={{ request.GET.rsu_adult }}">✎</a>
        {% endif %}
        {% if request.user|has_role:parameters.role_gestion_federation_implicit %}
          {% if user.cles_de_federation.implicit %}
            <a class="mini-ts" href="{{ eservices_url }}backoffice/submission/synchronisation-implicit/?session_var_rsu_adult={{ request.GET.rsu_adult }}&cancelurl={{ portal_agent_url }}?rsu_adult={{ request.GET.rsu_adult }}">⟳</a>
          {% else %}
            <a class="mini-ts" href="{{ eservices_url }}backoffice/submission/calcul-de-quotient-familial-bo/?session_var_rsu_adult={{ request.GET.rsu_adult }}&cancelurl={{ portal_agent_url }}?rsu_adult={{ request.GET.rsu_adult }}">Créer</a>
          {% endif %}
        {% endif %}
      </td>
    </tr>
    {% endif %}

    {% if request.user|has_role:parameters.role_visualisation_federation_saga %}
    <tr>
      <td>SAGA (factures) :</td>
      <td class="federation-key" title="{{ user.cles_de_federation.saga }}">{{ user.cles_de_federation.saga|default:"×" }}</td>
      <td>
        {% if request.user|has_role:parameters.role_gestion_manuelle_federation_saga %}
        <a class="mini-ts" href="{{ eservices_url }}backoffice/submission/modification-manuelle-de-federation-saga/?session_var_rsu_adult={{ request.GET.rsu_adult }}&cancelurl={{ portal_agent_url }}?rsu_adult={{ request.GET.rsu_adult }}">✎</a>
        {% endif %}
        {% if request.user|has_role:parameters.role_gestion_federation_saga %}
          {% if user.cles_de_federation.saga %}
            <a class="mini-ts" href="{{ eservices_url }}backoffice/submission/synchronisation-saga/?session_var_rsu_adult={{ request.GET.rsu_adult }}&cancelurl={{ portal_agent_url }}?rsu_adult={{ request.GET.rsu_adult }}">⟳</a>
          {% else %}
            <a class="mini-ts" href="{{ eservices_url }}backoffice/submission/creation-de-federations-saga/?session_var_rsu_adult={{ request.GET.rsu_adult }}&cancelurl={{ portal_agent_url }}?rsu_adult={{ request.GET.rsu_adult }}">Créer</a>
          {% endif %}
        {% endif %}
      </td>
    </tr>
    <tr>
      <td>Tiers SAGA (factures) :</td>
      <td class="federation-key" title="{{ user.cles_de_federation.saga_tiers }}">{{ user.cles_de_federation.saga_tiers|default:"×" }}</td>
      <td>
      </td>
    </tr>
    {% endif %}

    {% if request.user|has_role:parameters.role_visualisation_federation_infor %}
    <tr>
      <td>Infor (Médiathèque) :</td>
      <td class="federation-key" title="{{ user.cles_de_federation.infor }}">{{ user.cles_de_federation.infor|default:"×" }}</td>
      <td>
        {% if request.user|has_role:parameters.role_gestion_manuelle_federation_infor %}
        <a class="mini-ts" href="{{ eservices_url }}backoffice/submission/modification-manuelle-de-federation-infor/?session_var_rsu_adult={{ request.GET.rsu_adult }}&cancelurl={{ portal_agent_url }}?rsu_adult={{ request.GET.rsu_adult }}">✎</a>
        {% endif %}
        {% if request.user|has_role:parameters.role_gestion_federation_infor %}
          {% if user.cles_de_federation.infor %}
            <a class="mini-ts" href="{{ eservices_url }}backoffice/submission/synchronisation-infor/?session_var_rsu_adult={{ request.GET.rsu_adult }}&cancelurl={{ portal_agent_url }}?rsu_adult={{ request.GET.rsu_adult }}">⟳</a>
          {% else %}
            <a class="mini-ts" href="{{ eservices_url }}backoffice/submission/gestion-de-federation-infor/?session_var_rsu_adult={{ request.GET.rsu_adult }}&cancelurl={{ portal_agent_url }}?rsu_adult={{ request.GET.rsu_adult }}">Créer</a>
          {% endif %}
        {% endif %}
      </td>
    </tr>
    {% endif %}

    {% if request.user|has_role:parameters.role_visualisation_federation_authentic %}
    <tr>
      <td>Compte internaute :</td>
      <td class="federation-key" title="{{ user.cles_de_federation.authentic }}">{{ user.cles_de_federation.authentic|default:"×" }}</td>
      <td>
        {% if request.user|has_role:parameters.role_gestion_manuelle_federation_authentic %}
        <a class="mini-ts" href="{{ eservices_url }}backoffice/submission/creer-un-compte-en-ligne-pour-l-usager-bo/?session_var_rsu_adult={{ request.GET.rsu_adult }}&cancelurl={{ portal_agent_url }}?rsu_adult={{ request.GET.rsu_adult }}">Créer/modifier/supprimer</a>
        {% elif not user.cles_de_federation.authentic and request.user|has_role:parameters.role_gestion_federation_authentic %}
        <a class="mini-ts" href="{{ eservices_url }}backoffice/submission/creer-un-compte-en-ligne-pour-l-usager-bo/?session_var_rsu_adult={{ request.GET.rsu_adult }}&cancelurl={{ portal_agent_url }}?rsu_adult={{ request.GET.rsu_adult }}">Lier à un compte internaute</a>
        {% endif %}
      </td>
    </tr>
    {% endif %}

  </tbody></table>

</div>


{% if user.union %}
<div class="grid-1-1 newline"><hr /></div>

<div class="grid-1-1 newline">
  <h3>Conjoint — {% include "rsu/union_statut.html" with union_statut=user.union_statut %}</h3>
  <div class="grid-1-2 newline bloc-rsu">
    {% include "rsu/identite-mini.html" with user=user.union %}

    {% if request.user|has_role:parameters.role_separation %}
    <a class="mini-ts" href="{{ eservices_url }}backoffice/submission/declaration-d-une-separation-bo/?session_var_rsu_adult={{ request.GET.rsu_adult }}&cancelurl={{ portal_agent_url }}?rsu_adult={{ request.GET.rsu_adult }}">Déclarer la séparation</a>
    {% endif %}

    {% if request.user|has_role:parameters.role_gestion_reseau %}
    {% if user.union_statut == "unionlibre" %}
    <a class="mini-ts" href="{{ eservices_url }}backoffice/submission/relation-maritale-simple-passage-d-union-libre-a-mariage-bo/?session_var_rsu_adult={{ request.GET.rsu_adult }}&cancelurl={{ portal_agent_url }}?rsu_adult={{ request.GET.rsu_adult }}">Passer d’union libre à PACS/mariage</a>
    {% endif %}
    {% endif %}

    {% if request.user|has_role:parameters.role_erreur_statut_marital %}
    <a class="mini-ts" href="{{ eservices_url }}backoffice/submission/correction-d-une-relation-maritale-bo/?session_var_rsu_adult={{ request.GET.rsu_adult }}&cancelurl={{ portal_agent_url }}?rsu_adult={{ request.GET.rsu_adult }}">Erreur sur le type de relation</a>
    {% endif %}
  </div>
</div>
{% endif %}

<div class="grid-1-1 newline"><hr /></div>

{% if user.enfants or not user.parents %}
<div class="grid-1-1 newline">
  <h3>Enfants ({{ user.enfants|length }})</h3>
  {% for user in user.enfants|dictsort:"date_de_naissance" %}
  <div class="grid-1-2 bloc-rsu">
    {% include "rsu/identite-mini.html" with user=user %}
    {% if request.user|has_role:parameters.role_gestion_reseau %}
    <a class="mini-ts" href="{{ eservices_url }}backoffice/submission/suppression-du-lien-de-responsabilite-bo/?session_var_rsu_adult={{ request.GET.rsu_adult }}&session_var_rsu_child={{ user.id }}&cancelurl={{ portal_agent_url }}?rsu_adult={{ request.GET.rsu_adult }}">Suppression de la responsabilité</a>
    {% endif %}
  </div>
  {% empty %}
  <p>Pas d’enfants</p>
  {% endfor %}
</div>
{% endif %}{# not user.parents #}

{% if user.parents or not user.enfants %}
<div class="grid-1-1 newline">
  <h3>Parents ({{ user.parents|length }})</h3>
  {% for user in user.parents|dictsort:"date_de_naissance" %}
  <div class="grid-1-2">
    {% include "rsu/identite-mini.html" with user=user %}
  </div>
  {% empty %}
  <p>Pas de parents</p>
  {% endfor %}
</div>
{% endif %}{# not user.enfants #}

{% if request.user|has_role:parameters.role_suppression_fiche %}
<div class="grid-1-1 newline"><hr /></div>
<div class="grid-1-1 newline">
  <h3>Suppression de cette fiche #{{ user.id }}</h3>
  {% if user.parents or user.enfants or user.union or user.cles_de_federation.technocarte or user.cles_de_federation.implicit or user.cles_de_federation.infor or user.cles_de_federation.authentic %}
    <p>
    Vous avez le droit de supprimer des fiches, mais celle-ci ne peut être supprimée :
    <ul>
    {% if user.parents %}<li>cette fiche est liée à au moins un parent</li>{% endif %}
    {% if user.enfants %}<li>cette fiche est liée à au moins un enfant</li>{% endif %}
    {% if user.union %}<li>cette fiche est liée à un conjoint</li>{% endif %}
    {% if user.cles_de_federation %}<li>cette fiche est fédérée avec au moins un système</li>{% endif %}
    </ul>
    </p>
  {% else %}
    <a class="mini-ts" style="background: red; color: black;" href="{{ eservices_url }}backoffice/submission/suppression-fiche-rsu/?session_var_rsu_adult={{ request.GET.rsu_adult }}&cancelurl={{ portal_agent_url }}?rsu_adult={{ request.GET.rsu_adult }}">Supprimer cette fiche</a>
  {% endif %}
</div>
{% endif %}


{% endwith %}

{% else %}{# not json.data #}

<!-- pas d'individy affiché : on cache la barre latérale (recherche conjoint ou enfant) -->
<script> $(function() { $('aside#sidebar').hide(); }); </script>

{% endif %}
