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

{% block body %}
<div class="modal-body clearfix display_table">
	<span class="icone-modal {{ iconePopup | default('interrogation') }}"></span>
    <div class="display_cell">
    	<b>{{ strBuild('Le fournisseurs @1@ possède déjà ce N° Siret.' | trad, {'1': fournisseur})|raw  }} </b><br/>
        {{ 'Souhaitez-vous lier le fournisseur aux sociétés suivantes ?' | trad }}
        <br/>
        <ul>
            {% for societe in listeSteToAdd %}
                <li>- {{ societe.LIBELLE }} ({{ societe.CODE_STE }})</li>
            {% endfor %}
        </ul>
  	</div>
</div>
<div class="modal-footer">
    <button type="button" class="button secondaire" onClick="desactivePopup();">{{ 'Annuler' | trad }}</button>
    <button type="button" class="button secondaire" onClick="validateFrs('{{ pathValidation }}');">{{ 'Non' | trad }}</button>
    <button type="button" class="button principal" onClick="addSociete('{{ pathSociete }}')">{{ 'Oui'|trad }}</button>
</div>

<script>
    function addSociete(path)
    {
        activeLoader();
        $.ajax({
            url : path ,
            type: 'POST',
            success: function (data) {
                desactiveLoader();
                $("#modal-content").addClass("modal_small");
                $("#modal-body").html(data);
                activePopup();
            }
        });
    }

    function validateFrs(path)
    {
        activeLoader();
        $.ajax({
            url : path ,
            type: 'POST',
            data: {'byPassSociete' : true},
            success: function (data) {
                desactiveLoader();
                $("#modal-content").addClass("modal_small");
                $("#modal-body").html(data);
                activePopup();
            },
            error: function (data){
                var data = jQuery.parseJSON(data.responseText);
                if(data.postGestion){
                    redirectJSWithPost(data.path, data.postGestion);
                }
                else{
                    window.location.href = data.path;
                }
            }
        });
    }

</script>

{% endblock %}