{% extends request.is_ajax|yesno:"base_ajax.html,base_rigs.html" %}
{% load widget_tweaks %}

{% block title %}Person | {{ object.name }}{% endblock %}

{% block content %}
    <div class="row">
        {% if not request.is_ajax %}
            <div class="col-sm-12">
                <h1>Person | {{ object.name }}</h1>
            </div>

            <div class="col-sm-12 text-right">
                <div class="btn-group btn-page">
                    <a href="{% url 'person_update' object.pk %}" class="btn btn-default"><span
                        class="glyphicon glyphicon-pencil"></span> Edit</a>
                </div>
            </div>
        {% endif %}
        <div class="col-sm-6">
            <div class="panel panel-info">
                <div class="panel-heading">Person Details</div>
                <div class="panel-body">
                    <dl class="dl-horizontal">
                        <dt>Name</dt>
                        <dd>{{ object.name }}</dd>

                        <dt>Phone</dt>
                        <dd><a href="tel:{{ object.phone }}">{{ object.phone }}</a></dd>

                        <dt>Email</dt>
                        <dd><a href="mailto:{{ object.email }}"><span class="overflow-ellipsis">{{ object.email }}</span></a></dd>

                        <dt>Address</dt>
                        <dd>{{ object.address|linebreaksbr }}</dd>

                        <dt>Notes</dt>
                        <dd>{{ object.notes|linebreaksbr }}</dd>
                    </dl>                        
                </div>
            </div>
        </div>

        <div class="col-sm-6">
            <div class="panel panel-default">
                <div class="panel-heading">Associated Organisations</div>
                <div class="panel-body">
                    <div class="list-group">
                        {% for organisation,count in object.organisations %}
                            <a class="list-group-item" href="{% url 'organisation_detail' organisation.pk %}">{{ organisation.pk|stringformat:"05d" }} | {{ organisation.name }} <span class="badge" title="{{count}} events with {{object.name}} for {{organisation.name}}">{{count}}</span></a>
                        {% endfor %}
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div class="row">
        <div class="col-sm-12">
            <div class="panel panel-default">
                <div class="panel-heading">Associated Events</div>
                <div class="panel-body">
                    {% with object.latest_events as events %}
                        {% include 'RIGS/event_table.html' %}
                    {% endwith %}
                </div>
            </div>
        </div>
    </div>


    {% if not request.is_ajax %}
        <div class="row">
            <div class="col-sm-12 text-right">
                <div class="btn-group btn-page">
                    <a href="{% url 'person_update' object.pk %}" class="btn btn-default"><span
                        class="glyphicon glyphicon-pencil"></span> Edit</a>
                </div>
                <div>
                    <a href="{% url 'person_history' object.pk %}" title="View Revision History">
                        Last edited {{ object.last_edited_at }} by {{ object.last_edited_by.name }}
                    </a>
                </div>
            </div>
        </div>
    {% endif %}

{% endblock %}

{% if request.is_ajax %}
    {% block footer %}
        <div class="row">
            <div class="col-sm-12 text-right">
                <div class="btn-group btn-page">
                    <a href="{% url 'person_detail' object.pk %}" class="btn btn-default"><span
                        class="glyphicon glyphicon-eye-open"></span> Open Page</a>
                    <a href="{% url 'person_update' object.pk %}" class="btn btn-default"><span
                        class="glyphicon glyphicon-pencil"></span> Edit</a>
                </div>
                <div>
                    <a href="{% url 'person_history' object.pk %}" title="View Revision History">
                        Last edited {{ object.last_edited_at }} by {{ object.last_edited_by.name }}
                    </a>
                </div>
            </div>
        </div>
    {% endblock %}
{% endif %}