var $vars = {
    'status': $("#js-status"),
    'uploadBar': $("#uploadBar"),
    'montant': $("#montant"),
    'taux': $("#taux"),
    'registerModel' : $("#registerModel"),
    'selectDecomtpe' : $("#selectDecompte"),
    'depotValidation' : $("#depotValidation"),
    'fileLettre' : $("#fileLettre"),
    'fileJustificatifs' : $("#fileJustificatifs"),
    'fileAvancement' : $("#fileAvancement"),

    'extensions': null
};

$vars.registerModel.on("click", function(){
    $.ajax({
        'type': 'POST',
        'url': Routing.generate('test_AJAX'),
        'data': {
            'taux' : $vars.taux.val(),
            'montant' : $vars.montant.val(),
            'decompte' : $("#selectDecompte").find("option:selected").val(),
            'fileLettre' : $vars.fileLettre.val(),
            'fileJustificatifs' : $vars.fileJustificatifs.val(),
            'fileAvancement' : $vars.fileAvancement.val(),
        },
        'success': function (data) {
           console.log(data);
            swal({
                title: "coucou !",
                text: "bravo ça marche",
                icon: "success",
                button: {
                    text: "OK",
                    className: "bg-orange hoverOpacity"
                }
            })

        },
        'error': function (data) {
            console.log('error');
        }
    });
});

$vars.depotValidation.on('click', function(){
    var form = $('#formFiles').get(2);
    var formData = new FormData(form);// get the form data
    // console.log($('input[type=file]')[2].files[0]);



    //get file object
    var file = document.getElementById('fileLettre').files[0];
    if (file) {
        // create reader
        var reader = new FileReader();
        reader.readAsText(file);
        reader.onload = function(e) {
            // browser completed reading file - display it
            alert(e.target.result);
        };
    }

        $.ajax({
            // Your server script to process the upload


            url: Routing.generate('test_AJAX'),
            type: 'POST',
            cache: false,
            contentType: false,
            processData: false,


            // Form data
            'data': {
                'taux' : $vars.taux.val(),
                'montant' : $vars.montant.val(),
                'decompte' : $("#selectDecompte").find("option:selected").val(),
                'fileLettre' : $vars.fileLettre.val(),
                'fileJustificatifs' : $vars.fileJustificatifs.val(),
                'fileAvancement' : $vars.fileAvancement.val(),
                'files' : formData,
            },

            // cache: false,
            // contentType: false,
            // processData: false,


            'success' : function(data){
                console.log(document.getElementById('fileLettre').files[0]);

            }
        });
    });


