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


{% block title %}Account{% endblock %}


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


{% block content %}
<div id="content-main">
    <div class="module">
        <h2>Account Details</h2>
        <h3>{{ account }}</h3>
        <div class="table-container">
            <table class="keyvalue">
                <tr>
                    <th>Active:</th>
                    <td>
                        {% if account.date_deleted %}
                        <span class="no">Deleted</span>
                        {% elif account.is_locked %}
                        <span class="locked">Locked</span>
                        {% else %}
                        <span class="yes">Yes</span>
                        {% endif %}
                    </td>
                </tr>
                <tr>
                    <th>Username:</th>
                    <td>{{ account.username }}</td>
                </tr>
                <tr>
                    <th>Date Created:</th>
                    <td>{{ account.date_created|date }}</td>
                </tr>
                <tr>
                    <th>Date Deleted:</th>
                    <td>{{ account.date_deleted|date }}</td>
                </tr>
                <tr>
                    <th>Shell:</th>
                    <td>{{ account.shell }}</td>
                </tr>
            </table>
        </div>

        <div class="object-tools">
            <ul>
                {% if can_edit %}
                    <li><a href="{% url 'kg_account_edit' account.pk %}" class="changelink">Edit Account</a></li>
                {% endif %}
                {% if not account.date_deleted and is_admin %}
                    <li><a href="{% url 'kg_account_delete' account.id %}" class="deletelink">Delete Account</a></li>
                {% endif %}
                {% for_each_app_include "account_detail_tools.html" %}
            </ul>
        </div>

    </div>

    {% if account.project_list and not account.date_deleted %}
    <div class="module">
        <h2>Projects</h2>
        <table>
            <thead>
                <tr>
                    <th>Project</th>
                    <th>Name</th>
                    <th>Institute</th>
                    <th>Leaders</th>
                    <th>Default</th>
                    {% if is_admin %}
                    <th></th>
                    {% endif %}
                </tr>
            </thead>
            <tbody>
            {% for p in account.project_list %}
            <tr>
                <td><a href="{{ p.get_absolute_url }}">{{ p.pid }}</a></td>
                <td>{{ p.name|truncatewords:"10" }}</td>
                <td><a href="{{ p.institute.get_absolute_url }}">{{ p.institute }}</a></td>
                <td>{% for leader in p.leaders.all %}<a href="{{ leader.get_absolute_url }}">{{ leader }}, </a>{% endfor %}</td>
                <td>
                    {% ifequal p account.default_project %}
                        <span class="yes">Yes</span>
                    {% else %}
                        {% if can_edit %}
                        <form action="{% url 'kg_account_set_default' account.id p.pid %}" method="post">
                            {% csrf_token %}
                            <input type="submit" value="Make Default"/>
                        </form>
                        {% else %}
                        <span class="no">No</span>
                        {% endif %}
                    {% endifequal %}
                </td>
                {% if is_admin %}
                <td>
                    {% ifnotequal p account.default_project %}
                    <a href="{% url 'kg_remove_project_member' p.id account.person.username %}" class="deletelink">Remove</a>
                    {% endifnotequal %}
                </td>
                {% endif %}
            </tr>
            {% endfor %}
            </tbody>
        </table>
    </div>
    {% endif %}

    {% for_each_app_include "account_detail_extra.html" %}

</div>
{% endblock %}
