

<?php $__env->startSection('content'); ?>
    <div class="content">
        <div class="container-fluid">
            <div class="row">
                <div class="col-md-12">
                    <div class="card">
                        <div class="card-body">
                            <div class="row">
                                <div class="col-md-12 float-left">
                                    <button type="button" class="btn btn-primary" onclick="addModal()">
                                        Tambah
                                      </button>
                                </div>
                            </div>
                            <div class="table-responsive">
                                <table class="table table-hover" style="width:100%;" id="table_jenis_doc">
                                    <thead>
                                        <tr class="odd">
                                            <th>
                                                No.
                                            </th>
                                            <th>
                                                Jenis Dokumen
                                            </th>
                                            <th>
                                                Parent
                                            </th>
                                            <th>
                                                Aksi
                                            </th>
                                        </tr>
                                        
                                    </thead>
                                    <tbody>
                                        
                                    </tbody>
                                </table>
                            </div>

                            
                            <!-- Modal -->
                            <div class="modal fade" id="tambahDoc" tabindex="-1" aria-labelledby="tambahDocLabel" aria-hidden="true">
                                <div class="modal-dialog">
                                <div class="modal-content">
                                    <div class="modal-header">
                                        <h5 class="modal-title" id="tambahDocLabel">Tambah Jenis Dokumen</h5>
                                    
                                    </div>
                                    <div class="modal-body">
                                        <form action="" id="jenisDocForm" name="jenisDocForm">
                                            <?php echo csrf_field(); ?>
                                            <div class="form-group<?php echo e($errors->has('nama') ? ' has-danger' : ''); ?>">
                                                <label class="form-control-label" for="input-nama">
                                                    <?php echo e(__('Nama Dokumen')); ?>

                                                </label>
                                                <input type="text" name="nama" id="input-nama" class="form-control<?php echo e($errors->has('nama') ? ' is-invalid' : ''); ?>"  placeholder="<?php echo e(__('Nama Dokumen')); ?>" required autofocus>
                                                <input type="hidden" name="id" id="input-id" class="form-control<?php echo e($errors->has('id') ? ' is-invalid' : ''); ?>"  placeholder="<?php echo e(__('Nama Dokumen')); ?>" required autofocus>
                
                                                <?php echo $__env->make('alerts.feedback', ['field' => 'nama'], \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
                                            </div>
                                            <!-- <div class="form-group<?php echo e($errors->has('level') ? ' has-danger' : ''); ?>">
                                                <label class="form-control-label" for="levelSelect">
                                                    <?php echo e(__('Level Dokumen')); ?>

                                                </label>
                                                <select id="levelSelect" class="form-control" name="level">
                                                    <option value="">Pilih Level Dokumen</option>
                                                    <option value="0">1</option>
                                                    <option value="1">2</option>
                                                </select>
                
                                                <?php echo $__env->make('alerts.feedback', ['field' => 'level'], \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
                                            </div> -->
                                        </form>
                                    </div>
                                    <div class="modal-footer">
                                    <button type="button" class="btn btn-secondary" data-bs-dismiss="modal" onclick="closeModal()">Tutup</button>
                                    <button type="button" id="btn-save" class="btn btn-primary" onclick="save()">Simpan</button>
                                    <button type="button" id="btn-child" class="btn btn-primary" onclick="saveChild()">Simpan</button>
                                    <button type="button" id="btn-update" class="btn btn-primary" onclick="updateDoc()" style="display: none;">Update</button>
                                    </div>
                                </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
<?php $__env->stopSection(); ?>

<?php $__env->startPush('js'); ?>

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

        });

        function getTable() {
            var table = $('#table_jenis_doc').DataTable({
              processing: true,
              serverSide: true,
              ajax: "<?php echo e(route('jenis.table')); ?>",
              columns: [
                  {data: 'DT_RowIndex', name: 'DT_RowIndex'},
                  {data: 'nama', name: 'nama'},
                  {data: 'newLevel', name: 'newLevel'},
                //   {data: 'email', name: 'email'},
                //   {data: 'phone', name: 'phone'},
                  {
                      data: 'action', 
                      name: 'action', 
                      orderable: true, 
                      searchable: true
                  },
              ]
            });
        }

        function refresh_table() {
            $('#table_jenis_doc').DataTable().ajax.reload();
        }

        function save() {

            // console.log($('#jenisDocForm').serialize())
            $.ajax({
                data: $('#jenisDocForm').serialize(),
                url: "<?php echo e(route('jenis.save')); ?>",
                type: "POST",
                dataType: 'json',
                success: function (data) {
            
                    $('#jenisDocForm').trigger("reset");
                    $('#tambahDoc').modal('hide');
                    // table.draw();
                   demo.notifSuccess("Jenis Dokumen berhasil disimpan!")
                   refresh_table()
                },
                error: function (data) {
                    console.log('Error:', data);
                    // $('#saveBtn').html('Save Changes');
                }
            });
        }
        function addModal(){
            $('#jenisDocForm').trigger("reset");
            $('#tambahDocLabel').text('Tambah Jenis Dokumen')
            $('#tambahDoc').modal('show');
            $('#btn-save').show();
            $('#btn-child').hide();
            $('#btn-update').hide();
        }

        function closeModal(){
            $('#jenisDocForm').trigger("reset");
            $('#tambahDoc').modal('hide');
        }

        function editModal(id) {
            $('#jenisDocForm').trigger("reset");
            $('#tambahDocLabel').text('Edit Jenis Dokumen')
            console.log(id)
            $('#tambahDoc').modal('show');
            $('#btn-save').hide();
            $('#btn-child').hide();
            $('#btn-update').show();
            $.ajax({
                data: $('#jenisDocForm').serialize(),
                url: "jenis_doc/get/" + id,
                type: "GET",
                dataType: 'json',
                success: function (data) {
                    console.log(data.data.nama)
                    // $('#jenisDocForm').trigger("reset");
                    $('#input-id').val(data.data.id) 
                    $('#input-nama').val(data.data.nama) 
                    $('#levelSelect').val(data.data.level)
                    // $('#tambahDoc').modal('hide');
                    // table.draw();
                //    demo.notifSuccess("Jenis Dokumen berhasil disimpan!")
                
                },
                error: function (data) {
                    console.log('Error:', data);
                    // $('#saveBtn').html('Save Changes');
                }
            });
        }

        function updateDoc() {
            $.ajax({
                data: $('#jenisDocForm').serialize(),
                url: "<?php echo e(route('jenis.update')); ?>",
                type: "POST",
                dataType: 'json',
                success: function (data) {
                    console.log(data)
                    $('#jenisDocForm').trigger("reset");
                    $('#tambahDoc').modal('hide');
                    // table.draw();
                   demo.notifSuccess(data.message)
                   refresh_table()
                
                },
                error: function (data) {
                    console.log('Error:', data);
                    // $('#saveBtn').html('Save Changes');
                }
            });
        }

        function hapus(id) {
            console.log(id)
            $.ajax({
                url: "jenis_doc/delete/" + id,
                type: "get",
                // dataType: 'json',
                success: function (data) {
                    console.log(data)
                    // $('#jenisDocForm').trigger("reset");
                    // $('#tambahDoc').modal('hide');
                    // table.draw();
                   demo.notifSuccess(data.message)
                   refresh_table()
                
                },
                error: function (data) {
                    console.log('Error:', data);
                    // $('#saveBtn').html('Save Changes');
                }
            });
        }

        function childModal(id) {
            console.log(id)
            $('#jenisDocForm').trigger("reset");
            $('#tambahDocLabel').text('Tambah Sub Jenis Dokumen')
            $('#tambahDoc').modal('show');
            $('#btn-save').hide();
            $('#btn-child').show();
            $('#btn-update').hide();
            $.ajax({
                data: $('#jenisDocForm').serialize(),
                url: "jenis_doc/get/" + id,
                type: "GET",
                dataType: 'json',
                success: function (data) {
                    console.log(data.data.nama)
                    // $('#jenisDocForm').trigger("reset");
                    $('#input-id').val(data.data.id) 
                    // $('#input-nama').val(data.data.nama) 
                    // $('#levelSelect').val(data.data.level)
                    // $('#tambahDoc').modal('hide');
                    // table.draw();
                //    demo.notifSuccess("Jenis Dokumen berhasil disimpan!")
                
                },
                error: function (data) {
                    console.log('Error:', data);
                    // $('#saveBtn').html('Save Changes');
                }
            });
        }

        function saveChild(id) {
            $.ajax({
                data: $('#jenisDocForm').serialize(),
                url: "<?php echo e(route('jenis.child')); ?>",
                type: "POST",
                dataType: 'json',
                success: function (data) {
                    console.log(data)
                    $('#jenisDocForm').trigger("reset");
                    $('#tambahDoc').modal('hide');
                    // table.draw();
                   demo.notifSuccess(data.message)
                   refresh_table()
                
                },
                error: function (data) {
                    console.log('Error:', data);
                    // $('#saveBtn').html('Save Changes');
                }
            });
        }
    </script>
<?php $__env->stopPush(); ?>
<?php echo $__env->make('layouts.app', ['activePage' => 'jenis_dokumen', 'title' => 'Jenis Dokumen', 'navName' => 'Jenis Dokumen', 'activeButton' => 'laravel'], \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH D:\DARMAWANTO skripsi\project-g\resources\views/jenisDokumens/index.blade.php ENDPATH**/ ?>