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

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

{% block content %}
    {% if not request.is_ajax %}
        <div class="row">
            <div class="col-sm-8">
                <h3>{{ object.name }}<br/>
                    <span class="small">Last edited {{ object.last_edited_at }} by {{ object.last_edited_by.name }}</span>
                </h3>
            </div>
            <div class="pull-right">
                <a href="{% url 'organisation_update' object.pk %}" class="btn btn-primary">Edit <span
                        class="glyphicon glyphicon-pencil"></span></a>
            </div>
            <div class="col-sm-4">
            </div>
        </div>
    {% endif %}
    <div class="row">
        <div class="col-sm-6">
            <h4>Details</h4>
            <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 }}">{{ object.email }}</a></dd>

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

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

                <dt>Union Account</dt>
                <dd>{{ object.union_account|yesno|capfirst }}</dd>
            </dl>
        </div>

        <div class="col-sm-6">
            <h4>People</h4>
            <ul class="list-unstyled">
                {% for person in object.persons %}
                    <li><a href="{% url 'person_detail' person.pk %}">{{ person.name }}</a></li>
                {% endfor %}
            </ul>
        </div>
    </div>

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

{% if request.is_ajax %}
    {% block footer %}
        <div class="row">
            <div class="col-sm-10 align-left">
                Lasted edited at {{ object.last_edited_at|date:"SHORT_DATE_FORMAT" }}
                by {{ object.last_edited_by.name }}
            </div>
            <div class="col-sm-2">
                <div class="pull-right">
                    <a href="{% url 'organisation_update' object.pk %}" class="btn btn-primary">Edit <span
                            class="glyphicon glyphicon-pencil"></span></a>
                </div>
            </div>
        </div>
    {% endblock %}
{% endif %}