{% extends '@ajax-layout/layout.twig' %}

{% block body %}
<div class="modal-body clearfix display_table">
    {% if error != '' %}
        <div class="modal_attention">
            {{ error | raw }}
        </div>
    {% else %}
        <span class="icone-modal interrogation"></span>
        <div class="display_cell">
            {{ message | raw }}
        </div>
    {% endif %}
</div>
<div class="modal-footer">
    <button type="button" class="button secondaire" data-dismiss="modal" onClick="desactivePopup();desactiveLoader();">{{ 'Annuler' | trad}}</button>
    {% if pathURL and error  == ''%}
    	<button type="button" class="button principal" id="confirmeDelete" onClick="AjaxValidationQuestion('{{ pathURL }}', '{{ entity }}', 'redirect', '{{ form }}');desactivePopup();">{{ 'Confirmer' | trad}}</button>
    {% endif %}
</div>
<script>
    $("#modal-title").html('{{ params.titrePopup ? (params.titrePopup|e('js')|raw) : ('Validation'|trad)}}');

	{% if (error != '')  %}
		$( document ).ready(function() {
			$('.modal-header').addClass('popup_error');
		});
	{% endif %}

    function AjaxValidationQuestion(path, entity, div, form)
    {
        activeLoader();
        $.ajax({
            dataType : 'html',
            url: path,
            data : { 'entity' : entity ,'div' : div ,'form' : form },
            type: "POST",
            success: function(result){
                desactiveLoader();
                if(div=='page')
                {
                    window.location.reload();
                }
                else if(div=='redirect')
                {
                    try{
                        var data = jQuery.parseJSON(result);
                    }catch(error){
                        data = {};
                    }
                    
                    if(data.path)
                    {
                        redirectJSWithPost(data.path, data.post);
                    }
                }
                else
                {
                    try{
                        var data = jQuery.parseJSON(result);
                    }catch(error){
                        data = {};
                    }
                    

                    if(data.path && data.pathOnlyRedirect != true)
                    {
                        refrechDiv(data.path, div, form);
                    }
                    else
                    {
                        refrechDiv(window.location.pathname, div, form);
                    }
                }
                    
            },
            error: function (data){
                desactiveLoader();
                $("#modal-content").addClass("modal_small");
                $("#modal-body").html(data.responseText);
                activePopup();
            }
        });
    }
</script>
{% endblock %}