{% extends 'localcosmos_server/modals/large_modal_form.html' %}
{% load i18n localcosmos_tags %}

{% block title %}{% trans 'Add image' %}{% endblock %}

{% block action %}{% url 'datasets:add_dataset_image' request.app.uid dataset.id image_field_uuid %}{% endblock %}
{% block enctype %}multipart/form-data{% endblock %}

{% block footer %}
    {% include 'localcosmos_server/modals/footers/save.html' %}
{% endblock %}

{% block body %}
    {% if success %}
    {% else %}
        <div>
            {% render_bootstrap_form form %}
        </div>
    {% endif %}
{% endblock %}

{% block script %}
    {% if success %}
        <script>
            $("#LargeModal").modal("hide");

            const base_url = "{% url 'datasets:load_form_field_images' request.app.uid dataset.id %}";
            
            const url = base_url + "?field_uuid={{ image_field_uuid }}";

            const pictures_container_id = "id_{{ image_field_uuid }}_pictures";
            $.get(url, function(html){
                $("#" + pictures_container_id).html(html);
                ajaxify(pictures_container_id);
            });
        </script>
    {% endif %}
{% endblock %}