
{!! Form::open(['url' => route('cms_content_all_store'), 'class' => 'modal-content', 'enctype' => 'multipart/form-data', 'id'=> 'cmsContentForm']) !!}

<input type="hidden" name="id" id="id" value="{{ $value->id > 0 ? $value->id : 'new' }}">
<input type="hidden" name="identifier" id="identifier" value="{{ $value->identifier }}">
<input type="hidden" name="back" id="back" value="{{ $data['back'] }}">


<div class="modal-header">
    <h5 class="modal-title">
        {{ __('Inhalt') }}
        <span class="font-weight-light">erstellen/bearbeiten</span>
    </h5>
    <button type="button" class="close" data-dismiss="modal" aria-label="Close">×</button>
</div>
<div class="modal-body">

    <div class="form-row">
        <div class="form-group col">
            <label for="field" class="form-label">{{ __('Type') }}*</label>
            <select class="selectpicker" name="field"  data-style="btn-light" data-live-search="true" required>
                {!! \App\Models\CMSContent::getFieldsOptions($value->field) !!}
            </select>
        </div>
    </div>

    <div class="form-row show-field-name">
        <div class="form-group col">
            <label for="name" class="form-label">{{ __('Name') }}</label>
            {{ Form::text('name', $value->name,  array('placeholder'=>__('Name'), 'class'=>'form-control', 'required')) }}
        </div>
    </div>


    <div class="form-row show-content-text" style="display:none ;">
        <div class="form-group col">
            <label for="text" class="form-label">{{ __('Text') }}</label>
            {{ Form::text('text', $value->text,  array('placeholder'=>__('Text'), 'class'=>'form-control')) }}
        </div>
    </div>

    <div class="form-row show-content-full_text" style="display:none ;">
        <div class="form-group col">
            <label for="full_text" class="form-label">{{ __('Full Text') }}</label>
            {{ Form::textarea('full_text', $value->full_text,  array('placeholder'=>__('Full Text'), 'class'=>'form-control', 'rows'=>20)) }}
        </div>
    </div>

    <div class="form-row show-content-integer" style="display:none ;">
        <div class="form-group col">
            <label for="integer" class="form-label">{{ __('Zahl') }}</label>
            {{ Form::text('integer', $value->integer,  array('placeholder'=>__('Zahl'), 'class'=>'form-control')) }}
        </div>
    </div>

    <div class="form-row show-content-decimal" style="display:none ;">
        <div class="form-group col">
            <label for="decimal" class="form-label">{{ __('Kommazahl') }}</label>
            {{ Form::text('decimal', $value->decimal,  array('placeholder'=>__('Kommazahl'), 'class'=>'form-control')) }}
        </div>
    </div>

    <div class="form-row show-content-file" style="display:none ;">

        @if($value->isFile())
            <div class="col-12 " id="preview-mail-attachment">
                <div class="message-attachment ui-bordered p-2 mr-3 mb-3">
                    <div class="message-attachment-file display-4"><i class="mail-att-icon {{$value->getIconExt()}}"></i></div>
                    <div class="media-body ml-3">
                        <strong class="message-attachment-filename">{{$value->filename}}</strong>
                        <div class="text-muted small mail-att-size">{{$value->formatBytes()}}</div>
                        <div>
                            <a href="{{$value->getURL()}}" target="_blank" class="mail-att-show">Vorschau</a> &nbsp;
                            {{-- <a href="javascript:void(0)" class="mail-att-delete">entfernen</a> --}}
                        </div>
                    </div>
                </div>
            </div>
        @else

        <div class="col-12">
            <div class="alert alert-danger alert-dismissable" style="display:none;"></div>
        </div>
        <div class="col-12 mt-2 mb-4">
            <!-- You can add extra form fields here -->
            <div class="dropzone" id="fileUploadContentForm"></div>
        </div>
        @endif
    </div>

    <div class="form-row show-field-slug">
        <div class="form-group col-sm-10">
            <label for="slug" class="form-label">{{ __('Slug') }}</label>
            {{ Form::text('slug', $value->slug,  array('class'=>'form-control')) }}
        </div>
        <div class="form-group col-sm-2">
            <label for="pos" class="form-label">{{ __('Position') }}</label>
            {{ Form::text('pos', $value->pos,  array('class'=>'form-control')) }}
        </div>
    </div>

</div>
<div class="modal-footer">
    <button type="button" class="btn btn-default" data-dismiss="modal">schließen</button>
    <button type="submit" class="btn btn-primary">speichern</button>
</div>
{!! Form::close() !!}




<script type="text/javascript">

    $( document ).ready(function() {

        $('#cmsContentForm div[class*="show-content"]').hide();
        $('#cmsContentForm .show-content-'+$('#cmsContentForm select[name="field"]').val()).show();

        function cmsContentShowFileFields(){
            if($('#cmsContentForm select[name="field"]').val() === 'file' && $('#cmsContentForm input[name="id"]').val() === 'new'){
                $('.show-field-slug').hide();
                $('.show-field-name').hide();
            }else{
                $('.show-field-slug').show();
                $('.show-field-name').show();
            }
        }
        cmsContentShowFileFields();

        $('#cmsContentForm select[name="field"]').on('change', function () {
            $('#cmsContentForm div[class*="show-content"]').hide();
            $('#cmsContentForm .show-content-'+$(this).val()).show();
            cmsContentShowFileFields();
        });

        Dropzone.autoDiscover = false;
        $("#fileUploadContentForm").dropzone({
            url: "{{route('cms_content_all_store')}}",
            params: {'identifier':'{{ $value->identifier }}','back':'{{$data['back'] }}'},
            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();
                console.log(message);
                _ele.text(message);
            },
            success: function(file, response) {
                  console.log(file);
                  console.log(response);
                if(response.error === false){
                    //window.location.href = window.location.href; //This is a possibility
                    window.location.reload(); //Another possiblity
                }
            }
        });
    });


</script>
