<script type="text/javascript">
    warning_on_unsave_change();
    init_magic_dialog();
    $('#prescription-transport-btn').click(function() {
        $('#ajax-dlg').load('prescription-transport',
          function () {
             $(this).dialog({title: 'Prescription de transport', width: '800px',
                      buttons: [ { text: "Fermer",
                          click: function() { $(this).dialog("close"); } },
                      { text: "Prescrire",
                          click: function() { $("#ajax-dlg form").submit(); $(this).dialog("close"); } }]});
             $('.addresses input[type=radio]').first().click();
         });
         return false;
    });
    $('#new-protection-btn').click(function() {
        generic_ajaxform_dialog('protection/new', 'Ajouter une mesure de protection',
            '#ajax-dlg', '800px', 'Ajouter', null, add_datepickers);
    });
    $('.update-protection-btn').click(function() {
        generic_ajaxform_dialog('protection/' + $(this).data('id') + '/update', 'Modifier une mesure de protection',
            '#ajax-dlg', '800px', 'Modifier', null, add_datepickers);
    });
    $('.del-protection').click(function() {
        generic_ajaxform_dialog('protection/' + $(this).data('id') + '/del', 'Supprimer une mesure de protection',
            '#ajax-dlg', '500px', 'Supprimer');
    });
    $('input#id_id-birthdate').datepicker({dateFormat: 'd/m/yy', showOn: 'button' });
    calebasse_ajax_form('#tabs-2');
