{% extends "agenda_culturel/page-admin.html" %}
{% load static %}
{% load utils_extra %}
{% load cat_extra %}
{% load event_extra %}
{% load tag_extra %}


{% block title %}{% block og_title %}Appliquer les catégorisations{% endblock %}{% endblock %}

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

{% block content %}

<h1>Appliquer les catégorisations</h1>
<p>Les règles de catégorisation proposent de modifier comme suit les événements suivants. Sélectionnez les modifications qui vous conviennent.</p>

<form method="post">{% csrf_token %}
{% for field in form %}
    {% if not field.is_hidden %}
    <article>
        {{ field.errors }}
        
        {% with eid=field.auto_id|remove_id_prefix %}
            {% with event=events|get_item:eid %}
                {% with altcat=categories|get_item:eid %}

                    <header>
                        {{ field }} Changer {{ event.category|small_cat }} en {{ altcat|small_cat }} pour l'événement 
                        <a href="#event-{{ event.id }}" 
                            aria-label="Fermer" 
                            class="close" 
                            data-target="event-{{ event.id }}"
                            onClick="toggleModal(event)"></a>
                            <h3>{{ event|picto_status }} {{ event.title }}</h3>
                        
                            <p>
                                {% picto_from_name "map-pin" %}
                                {{ event.location }}
                            </p>
                            <p>
                                {% picto_from_name "calendar" %}
                                {% if event.end_day and event.end_day != event.start_day %}du{% else %}le{% endif %}
                                {{ event.start_day|date|frdate }} 
                                {% if event.start_time %} {% if not event.end_day or event.end_day == event.start_day %}{% if event.end_time %}de{% else %}à{% endif %}{% endif %}
                                    {{ event.start_time }}
                                {% endif %}
                                {% if event.end_day and event.end_day != event.start_day %}
                                    au {% if event.end_day and event.end_day != event.start_day %}{{ event.end_day|date|frdate }}{% endif %}
                                {% endif %}
                                {% if event.end_time %} {% if not event.end_day|date|frdate or event.end_day == event.start_day %}jusqu'à{% endif %} {{ event.end_time }}{% endif %}                            </p>
                    </header>
                
                    <div class="body-fixed">{{ event.description |linebreaks }}</div>
                
                
                    <p>
                        {% for tag in event.sorted_tags %}
                        {{ tag | tag_button }}
                        {% endfor %}
                    </p>
                
                {% endwith %}
            {% endwith %}
        {% endwith %}
        
    </article>
    {% else %}
        {{ field }}
    {% endif %}
{% endfor %}
<div class="grid buttons">
    <a href="{% if request.META.HTTP_REFERER %}{{ request.META.HTTP_REFERER }}{% else %}{% url 'categorisation_rules' %}{% endif %}" role="button" class="secondary">Annuler</a>
    <input type="submit" value="Envoyer">
</div>
</form>


{% endblock %}