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

{% block body %}
<div class="modal-body clearfix display_table">
	<span class="icone-modal interrogation"></span>
    <div class="display_cell">
    	{{ message | raw }}
  	</div>
</div>
<div class="modal-footer">
    <button type="button" class="button secondaire" data-dismiss="modal" onClick="desactivePopup();desactiveLoader();">{{ 'Annuler' | trad}}</button>
    {% if pathURL %}
    	<button type="button" class="button principal" id="confirmeDelete" onClick="AjaxDevaliderGestionEval('{{ pathURL }}', '{{ entity }}', '{{ div }}', '{{ form }}');">{{ 'Confirmer' | trad}}</button>
    {% endif %}
</div>
<script>
function AjaxDevaliderGestionEval(path, entity, div, form)
{
	activeLoader();
	$.ajax({
      	dataType : 'html',
    	url: path,
    	data : { 'entity' : entity ,'div' : div ,'form' : form ,  'post' : {{post | raw }} },
    	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)
				{
					refrechDivGestionEval(data.path, div, form);
					
				}
    			else
    			{
    				refrechDivGestionEval(window.location.pathname, div, form);
    			}
			}
    			
    	},
    	error: function (data){
        	desactiveLoader();
            $("#modal-content").addClass("modal_small");
    		$("#modal-body").html(data.responseText);
            activePopup();
    	}
    });
}


function refrechDivGestionEval(path, id, form, menu, paramJson)
{
	activeLoader();
	if(form == 'undefined' || form == null)
	{

		data = '';
	}
	else if(paramJson != null || paramJson != 'undefined' && form == 'undefined' || form == null)
	{
		data = paramJson;
	}	
	else if(form)
	{
		data = $('#'+form).serialize();
	}
	else
	{
		data = '';
	}
	$.ajax({
			url: path,
			type: 'POST',
			dataType: 'html',
			data : {{post | raw }},
			success: function (htmlData) 
			{
			
				refreshFonction(id, htmlData, menu);
	
				desactiveLoader();
				desactivePopup();
				return true;
			}
	});	
	
	return false;

}
</script>
{% endblock %}