@extends('layouts.app', ['activePage' => 'dokumen', 'title' => 'Dokumen', 'navName' => 'Tambah Dokumen', 'activeButton' =>
'laravel'])

@section('content')
<div class="content">
    <div class="container-fluid">
        <div class="row">
            <div class="col-md-12">
                <div class="card">
                    <div class="card-body">
                        
                        
                        <form action="{{route('doc.save')}}" method="post" enctype="multipart/form-data">
                        
                            {{ csrf_field() }}
                            <div class="form-group">
                                <label for="Product Name">Nama Dokumen</label>
                                <input type="text" name="nama" class="form-control" placeholder="Product Name">
                            </div>
                            <div class="form-group">
                                <label class="form-control-label" for="jenisDoc">
                                    {{ __('Jenis Dokumen') }}
                                </label>
                                <select id="jenisDoc" class="form-control"  name="jenis_doc">
                                    <option value="">Pilih Jenis Dokumen</option>
                                    {{-- <option value="0">1</option>
                                    <option value="1">2</option> --}}
                                </select>
                            </div>
                            <label for="Product Name">File Dokumen</label>
                            <br />
                            <input type="file" class="form-control"  name="doc" />
                            <br /><br />
                            <input type="submit" class="btn btn-primary" value="Upload" />
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
@endsection

@push('js')

<script type="text/javascript">
    
    $(document).ready(function () {
        // Javascript method's body can be found in assets/js/demos.js
        getJenis();

    });

    function getJenis(){
        $.ajax({
            // data: $('#docForm').serialize(),
            url: "{{ route('jenis.all') }}",
            type: "GET",
            dataType: 'json',
            success: function (data) {
                $("#jenisDoc").empty();

                for( var i = 0; i<data.data.length; i++){
                    var id = data.data[i]['id'];
                    var name = data.data[i]['nama'];
                    
                    $("#jenisDoc").append("<option value='"+id+"'>"+name+"</option>");

                }

            },
            error: function (data) {
                console.log('Error:', data);
                // $('#saveBtn').html('Save Changes');
            }
        });
    }

</script>
@endpush
