{% extends "main.html" %}
{% load karaage_tags %}
{% load render_table from django_tables2 %}


{% block title %}Person{% endblock %}


{% block breadcrumbs %}
<div class="breadcrumbs">
    <a href='{% url "index" %}'>Home</a>&nbsp;›
    <a href="{% url 'kg_person_list' %}">People</a>&nbsp;›
    {{ person }}
</div>
{% endblock %}


{% block content %}
<div id="content-main">

    <div class="module">
        <h2>Person Details</h2>
        <h3>{% if person.title %}{{ person.title }}{% endif %} {{ person }}</h3>
        <div class="table-container">
            <table class="keyvalue">
                <tr>
                    <th>Active:</th>
                    <td>
                        {% if not person.is_active %}
                        <span class="no">Deleted</span>
                        {% elif person.is_locked %}
                        <span class="locked">Locked</span>
                        {% else %}
                        <span class="yes">Yes</span>
                        {% endif %}
                    </td>
                </tr>
                <tr>
                    <th>Admin:</th>
                    <td>
                        {% if not person.is_admin %}
                        <span class="no">No</span>
                        {% else %}
                        <span class="yes">Yes</span>
                        {% endif %}
                    </td>
                </tr>
                {% if person.deleted_by %}
                <tr><th>Deleted:</th><td>Deleted by {{ person.deleted_by }} on {{ person.date_deleted }}</td></tr>
                {% endif %}
                <tr><th>Email:</th><td>{{ person.email|urlize }}</td></tr>
                <tr><th>Position:</th><td>{{ person.position|default:"" }}</td></tr>
                <tr><th>Department:</th><td>{{ person.department|default:"" }}</td></tr>
                <tr><th>Supervisor:</th><td>{{ person.supervisor|default:"" }}</td></tr>
                <tr>
                  <th>Institutes:</th>
                  <td>
                    <a href="{{ person.institute.get_absolute_url }}">{{ person.institute }}</a><br/>
                    {% for institute in person.institutes.all %}
                    <a href="{{ institute.get_absolute_url }}">{{ institute }}</a>
                    {% if not forloop.last %}, {% endif %}
                    {% endfor %}
                  </td>
                </tr>

                <tr>
                  <th>Phone:</th>
                  <td>{{ person.telephone|default:"" }}</td>
                </tr>

                {% if person.mobile %}
                <tr>
                  <th>Mobile:</th><td>{{ person.mobile|default:"" }}</td>
                </tr>
                {% endif %}

                <tr>
                  <th>Groups:</th>
                  <td>
                    {% for group in person.groups.all %}
                    {% if is_admin %}
                    <a href="{{ group.get_absolute_url }}">{{ group }}</a>
                    {% else %}
                    {{ group }}
                    {% endif %}
                    {% if not forloop.last %}, {% endif %}
                    {% endfor %}
                  </td>
                </tr>

                <tr>
                  <th>Projects:</th>
                  <td>
                    {% for project in person.projects.all %}
                    <a href="{{ project.get_absolute_url }}">{{ project }}</a>
                    {% if not forloop.last %}, {% endif %}
                    {% endfor %}
                  </td>
                </tr>

                <tr>
                  <th>Software:</th>
                  <td>
                    {% for software in person.software.all %}
                    <a href="{{ software.get_absolute_url }}">{{ software }}</a>
                    {% if not forloop.last %}, {% endif %}
                    {% endfor %}
                  </td>
                </tr>
                <tr class="hidden-link">
                  <td colspan="2">
                    <a href="#">More....</a>
                  </td>
                </tr>
                <tr><th>Fax:</th><td>{{ person.fax }}</td></tr>
                <tr><th>Address:</th><td>{{ person.address|linebreaksbr|default:"" }}</td></tr>
                <tr><th>Country:</th><td>{{ person.get_country_display|default:"" }}</td></tr>
                {% if is_admin %}
                <tr><th>Comment:</th><td>{{ person.comment|default:"" }}</td></tr>
                <tr><th>Approved by:</th><td>{{ person.approved_by }}</td></tr>
                <tr><th>Date Approved:</th><td>{{ person.date_approved|date }}</td></tr>
                {% if person.deleted_by %}
                <tr><th>Deleted by:</th><td>{{ person.deleted_by }}</td></tr>
                <tr><th>Date Deleted:</th><td>{{ person.date_deleted|date }}</td></tr>
                {% endif %}
                <tr><th>Username:</th><td>{{ person.username }}</td></tr>
                {% if person.saml_id %}
                <tr><th>AAF ID:</th><td>{{ person.saml_id }}</td></tr>
                {% endif %}
                {% endif %}
            </table>
        </div>
        {% if person.is_active or is_admin %}
        <div class="object-tools">
            <ul>

                {% if person.is_active and is_admin %}
                <li><a href="{% url 'kg_account_add' person.username %}" class="addlink">Add account</a></li>
                <li><a href="{% url 'kg_account_add_project' person.username %}" class="addlink">Add project</a></li>
                {% endif %}

                {% for_each_app_include "person_detail_tools.html" %}

                {% if person.is_active %}

                    {% if is_admin %}

                        <li><a href="{% url 'kg_person_logs' person.username %}">Logs</a></li>
                        <li><a href="{% url 'kg_person_verbose' person.username %}">Verbose</a></li>
                        <li><a href="{% url 'kg_person_edit' person.username %}" class="changelink">Edit details</a></li>
                        <li><a href="{%url 'kg_person_delete' person.username %}" class="deletelink">Delete</a></li>
                        {% if person.is_locked %}
                        <li><a href="{% url 'kg_person_unlock' person.username %}" class="unlocklink">Unlock</a></li>
                        {% else %}
                        <li> <a href="{% url 'kg_person_lock' person.username %}" class="locklink">Lock</a></li>
                        <li><a href="{% url 'kg_person_reset' person.username %}">Reset Password</a></li>
                        <li><a href="{% url 'kg_person_password' person.username %}" class="changelink">Change Password</a></li>
                        {% endif %}
                        <li><a href="{% url 'kg_person_bounce' person.username %}">Bounced Email</a></li>

                    {% else %}

                        <li><a href="{% url 'kg_person_reset' person.username %}">Reset Password</a></li>

                    {% endif %}

                {% else %}

                    {% if is_admin %}
                    <li><a href="{% url 'kg_person_logs' person.username %}">Logs</a></li>
                    <li><a href="{% url 'kg_person_verbose' person.username %}">Verbose</a></li>
                    <li><a href="{% url 'kg_person_activate' person.username %}">Activate</a></li>
                    {% endif %}


                {% endif %}
            </ul>
        </div>
        {% endif %}
    </div>

    <div class="module">
        <h2>Leader of Projects</h2>
        {% render_table leader_project_list %}
    </div>

    <div class="module">
        <h2>Delegate of Institutes</h2>
        {% render_table delegate_institute_list %}
    </div>

    {% load machines %}
    {% load render_table from django_tables2 %}
    {% get_account_table person.account_set.all as table %}
    <div class="module">
        <h2>Accounts</h2>
        {% render_table table %}
    </div>

    {% for_each_app_include "person_detail_extra.html" %}

    {% if is_admin %}
    <div class="module">
        <h2>Comments</h2>
        {% comments person %}
        <div class="object-tools">
            <ul>
                <li><a href="{% url 'kg_person_add_comment' person.username %}" class="addlink">Add comment</a></li>
            </ul>
        </div>
    </div>
    {% endif %}
</div>
{% endblock %}
