@extends('layouts.app', ['activePage' => 'berita', 'title' => 'Edit Berita', 'navName' => 'Edit Berita', '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">
                        
                        <?php
                            if($data){
                                $judul = $data != null ? $data->judul : "";
                                $id = $data != null ? $data->id : "";
                                $isi = $data != null ? $data->isi : "";
                                $thumbnail = $data != null ? $data->thumbnail : "";
                            }
                            
                        ?>
                        
                        <form action="{{route('news.update')}}" method="post" enctype="multipart/form-data">
                            {{ csrf_field() }}
                            <div class="form-group">
                                <label for="Product Name">Judul</label>
                                <input type="text" name="judul" class="form-control" value="{{$judul}}">
                                <input type="hidden" name="id" class="form-control" value="{{$id}}">
                            </div>
                            <div class="form-group">
                                <label for="Isi Berita">Isi</label>
                                <textarea name="isi" id="isi"  class="form-control">
                                    {{$isi}}
                                </textarea>
                            </div>
                            <label for="Product Name">Thumbnail</label>
                            <br />
                            <input type="file" class="form-control" value="{{$thumbnail}}" name="thumbnail" />
                            <input type="hidden" name="old_thumbnail" value="{{$thumbnail}}">
                            <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
