@extends('layouts.master')
@section('pageTitle') @include('layouts.includes.title', ['moduleTitle' => __('locale.timetable')]) @stop
@section('pageBreadcrumb') @include('layouts.includes.breadcrumb', ['moduleTitle' => __('locale.file_manager').' '. __('locale.details') ]) @stop
@section('content')
    <div class="row __sms__datatable">
        <div class="col-lg-12">
            <div class="card card-topline-yellow">
                <div class="card-head">
                    <header>{{ __('locale.upload_file_manager')}} </header>
                </div>
                <div class="card-body ">
                    {!! Form::open(['id' => 'uploadFileForm', 'data-create-url' => route('file_manager.store'), 'data-update-url' => route('file_manager.update', 'timetableRef')]) !!}
                    {!!  Form::hidden('__ref__id', 0, array("class" => "__ref__id", "id" => "__ref__id", "readonly" => true)) !!}
                    <div class="row">
                        {!!  Form::openGroup('class_id', __('locale.standard') ,array("lbl_class" => "required", "class" => 'col-lg-12')) !!}
                        {!!  Form::select('class_id', [null=>__('locale.please_select')] +$data['studentClasses'], '', array("required" => "true", 'id' => '_ref_class_id', 'class'=> 'form-control col-lg-4','defaultTxt' => __( 'locale.select' ) ) ) !!}
                        {!!  Form::closeGroup() !!}

                        {!!  Form::openGroup('file_title', __('locale.file_title'), array("lbl_class" => "required", "class" => 'col-lg-12')) !!}
                        {!!  Form::text('file_title', old('file_title'), array("class" => "__sms_file_title col-lg-4")) !!}
                        {!!  Form::closeGroup() !!}

                        {!!  Form::openGroup('category', __('locale.category') ,array("lbl_class" => "required", "class" => 'col-lg-12')) !!}
                        {!!  Form::select('category', [null=>__('locale.please_select')] +$data['fileCategory'], '', array("required" => "true", 'id' => '_ref_category', 'class'=> 'form-control col-lg-4','defaultTxt' => __( 'locale.select' ) ) ) !!}
                        {!!  Form::closeGroup() !!}

                        <div class="col-lg-12">
                            <label class="control-label col-md-3">{{ __('locale.upload_file')}}
                                <span class="required">*</span>
                            </label>
                            <div class="col-md-10">
                                <div id="id_dropzone" class="dropzone dz-clickable"><div class="dz-default dz-message"><span>Drop files here to upload</span></div></div>
                            </div>
                        </div>

                        {!!  Form::openGroup('tags', __('locale.tags'),array("lbl_class" => "required", "class" => 'col-lg-12')) !!}
                        {!!  Form::text('tags',old('tags'),["required" => "true", 'id' => '_ref_tags', "autocomplete" => "off",'class' => 'form-control col-lg-12 tags tags-input', 'data-type' => "fruits-tags", 'data-highlight-color'=>"#00C0EF", "style" => 'width:100px;']) !!}
                        {!!  Form::closeGroup() !!}

                        <div class="col-lg-12 form-group col-md-12" id="form-errors"></div>

                        <div class="col-lg-12 form-group col-md-12" style="align-self: flex-end;">
                            <button type="submit"
                                    class="mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect m-b-10 btn-pink float-right"
                                    id="form-btn-save" data-upgraded=",MaterialButton,MaterialRipple">Save<span
                                    class="mdl-button__ripple-container"><span class="mdl-ripple"></span></span>
                            </button>
                        </div>
                    </div>
                    {!! Form::close() !!}
                </div>
            </div>
        </div>
    </div>
    <div class="row">
        <div class="col-lg-12">
            <div class="card card-topline-yellow">
                <div class="card-body ">
                    <div class="table-scrollable">
                        <table id="{{$moduleName}}-table"
                               class="display table table-checkable order-column valign-middle __class__teacher__table"
                               style="width: 100%">
                            <thead>
                            <tr>
                                <th width="10%"> {{ __('locale.class') }}</th>
                                <th width="20%"> {{ __('locale.file_title') }}</th>
                                <th width="20%"> {{ __('locale.category') }}</th>
                                <th width="20%"> {{ __('locale.tags') }}</th>
                                <th width="10%"> {{ __('locale.date') }}</th>
                                <th width="15%"> {{ __('locale.download') }}</th>
                            </tr>
                            </thead>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
@stop
@section('scripts')

    <link href="{{ asset('assets/plugins/sweet-alert/sweetalert2.min.css') }}" rel="stylesheet">
    <script src="{{ asset('assets/plugins/sweet-alert/sweetalert2.all.min.js') }}"></script>

    <link href="{{ asset('assets/plugins/dropzone/dropzone.css') }}" rel="stylesheet"
          type="text/css" />
    <script src="../assets/plugins/dropzone/dropzone.js"></script>
    <!--tagsinput-->
    <link href="../assets/plugins/jquery-tags-input/jquery-tags-input.css" rel="stylesheet">
    <!--tags input-->
    <script src="../assets/plugins/jquery-tags-input/jquery-tags-input.js"></script>
    <script src="../assets/plugins/jquery-tags-input/jquery-tags-input-init.js"></script>

    <script>

        Dropzone.autoDiscover = false;
        $(document).ready(function () {
            $("#id_dropzone").dropzone({
                maxFiles: 1,
                maxFilesize: 10, // MB
                acceptedFiles: null,
                url: "{{ route('file_manager.upload') }}",
                sending: function (file, xhr, formData) {
                    formData.append("_token", "{{ csrf_token() }}");
                },
                success: function (file, response) {
                    let data = $.parseJSON(response);
                    if (data.success == true) {

                        let input = document.createElement("input");
                        input.setAttribute("type", "hidden");
                        input.setAttribute("class", "uploaded-files");
                        input.setAttribute("name", "file_name");
                        input.setAttribute("value", data.data);
                        document.getElementById("uploadFileForm").appendChild(input);

                    } else {
                        $(".upl-success").fadeOut();
                        $(".upl-fail").html(data.message);
                        $(".upl-fail").fadeIn(100);
                    }
                    // this.removeAllFiles();
                }
            });
        })


        let columnsArray = [{data: 'class', name: 'class '}, {data: 'file_title', name: 'file_title'},
            {data: 'category', name: 'category'},
            {data: 'tags', name: 'tags'},
            {data: 'date', name: 'date'},
            {data: 'download', name: 'download'}];
        let routeUrl = "{{ route($moduleName.'.index') }}";
        let tableRef = "{{ $moduleName.'-table'}}";
        // Run the Datatable
        let table = __commonDatatableListing(tableRef, routeUrl, columnsArray);
        let actionUrl = {
            {{--'_add_edit_record': "{{ route($moduleName.'.crud', '_refSection') }}",--}}
            '_edit_record': "{{ route($moduleName.'.edit', '_refSection') }}",
            '_destroy_record': "{{ route($moduleName.'.destroy', '_refSection') }}",
            {{--'_get_division': "{{ route($moduleName.'.get_divisions') }}",--}}
            '_success_msg': "{{ __('locale.file_saved') }}",
            '_get_class_section_url': "{{ route('class.ajax_on_change', 'classId') }}"
        };
    </script>
@stop

