
<script>
    function sendFordm(id)
    {
    	activeLoader();
    	jForm.append("pageParent", $('#pageParent').val());
    	jForm.append("validationForm", $('#validationForm').val());
    	jForm.append("URLfileToUpload", $('#input_URLfileToUpload').val());
    	jForm.append("type", $('#type').val());

        $.ajax({
        	url : '{{ path('Facture.popup.uploadImageFacture' , {numFact : numFact }) }}',
            type: 'POST',
		  	dataType : 'JSON',
            data: jForm,
            mimeType: "multipart/form-data",
            contentType: false,
            cache: false,
            processData: false,
            success: function (data) {
                if(data.statut == 'O')
                {
					{% if post.pageParent=='creationFacture' %}
						$('#imageFacture span').html(data.nameImageFacture);
						$('#FIC_LAD').val(data.FIC_LAD);
						$('#imageFacture button').show()
					{% else %}
						reloadGestionFacture('{{ path('Facture.GestionFacture.index') }}');
					{% endif %}
		    		desactiveLoader();
    	        	desactivePopup ();
                } else{
            		desactiveLoader();
                	$('#message_erreur_popup').html(data.message);
					$('#message_erreur_popup').show();
                }
            }
        });
        return false;
    }

    function switchDiv(value)
    {	
        if(value=='E')
        {
            $('#uploadInput').css("display", "none");
            $('#urlInput').css("display", "block");
        }else
        {
    	   $('#uploadInput').css("display", "block");
           $('#urlInput').css("display", "none");
        }
    }

    // ouverture du lien dans un nouvel onglet 
    $('#url_URLfileToUpload').click(function() {
        let link = $('#input_URLfileToUpload').val();
        window.open(link, '_blank');
        window.focus();
    })
        


</script>
<div id="message_erreur_popup" class="error displayNone clearfix" ></div>
<form method="post" enctype="multipart/form-data" name="form_choix_image" id="form_choix_image" class="">
    <input type="hidden" name="pageParent" id="pageParent" value="{{ post.pageParent }}"/>
    {#
    Dossier 40876 : désactivation "temporaire" du chargement par URL
    <div class="row">
        <label>Type :</label>
        <select name="type" id="type" class="form-control" onchange="switchDiv(this.value)">
            <option value="C" >{{ 'Copie' | trad }}</option>
            <option value="E" >{{ 'URL' | trad }}</option>
        </select>
        <input type="hidden" name="validationForm" id="validationForm" value="1" />
    </div>
    #}
    <input id="type" type="hidden" name="toto" value="C" />
    <input type="hidden" name="validationForm" id="validationForm" value="1" />

    <div class="row" id="uploadInput">
        {{ inputAdvance('FILE', {'name' : 'fileToUpload' }) }}
    </div>
    {#
    <div class="row" id="urlInput" style="display : none">
        {{ inputAdvance('TEXT',{
            'titre' : 'URL du fichier à importer :' | trad,
            'name' : 'URLfileToUpload',
            'pathValidator' : path('Ajax.validator.isUrlValide'),
            'paramsValidator' : "{}",
            'iconeLabel' : 'URL2.png',
            'idIconeLabel' : 'url_URLfileToUpload',
            'tooltipIconeLabel' : 'Ouverture du lien dans un nouvel onglet' | trad,
        }) }}
    </div>
    #}
    <div class="modal-footer">
        <button type="button" class="button secondaire" data-dismiss="modal" onClick="desactivePopup();">{{ 'Annuler' | trad }}</button>
        <button type="button" class="button principal" onclick="sendFordm('form_choix_image');">{{ 'Enregistrer' | trad }}</button>
    </div>
</form>
