{% extends "agenda_culturel/page.html" %}

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

{% load tag_extra %}
{% load utils_extra %}
{% load cat_extra %}
{% load static %}
{% load cache %}
{% load l10n %}

{% block entete_header %}
    {% css_categories %}
    <script src="/static/admin/js/vendor/jquery/jquery.js"></script>
    <script src="/static/admin/js/jquery.init.js"></script>
    <script src="{% static 'location_field/leaflet/leaflet.js' %}"></script>
    <link href="{% static 'location_field/leaflet/leaflet.css' %}" type="text/css" media="all" rel="stylesheet">
{% endblock %}

{% block fluid %}{% endblock %}

{% block body-class %}organisation{% endblock %}
{% block content %}

<article>
    <header>
        <a href="{% url 'view_organisations' %}" role="button">{% picto_from_name "chevron-left" %} Toutes les organisations</a>    
        {% if perms.agenda_culturel.change_organisation %}
        <div class="slide-buttons">
            <a href="{% url 'edit_organisation' object.pk %}" role="button">Modifier {% picto_from_name "edit-3" %}</a>
            <a href="{% url 'delete_organisation' object.pk %}" role="button">Supprimer {% picto_from_name "trash-2" %}</a>
        </div>
        {% endif %}
        <h1>{{ object.name }}</h1>
        {% if object.website or object.principal_place %}
        <ul>
            {% if object.website %}
            <li><strong>Site internet&nbsp;:</strong> <a href="{{ object.website }}">{{ object.website }}</a></li>
            {% endif %}
            {% if object.principal_place %}
            <li><strong>Lieu principal&nbsp;:</strong> <a href="{{ object.principal_place.get_absolute_url }}">{{ object.principal_place }}</a></li>
            {% endif %}
        </ul>
        {% endif %}
        {% if user.is_authenticated %}
            {% if object.recurrentimport_set.all|length == 1 %}
            <p>Cet organisateur est associé à l'import récurrent <a href="{{ object.recurrentimport_set.all.0.get_absolute_url }}">{{ object.recurrentimport_set.all.0 }}</a>.</p>
            {% endif %}
            {% if object.recurrentimport_set.count > 1 %}
            <p>Cet organisateur est associé aux imports récurrents&nbsp;:</p>
            <ul>
                {% for ir in object.recurrentimport_set.all %}
                <li><a href="{{ ir.get_absolute_url }}">{{ ir }}</a></li>
                {% endfor %}
            </ul>
            {% endif %}
        {% endif %}

        {{ object.description|safe }}
    </header>

    {% with cache_timeout=user.is_authenticated|yesno:"30,600" %}
    {% cache cache_timeout organisation_list user.is_authenticated object page_obj.number past %}
    <div class="slide-buttons">
        {% if past %}
        <a href="{{ object.get_absolute_url }}" role="button">Voir les événements à venir</a>
        {% else %}
        <a href="{% url 'view_organisation_past' object.pk %}" role="button">Voir les événements passés</a>
        {% endif %}
    </div>
    {% if past %}
    <h2>Événements passés</h2>
    {% else %}
    <h2>Événements à venir</h2>
    {% endif %}
    {% if object_list %}

        {% include "agenda_culturel/navigation.html" with page_obj=page_obj %}

        {% for event in object_list %}
            {% include "agenda_culturel/single-event/event-elegant-inc.html" with event=event day=0 no_location=1 %}
        {% endfor %}

        {% include "agenda_culturel/navigation.html" with page_obj=page_obj %}

    {% else %}
        <p><em>Aucun événement</em></p>
    {% endif %}
    {% endcache %}
    {% endwith %}
    <footer>
    </footer>    
</article>

{% endblock %}