{% 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 }}
  	</div>
</div>
	<div class="modal-body">
		<div class="row ml-2">
			<div class="col-md-6 colonne2-flex-between">
				<label>{{ 'Sur les dossiers en préparation et les modèles' | trad }}</label>
				{{ inputAdvance('SWITCH', {
					'titre' : '',
					'name' : 'del_foldersInProgress',
					'addClass' : 'hor'
				}) }}
			</div>
		</div>
		<div class="row mt-half ml-2">
			<div class="col-md-6 colonne2-flex-between">
				<label>{{ 'Uniquement sur les modèles' | trad }}</label>
				{{ inputAdvance('SWITCH', {
					'titre' : '',
					'name' : 'del_TemplatesOnly',
					'addClass' : 'right hor'
				}) }}
			</div>
		</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" onClick="AjaxSuppresionEntity('{{ pathURL }}', '{{ entity }}', '{{ div }}', '{{ form }}', '{{ nextPath }}', {{ postPath? postPath:"{}" }});desactivePopup();">{{ 'Confirmer' | trad}}</button>
    {% endif %}
</div>

<script>
$("#modal-title").html('{{ titrePopup? (titrePopup | raw):('')}}');

$('#input_del_foldersInProgress').on('click', function (e) {
	if($(this).is(':checked') && $('#input_del_TemplatesOnly').is(':checked')) {
		changeValueSwitch('del_TemplatesOnly', false);
	}
})
$('#input_del_TemplatesOnly').on('click', function (e) {
	if($(this).is(':checked') && $('#input_del_foldersInProgress').is(':checked')) {
		changeValueSwitch('del_foldersInProgress', false);
	}
})


function AjaxSuppresionEntity(path, entity, div, form, nextPath, postPath)
{
	data = "{{ prePost |e('js') }}";

	var data = data.replace(/&quot;/g, '"');
	activeLoader();
	$.ajax({
      	dataType : 'html',
    	url: path,
    	data : {
      		'entity': entity,
			del_foldersInProgress: $('#input_del_foldersInProgress').is(':checked'),
			del_TemplatesOnly: $('#input_del_TemplatesOnly').is(':checked'),
			prePost: data
		},
    	type: "POST",
		statusCode: {
			413: function(xhr) {
				desactiveLoader();
				desactivePopup();
				alert('Error - ModSecurity.');
			},
			500: function(xhr) {
				desactiveLoader();
				desactivePopup();
				alert('Internal Server Error.');
			}
		},
    	success: function(result) {
    		desactiveLoader();
    		if(div=='page')
    		{
    			window.location.reload();
    		}
    		else if (div=='redirection')
    		{
    			redirectJSWithPost(nextPath, postPath);
    		}
    		else
			{
                try{
                     var data = jQuery.parseJSON(result);
                }catch(error){
                     data = {};
                }

				if(data.path)
				{
					refrechDiv(data.path, div, form);
				}
				else if(nextPath)
				{
					refrechDiv(nextPath, div, form);
				}
    			else
    			{
    				refrechDiv(window.location.pathname, div, form);
    			}
			}
    	}
    });
}
</script>
{% endblock %}