{% extends "base.html" %}
{% load render_table from django_tables2 %}
{% load static %}

{% block title %}
List patients
{% endblock %}



{% block head %}

<link rel="stylesheet" href="https://cdn.datatables.net/1.10.19/css/jquery.dataTables.min.css">
<script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>

<!-- Load js for initializing tables via their server-side options -->
<script type="text/javascript" charset="utf8" src="{% static 'js/datatableview.js' %}"></script>
<script type="text/javascript">
    $(function(){
        datatableview.initialize($('.datatable'));
    });
</script>
{% endblock %}


{% block content %}


{# { datatable } #}
{% render_table object_list %}

    <h2>List patients</h2>

	{% if is_paginated %}
        <div class="pagination">
            <span class="page-links">
                {% if page_obj.has_previous %}
                    <a href="?page={{ page_obj.previous_page_number }}">previous</a>
                {% endif %}
                <span class="page-current">
                    Page {{ page_obj.number }} of {{ page_obj.paginator.num_pages }}.
                </span>
                {% if page_obj.has_next %}
                    <a href="?page={{ page_obj.next_page_number }}">next</a>
                {% endif %}
            </span>
        </div>
    {% endif %}

    <table>
    <thead>
          <tr>
              <th>Detail</th>
              <th>姓名</th>
              <th>病歷號</th>
              <th>性別</th>
              <th>生日</th>
              <th>地址</th>
              <th>電話</th>
              <th>身份證號</th>
              <th>Memo</th>
              <th>Delete</th>
              <th>Edit</th>
              <th>Print</th>
          </td>
    </thead>
    <tbody>
        {% for patient in object_list %}
        <tr>
            <td><a href='/patient/detail/{{patient.id}}/'><img src="/site_media/img/actions/document-open.png" alt="Detail" border=0 title="{{patient.name}}'s treatments"/></a></td>
            <td>{{ patient.name }}</td>
            <td>{{ patient.medical_records }}</td>
            <td>{{ patient.get_gender_display }}</td>
            <td>{{ patient.birthday }}</td>
            <td>{{ patient.address }}</td>
            <td>{{ patient.phone }}</td>
            <td>{{ patient.id_cards }}</td>
            <td>
              {{ patient.memo }}
              {% if patient.dead %}
              <em>{{patient.dead}}已死亡</em>
              {% endif %}
            </td>
            <td><a href='/patient/delete/{{patient.id}}/'><img src="/site_media/img/actions/edit-delete.png" alt="Delete" border=0 title="Delete {{patient.name}}"/></a></td>
            <td><a href='/patient/update/{{patient.id}}/'><img src="/site_media/img/apps/accessories-text-editor.png" alt="Edit" border=0 title="Edit {{patient.name}}"/></a></td>
            <td><a href='/patient/print/{{patient.id}}/' target='_blank'><img src="/site_media/img/actions/document-print.png" alt="Print" border=0 title="Print summary"/></a></td>
       </tr>
        {% endfor %}
    </tbody>
    </table>

	{% if is_paginated %}
        <div class="pagination">
            <span class="page-links">
                {% if page_obj.has_previous %}
                    <a href="?page={{ page_obj.previous_page_number }}">previous</a>
                {% endif %}
                <span class="page-current">
                    Page {{ page_obj.number }} of {{ page_obj.paginator.num_pages }}.
                </span>
                {% if page_obj.has_next %}
                    <a href="?page={{ page_obj.next_page_number }}">next</a>
                {% endif %}
            </span>
        </div>
    {% endif %}

<div>
    
    <a href=/patient/search/ ><button type="button" class="btn btn-primary">Add/Search patients</button></a>
</div>

{% endblock %}