</script>
{% extends 'dossiers/patientrecord_tab.html' %}
{% load dossiers %}
{% block content %}
<div id="tabs-2">
  <form method="post" action="tab2" id="administrative-form" class="patientrecordform">{% csrf_token %}
    <p><button class="save enable-on-change">Enregistrer</button></p>
    <div class="frame inline">
      <h3>État civil</h3>
      <table class="basic">
        <tbody>
        {% get_fieldset last_name,first_name,birthplace,birthdate,gender,nationality as id_fields from form %}
        {% for field in id_fields %}
        <tr>
          <td class="width-limited">{{ field.label_tag }}</td>
          <td>{{ field }}</td>
          <td>{{ field.errors }}</td>
        </tr>
        {% endfor %}
        </tbody>
      </table>
      <input type="hidden"  name="tab"  value="1">
    </div>

    <div class="frame inline">
      <h3>Inscription</h3>
      <table class="basic">
        <tbody>
        {% get_fieldset analysemotive,familymotive,provenance,advicegiver,provenanceplace as inscription_fields from form %}
        {% for field in inscription_fields %}
        <tr><td class="width-limited">{{ field.label_tag }}</td><td>{{ field }}
            <button type="button"
              class="dialog-button"
              data-url="../../ressources/{{ field.name }}/new/ #form-content"
              data-default-button="Ajouter"
              data-next-url="{{ request.get_full_path }}#tab=1"
              data-add-select="#id_inscription-{{ field.name }}"
              title="Ajouter un {{ field.label.lower }}"
              type="button">+</button></td><td>{{ field.errors }}</td></tr>
        {% endfor %}
        </tbody>
      </table>
      <input type="hidden"  name="tab"  value="1">
    </div>

    <div class="frame inline">
      <h3>Sortie</h3>
      <table class="basic">
        <tbody>
        {% get_fieldset outmotive,outto as out_fields from form %}
        {% for field in out_fields %}
        <tr><td class="width-limited">{{ field.label_tag  }}</td><td>{{ field }}
            <button type="button"
              class="dialog-button"
              data-url="../../ressources/{{ field.name }}/new/ #form-content"
              data-default-button="Ajouter"
              data-next-url="{{ request.get_full_path }}#tab=1"
              data-add-select="#id_out-{{ field.name }}"
              title="Ajouter un {{ field.label.lower }}"
              type="button">+</button></td><td>{{ field.errors }}</td></tr>
        {% endfor %}
        </tbody>
      </table>
      <input type="hidden"  name="tab"  value="1">
    </div>

    <div class="frame inline">
      <h3>Famille</h3>
      <table class="basic">
        <tbody>
        <tr><td class="width-limited">{{ form.sibship_place.label_tag  }}</td><td>{{ form.sibship_place }}</td><td>{{ form.sibship_place.errors }}</td></tr>
        <tr><td class="width-limited">{{ form.nb_children_family.label_tag  }}</td><td>{{ form.nb_children_family }}</td><td>{{ form.nb_children_family.errors }}</td></tr>
        <tr><td class="width-limited"><label>Rang (gémellité) :  </label></td><td>{{ object.twinning_rank|default_if_none:"Aucun" }}</td><td></td></tr>
        {% get_fieldset parental_authority,family_situation,child_custody,job_mother,job_father,rm_mother,rm_father as familly_fields from form %}
        {% for field in familly_fields %}
        <tr>
          <td class="width-limited">{{ field.label_tag }}</td><td>{{ field }}
            <button type="button"
              class="dialog-button"
              data-url="../../ressources/parentalauthoritytype/new/ #form-content"
              data-default-button="Ajouter"
              data-next-url="{{ request.get_full_path }}#tab=1"
              data-add-select="#id_family-parental_authority"
              title="Ajouter {{ field.label.lower }}">+</button></td><td>{{ field.errors }}</td>
        </tr>
        {% endfor %}
        <tr><td class="width-limited">{{ form.family_comment.label_tag  }}</td><td>{{ form.family_comment }}</td><td>{{ form.family_comment.errors }}</td></tr>
        </tbody>
      </table>
      <input type="hidden"  name="tab"  value="1">
    </div>

    <div class="frame inline">
      <h3>Transport</h3>
      <table class="basic">
        <tbody>
        {% get_fieldset transporttype,transportcompany,simple_appointment_transport,periodic_appointment_transport as transport_fields from form %}
        {% for field in transport_fields %}
        <tr><td class="width-limited">{{ field.label_tag }}</td><td>{{ field }}
            <button type="button"
              class="dialog-button"
              data-url="../../ressources/{{ field.name }}/new/ #form-content"
              data-default-button="Ajouter"
              data-next-url="{{ request.get_full_path }}#tab=1"
              data-add-select="#id_transport-{{ field.name }}"
              title="Ajouter {% if field.label.lower == "type de transport" %}un{% else %}une{% endif %} {{ field.label.lower }}">+</button></td><td>{{ field.errors }}</td></tr>
        {% endfor %}
        </tbody>
      </table>
      <br/>
      <table>
        <tr>
          <td><!--<button id="attestation-transport-btn">Attestation de transport</button>--></td><td><button id="prescription-transport-btn">Prescription de transport</button></td>
        </tr>
        <tr>
          <td></td>
          <td>{% if last_prescription %} Dernière prescription le {{ last_prescription.created }}{% endif %}</td>
        </tr>
      </table>
    </div>

    <div class="frame inline">
      <h3>Suivi du patient</h3>
      <table class="basic">
        <tbody>
        <tr><td class="width-limited">{{ form.coordinators.label_tag  }}</td><td>{{ form.coordinators }}</td><td>{{ form.coordinators.errors }}</td></tr>
        <tr><td class="width-limited">{{ form.externaldoctor.label_tag  }}</td><td>{{ form.externaldoctor }}
            <button type="button"
              class="dialog-button"
              data-url="../../personnes/externaltherapist/new/ #form-content"
              data-default-button="Ajouter"
              data-next-url="{{ request.get_full_path }}#tab=1"
              data-add-select="#id_followup-externaldoctor"
              title="Ajouter un médecin extérieur">+</button></td><td>{{ form.externaldoctor.errors }}</td></tr>
        <tr><td class="width-limited">{{ form.externalintervener.label_tag  }}</td><td>{{ form.externalintervener }}
            <button type="button"
              class="dialog-button"
              data-url="../../personnes/externalworker/new/ #form-content"
              data-default-button="Ajouter"
              data-next-url="{{ request.get_full_path }}#tab=1"
              data-add-select="#id_followup-externalintervener"
              title="Ajouter un intervenant extérieur">+</button></td><td>{{ form.externalintervener.errors }}</td></tr>
        </tbody>
      </table>
    </div>
    <input type="hidden"  name="tab"  value="1">
    <p><button class="save enable-on-change">Enregistrer</button></p>
  </form>

  <div class="frame">
    <h3>Mesures de protection</h3>
    <p><button id="new-protection-btn">Nouvelle mesure de protection</button></p>
    {% for protection in object.protectionstate_set.all %}
    <div class="subframe">
      Depuis le {{ protection.start_date }} : {{ protection.status.name }}
      <div class="buttons">
        <button type="button" data-id="{{ protection.id }}" class="del-protection icon-minus" title="Supprimer"></button>
        <button type="button" data-id="{{ protection.id }}" class="update-protection-btn icon-edit" title="Modifier"></button>
      </div>
      <div>
        <ul>
          {% if protection.end_date %}<li><label>Date de fin</label> : {{ protection.end_date }}</li>{% endif %}
          {% if protection.comment %}<li><label>Commentaire</label> : {{ protection.comment }}</li>{% endif %}
        </ul>
      </div>
    </div>
    {% endfor %}
  </div>
</div>
{% endblock %}
