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

{% block title %}{% block og_title %}Importation récurrente{% endblock %}{% endblock %}

{% block configurer-bouton %}{% endblock %}

{% block entete_header %}
<script src="{% static 'choicejs/choices.min.js' %}"></script>

<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>
{% endblock %}

{% block content %}

<h1>Importation récurrente</h1>

<article>
    <form method="post">{% csrf_token %}
        {{ form.as_p }}
        <div class="grid buttons">
            <a href="{% if request.META.HTTP_REFERER %}{{ request.META.HTTP_REFERER }}{% else %}{{ object.get_absolute_url }}{% endif %}" role="button" class="secondary">Annuler</a>    
            <input type="submit" value="Envoyer">
        </div>
    </form>
</article>

<script>
        show_firstgroup = {
                choice(classes, choice) {
                    const i = Choices.defaults.templates.choice.call(this, classes, choice);
                    if (this.first_group !== null && choice.groupId == this.first_group)
                        i.classList.add("visible");
                    return i;
                },
                choiceGroup(classes, group) {
                    const g = Choices.defaults.templates.choiceGroup.call(this, classes, group);
                    if (this.first_group === undefined && group.value == "Suggestions")
                        this.first_group = group.id;
                    if (this.first_group !== null && group.id == this.first_group)
                       g.classList.add("visible");
                    return g;
                }
    };

    const tags = document.querySelector('#id_defaultTags');
    const choices_tags = new Choices(tags,
        {
            placeholderValue: 'Sélectionner les étiquettes par défaut',
            allowHTML: true,
            delimiter: ',',
            removeItemButton: true,
            shouldSort: false,
            callbackOnCreateTemplates: () => (show_firstgroup)
        }
    );
</script>

{% endblock %}