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

{% block body %}
<form method="post" id="form_erreurPlusieursXML" name="form_erreurPlusieursXML">
	<div class="text-danger" data-form-error></div>
	<input type="hidden" name='postArray' id='postArray' value='{{ post }}'>
	{% if IGNORER_ACTIF %}
		<div class="text-right">
			<span class="mr-tiny">{{ 'Tout cocher' | trad }}</span>
			<input type="checkbox" class="form-control checkbox" 
				data-checkall-input="warning_ignore"
				style="vertical-align: bottom;"
			/>
		</div>
	{% endif %}

	{% for docStatus in listDocStatus %}
			<div class="bs-row flex-y-center">
				<h2 class="bs-col">
					{{ 
						strBuild(
							'@1@ n°@2@',
							[
								entityLabel | capitalize,
								docStatus.docId
							]
						) 
					}}
					{% if docStatus.status == 'B' %}
						{{colon() ~ 'Présence d\'erreurs bloquantes.' | trad}}
					{% elseif docStatus.status == 'A' %}
						{{colon() ~ 'Présence d\'avertissements.' | trad}}
					{% endif %}
				</h2>
				{% if docStatus.status == 'A' and IGNORER_ACTIF %}
				<div class="bs-col-auto">
					<input type="checkbox" class="form-control checkbox" 
						name="selection[{{ docStatus.docId }}]" value="1"
						data-checkall="warning_ignore" checked
					/>
				</div>
				{% endif %}
			</div>
			
			{% if docStatus.listAnomalie is not empty %}
			<div class="form">
				<table class="table table-hover">
					<thead class="thead-dark">
						<tr>
							<th scope="col" width="5%">{{ 'N°' | trad}}</th>
							<th scope="col">{{ 'Libellé' | trad }}</th>
							<th scope="col" width="15%">
								{{- 'Bloquant' | trad -}}
							</th>
						</tr>
					</thead>
					<tbody>
						{% for ano in docStatus.listAnomalie %}
						<tr>
							<td class="text-right">{{ ano.ligneId }}</td>
							<td>{{ ano.message | convert_encoding('UTF-8', 'ISO-8859-1') }}</td>
							{#<td {% if erreur.Bloquante=='true' %}class="bloquant"{% endif %}></td>#}
							<td>
								{{- ano.isBloquant=='true' ? 
									'Oui' | trad : 'Non' | trad 
								-}}
							</td>
						</tr>
						{% endfor %}
					</tbody>
				</table>                     
			</div>
			{% endif %}			
		    
		<input type="hidden" value="{{ docStatus.algoSpecif }}" name="algoSpecif[{{ docStatus.docId }}]" />

		{{ specifique('HtmlExtension', 'specifiqueBouygueSignature', {
			'listAnomalie': docStatus.listAnomalie,
			'algoSpecif' : docStatus.algoSpecif,
			'docId' : docStatus.docId
		}) }}
	{% endfor %}
	
    <div class="modal-footer text-right">
		<button type="button" class="button secondaire" 
			data-dismiss="modal" onClick='desactivePopup();'
		>{{ 'Annuler' | trad }}</button>
		{% if IGNORER_ACTIF  %}
		<button type="button" class="button principal" onClick="validationXML('{{ pathSubmit }}');">
			{{- 'Confirmer' | trad -}}
		</button>
		{% endif %}
    </div>
</form>

<script>
{% if IGNORER_ACTIF  %}
    $( document ).ready(function() {
		$('.modal-header').addClass('popup_alert');
    });
{% else %}
    $( document ).ready(function() {
        $('.modal-header').addClass('popup_error');
    });
{% endif %}

showBtnIgnorerPopupErrSign();
$("#modal-title").html("{{ 'Erreur' | trad ~ colon }}");

	{% if asynchrone %}

		function validationXML(path)
		{
			
			activeLoader();
			$.ajax({
				dataType : 'JSON',
				url: path,
				data: $('#form_erreurPlusieursXML').serialize(),
				type: 'POST', // la méthode indiquée dans le formulaire (get ou post)
				success: function(data) { // je récupère la réponse du fichier PHP
					if(data.statut == 'enregEnCours') {
						asyncBackground(wsdlEnAsync, data, '{{ path('Outil.Asynchrone.getResultAsynchrone') }}');
					} else {
						$('.text-danger').html(data.responseText);
						desactiveLoader();
					}
				}, 
				error: function (data){
					$('.text-danger').html(data.responseText);
					desactiveLoader();
				} 
			});
		}

		function wsdlEnAsync(requestData, dataRetourWsdl)
		{
			$.ajax({
				dataType : 'JSON',
				url: requestData.pathNextStep,
				data: {
					dataAsync: JSON.stringify(requestData),
					dataRetourWsdl: JSON.stringify(dataRetourWsdl),
				},
				type: 'POST', 
				success: function(data) {
					desactiveLoader();
					if (data.bodyHtml) {
						$("#modal-content").addClass(data.class);
						$("#modal-body").html(data.bodyHtml);
						$("#modal-title").html(data.title);
						activePopup();
					} else {
						refrechDiv(window.location.pathname, data.form, data.div);
					}
				}, 
				error: function (data){
					$('.text-danger').html(data);
					desactiveLoader();
				} 
			}); 
		}

	{% else %}
		function validationXML(path){

			activeLoader();
			$.ajax({
				url : path ,
				type: 'POST',
				data: $('#form_erreurPlusieursXML').serialize(),
				success: function (data) {
					desactiveLoader();
					$("#modal-body").html(data);
				},
				error: function (data){
					//si retour json code 443, alors on fait la redirection
					var data = jQuery.parseJSON(data.responseText);
					if(data.postGestion){
						redirectJSWithPost(data.path, data.postGestion);
					}
					else{
						window.location.href = data.path;
					}
				}
			});
		};
	{% endif %}

</script>
{% endblock %}