
<div class="modal-content">
<div class="modal-header">
    <h5 class="modal-title">
        {{ __('Datei') }}
        <span class="font-weight-light">hinzufügen</span>
    </h5>
    <button type="button" class="close" data-dismiss="modal" aria-label="Close">×</button>
</div>
<div class="modal-body">
    <div class="form-row show-content-file">
        <div class="col-12">
            <div class="alert alert-danger alert-dismissable" style="display:none;"></div>
        </div>
        <div class="col-12 mt-2 mb-4">
            {!! Form::open([ 'url' => $data['url'], 'method' => 'post', 'files' => true, 'enctype' => 'multipart/form-data', 'class' => 'dropzone', 'id' => 'uploadModalFile' ]) !!}
            <input type="hidden" name="id" value="{{ $data['id'] }}">
            <input type="hidden" name="action" value="{{ $data['action'] }}">
            <input type="hidden" name="back" value="{{ $data['back'] }}">

            <div class="fallback">
                <input name="file" type="file" multiple>
            </div>
            {!! Form::close() !!}
        </div>
    </div>
</div>
<div class="modal-footer">
    <button type="button" class="btn btn-default" data-dismiss="modal">schließen</button>
</div>
</div>




<script type="text/javascript">

    var responseRedirect = undefined;
    $('#modals-load-content').on('hide.bs.modal', function (event) {
       $(this).off('hide.bs.modal');
       if(responseRedirect){
           window.location.href = responseRedirect;
       }
    });

    $( document ).ready(function() {
        Dropzone.autoDiscover = false;
        $("#uploadModalFile").dropzone({
            uploadMultiple: false,
            parallelUploads: 1,
            maxFilesize: 32,
            addRemoveLinks: true,
            dictDefaultMessage: '<i class="ion ion-ios-cloud-upload "></i>Hier klicken, oder Datei hier reinziehen (Drag&Drop)',
            dictFallbackMessage: 'Ihr Browser unterstützt Drag&Drop Dateiuploads nicht',
            dictFallbackText: 'Benutzen Sie das Formular um Ihre Dateien hochzuladen',
            dictFileTooBig: "Die Datei ist zu groß. Die maximale Dateigröße beträgt 32 MB",
            dictInvalidFileType: 'Eine Datei dieses Typs kann nicht hochgeladen werden',
            dictResponseError: "Der Server hat ihre Anfrage mit Status error abgelehnt",
            dictCancelUpload: 'Hochladen abbrechen',
            dictCancelUploadConfirmation: null,
            dictRemoveFile: 'Datei entfernen',
            dictMaxFilesExceeded: 'Sie können keine weiteren Dateien mehr hochladen',
            acceptedFiles: "image/jpeg,image/pjpeg,image/png,image/gif,application/pdf,text/plain",
            // The setting up of the dropzone
            headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
            },
            init:function() {
                this.on("removedfile", function(file) {
                    var _ele = $('.alert-danger');
                    _ele.fadeOut();

                });
                this.on("addedfile", function (file) {
                    var _ele = $('.alert-danger');
                    _ele.fadeOut();
                });
            },
            error: function(file, response) {
                var message
                if($.type(response) === "string")
                    message = response; //dropzone sends it's own error messages in string
                else
                    message = response.message;
                var _ele = $('.alert-danger');
                _ele.fadeIn();
                $(file.previewElement).find('.dz-error-message').text(message);
                $(file.previewElement).addClass('dz-error');
                _ele.text(message);
            },
            success: function(file, response) {
                  //console.log(file);
                  //console.log(response);
                $(file.previewElement).addClass('dz-success');
                if(response.error === false){
                    if(response.redirect){
                        responseRedirect = response.redirect;
                       // window.location.href = response.redirect
                    }else{
                        //window.location.href = window.location.href; //This is a possibility
                       // window.location.reload(); //Another possiblity
                    }
                }
            }
        });
    });


</script>
