{% extends "timepiece/person/base.html" %}
{% load url from future %}
{% load timepiece_tags markup bootstrap_toolkit %}

{% block title %}{{ person.first_name }} {{ person.last_name }}{% endblock %}

{% block crumbs %}
    {{ block.super }}
    <li><span class="divider">/</span> <a href="{% url 'view_person' person.pk %}">Person Detail</a></li>
{% endblock crumbs %}

{% block content %}
    <div class="row-fluid">
        <div class="span12">
            <h2>{{ person.first_name }} {{ person.last_name }}</h2>
            <ul class="nav nav-pills">
                {% if perms.auth.change_person %}
                    <li><a href="{% url 'edit_person' person.pk %}">Edit Person</a></li>
                    <li><a href="{% url 'delete_person' person.pk %}">Delete Person</a></li>
                {% endif %}
                {% if perms.auth.view_entry_summary %}
                    <li><a href="{% url 'view_person_time_sheet' person.pk %}">View Time Sheet</a></li>
                {% endif %}
            </ul>
        </div>
    </div>

    <div class="row-fluid">
        <div class="span6">
            <table class="table table-bordered table-striped">
                <tr><th>Username</th><td>{{ person.username }}</td></tr>
                <tr><th>First Name</th><td>{{ person.first_name }}</td></tr>
                <tr><th>Last Name</th><td>{{ person.last_name }}</td></tr>
                <tr><th>Email</th><td>{{ person.email }}</td></tr>
            </table>
        </div>

        <div class="span4 offset1">
            <h3>Projects</h3>
            <ul class="projects">
                {% ifnotequal person.project_relationships.count 0 %}
                {% for relationship in person.project_relationships.select_related %}
                    <li>
                        {{ relationship.project.name }}
                        {% if perms.timepiece.change_projectrelationship %}
                            {% with caption="Edit "|add:person.get_full_name|add:"'s relationship to "|add:relationship.project.name project=relationship.project %}
                                <a title="{{ caption }}" href="{% url 'edit_project_relationship' project_id=project.id user_id=person.id %}?next={% url 'view_person' person_id=person.id %}"><i alt="{{ caption }}" class="icon-pencil"></i></a>
                            {% endwith %}
                        {% endif %}
                        {% if perms.timepiece.delete_projectrelationship %}
                            {% with caption="Remove "|add:person.get_full_name|add:" from "|add:relationship.project.name project=relationship.project %}
                                <a title="{{ caption }}" href="{% url 'remove_project_relationship' project_id=project.id user_id=person.id %}?next={% url 'view_person' person_id=person.id %}"><i alt="{{ caption }}" class="icon-remove"></i></a>
                            {% endwith %}
                        {% endif %}
                    </li>
                {% endfor %}
                {% endifnotequal %}
            </ul>
            {% if perms.timepiece.add_projectrelationship %}
                <form class="form-inline" action="{% url 'add_project_to_user' user_id=person.id %}?next={% url 'view_person' person_id=person.id %}" method="post" accept-charset="utf-8">
                    {% csrf_token %}
                    {{ add_project_form|as_bootstrap:"inline" }}
                    <input class="btn" type="submit" name="submit" id="submit" value="Add" />
                </form>
            {% endif %}
        </div>
    </div>
{% endblock %}
