@extends('layouts.master')

@section('title')
    Penelitian Sumber Dana Non Kemenristek/BRIN
@endsection

@section('header')
<div class="page-title">
    <h3>Penelitian Sumber Dana Non Kemenristek/BRIN</h3>
</div>
@endsection

@section('contents')
@php
 $menu = 'dashboard';
@endphp
    <div class="account-settings-container layout-top-spacing">
        <form action="{{ route('penelitiansumber.store') }}" method="POST">
            @csrf
        <div class="account-content">
            <div class="scrollspy-example" data-spy="scroll" data-target="#account-settings-scroll" data-offset="-100">
                <div class="row">
                        <div class="col-xl-12 col-lg-12 col-md-12 layout-spacing">
                            <div id="contact" class="section contact">
                                <div class="info">
                                    <h5 class="">Data Penelitian Sumber Dana Non Kemenristek/BRIN</h5>
                                    <div class="row">
                                        <div class="col-md-11 mx-auto">
                                            <div class="row">
                                                <div class="col-md-12">
                                                    <div class="form-group">
                                                            <label>Judul</label>
                                                            <textarea class="form-control" name="data[judul]" id="judul" placeholder="Judul" rows="3"></textarea>
                                                    </div>
                                                </div>
                                                <div class="col-md-6">
                                                    <div class="form-group">
                                                        <label>Jenis Penelitian</label>
                                                        <select name="data[jenis]" class="form-control" id="kategori">
                                                            <option>Penelitian Dasar</option>
                                                            <option>Norway</option>
                                                            <option>Canada</option>
                                                        </select>
                                                    </div>
                                                </div>
                                                <div class="col-md-6">
                                                </div>
                                                <div class="col-md-6">
                                                    <div class="form-group">
                                                        <label>Kategori</label>
                                                        <select class="form-control" id="kategori">
                                                            <option>Penelitian Dasar</option>
                                                            <option>Norway</option>
                                                            <option>Canada</option>
                                                        </select>

                                                    </div>
                                                </div>
                                                <div class="col-md-6">
                                                    <div class="form-group">
                                                        <label>Bidang Penelitian</label>
                                                        <select name="data[bidang]" class="form-control" id="kategori">
                                                            <option>Penelitian Dasar</option>
                                                            <option>Norway</option>
                                                            <option>Canada</option>
                                                        </select>
                                                    </div>
                                                </div>
                                                <div class="col-md-6">
                                                    <div class="form-group">
                                                        <label>Kategori</label>
                                                        <select class="form-control" id="tujuan">
                                                            <option>Penelitian Dasar</option>
                                                            <option>Norway</option>
                                                            <option>Canada</option>
                                                        </select>
                                                    </div>
                                                </div>
                                                <div class="col-md-6">
                                                    <div class="form-group">
                                                        <label>Tujuan Sosial Ekonomi</label>
                                                        <select name="data[tujuan]" class="form-control" id="kategori">
                                                            <option>Penelitian Dasar</option>
                                                            <option>Norway</option>
                                                            <option>Canada</option>
                                                        </select>
                                                    </div>
                                                </div>
                                                <div class="col-md-6">
                                                    <div class="form-group">
                                                        <label>Sumber Dana</label>
                                                        <select name="data[sumberdana]" class="form-control" id="sumber_dana">
                                                            <option>Penelitian Dasar</option>
                                                            <option>Norway</option>
                                                            <option>Canada</option>
                                                        </select>
                                                    </div>
                                                </div>
                                                <div class="col-md-6">
                                                </div>
                                                <div class="col-md-6">
                                                    <div class="form-group">
                                                        <label>Institusi Sumber Dana</label>
                                                        <select name="data[institusi]" class="form-control" id="institusi">
                                                            <option>Penelitian Dasar</option>
                                                            <option>Norway</option>
                                                            <option>Canada</option>
                                                        </select>
                                                    </div>
                                                </div>
                                                <div class="col-md-6">
                                                </div>
                                                <div class="col-md-6">
                                                    <div class="form-group">
                                                        <label>Jumlah Dana</label>
                                                        <input name="data[jumlah_dana]" type="text" class="form-control mb-4" id="jumlah_dana" placeholder="Jumlah Dana">
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <div class="col-xl-12 col-lg-12 col-md-12 layout-spacing">
                            <div id="general-info" class="section general-info">
                                <div class="info">
                                    <h6 class="">Personil Dosen</h6>
                                    <div class="row">
                                        <div class="col-lg-11 mx-auto">
                                            <div class="row">
                                                <div class="col-md-8">
                                                    <div class="table-responsive">
                                                        <table class="table table-bordered mb-4">
                                                            <thead>
                                                                <tr>
                                                                    <th>No</th>
                                                                    <th>Nama</th>
                                                                    <th>Program Studi</th>
                                                                    <th class="text-center">Keanggotaan</th>
                                                                    <th></th>
                                                                </tr>
                                                            </thead>
                                                            <tbody id="table_dosen_nidn">
                                                            </tbody>
                                                        </table>
                                                    </div>
                                                </div>
                                                <div class="col-md-4">
                                                    <div class="input-group mb-4">
                                                        <input type="text" class="form-control" id="input_dosen_nidn" placeholder="NIDN" aria-label="nidn">
                                                        <div class="input-group-append">
                                                            <button type="button" onclick="checkNidn('dosen_nidn')" class="btn btn-info" type="button">Cek</button>
                                                        </div>
                                                    </div>
                                                    <div class="form-row mb-4">
                                                        <div class="form-group col-md-6">
                                                            <label for="inputEmail4">Nama Dosen</label>
                                                            <input type="text" class="form-control" id="nama_dosen_nidn">
                                                        </div>
                                                        <div class="form-group col-md-6">
                                                            <label for="inputPassword4">Program Studi</label>
                                                            <input type="text" class="form-control" id="prodi_dosen_nidn">
                                                        </div>
                                                        <div class="form-group col-md-6">
                                                            <div class="form-group">
                                                                <label>Keanggotaan</label>
                                                                <select class="form-control" id="keanggotaan_dosen_nidn">
                                                                    <option>Penelitian Dasar</option>
                                                                    <option value="norway">Norway</option>
                                                                    <option value="canada">Canada</option>
                                                                </select>
                                                            </div>
                                                        </div>
                                                        <div class="form-group col-md-6">
                                                            <input type="text" id="dosen_nidn" value="" hidden>
                                                        </div>
                                                        <div class="form-group col-md-6">
                                                            <button type="button" onclick="saveDosen('dosen_nidn')" id="multiple-messages" class="btn btn-primary">Save Changes</button>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <div class="col-xl-12 col-lg-12 col-md-12 layout-spacing">
                            <div id="general-info" class="section general-info">
                                <div class="info">
                                    <h6 class="">Personil Non Dosen</h6>
                                    <div class="row">
                                        <div class="col-lg-11 mx-auto">
                                            <div class="row">
                                                <div class="col-md-8">
                                                    <div class="table-responsive">
                                                        <table class="table table-bordered mb-4">
                                                            <thead>
                                                                <tr>
                                                                    <th>No</th>
                                                                    <th>Nama</th>
                                                                    <th>Institusi</th>
                                                                    <th class="text-center">Keanggotaan</th>
                                                                    <th></th>
                                                                </tr>
                                                            </thead>
                                                            <tbody id="table_non_dosen_nip">
                                                            </tbody>
                                                        </table>
                                                    </div>
                                                </div>
                                                <div class="col-md-4">
                                                    <div class="input-group mb-4">
                                                        <input type="text" class="form-control" placeholder="Nomor Identitas" aria-label="nidn" id="non_dosen_nip">
                                                    </div>
                                                    <div class="form-row mb-4">
                                                        <div class="form-group col-md-6">
                                                            <label for="inputEmail4">Nama</label>
                                                            <input type="text" class="form-control" id="nama_non_dosen_nip">
                                                        </div>
                                                        <div class="form-group col-md-6">
                                                            <label for="inputPassword4">Institusi</label>
                                                            <input type="text" class="form-control" id="prodi_non_dosen_nip">
                                                        </div>
                                                        <div class="form-group col-md-6">
                                                            <div class="form-group">
                                                                <label>Keanggotaan</label>
                                                                <select class="form-control" id="keanggotaan_non_dosen_nip">
                                                                    <option>Penelitian Dasar</option>
                                                                    <option>Norway</option>
                                                                    <option>Canada</option>
                                                                </select>
                                                            </div>
                                                        </div>
                                                        <div class="form-group col-md-6">
                                                        </div>
                                                        <div class="form-group col-md-6">
                                                            <button onclick="saveNonDosen('non_dosen_nip')" type="button" id="multiple-messages" class="btn btn-primary">Save Changes</button>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>


                </div>
            </div>
        </div>

        <div class="account-settings-footer">
            <div class="as-footer-container">
                <button id="multiple-reset" class="btn btn-warning">Batal</button>
                <button id="multiple-messages" class="btn btn-primary">Save Changes</button>
            </div>
        </div>
        </form>
    </div>

@endsection

@section('js')
    <script src="{{ url('theme/plugins/apex/apexcharts.min.js') }} "></script>
    <script src="{{ url('theme/assets/js/dashboard/dash_2.js') }} "></script>
    <script>
        var iDosen = 1;
        var iNonDosen = 1;
        function checkNidn(id){
            var value = $('#input_'+id).val();

            var request = $.ajax({
                url: "{{ route('get-biodata') }}",
                type: "get",
                dataType: "json",
                data: {nidn:value},
                success: function(result){
                    $('#nama_'+id).val(result['name']);
                    $('#prodi_'+id).val(result['prodi']);
                    $('#'+id).val(result['nidn']);
                }
            })
        }

        function saveDosen(id){
            saveChange(id, 'dosen', iDosen++);
        }

        function saveNonDosen(id){
            saveChange(id, 'non_dosen', iNonDosen++);
        }

        function saveChange(id, name, no){
            var nama = $('#nama_'+id).val();
            var prodi = $('#prodi_'+id).val();
            var nidn = $('#'+id).val();
            var keanggotaan = $('#keanggotaan_'+id).val();

            var request = $.ajax({
                url: "{{ route('get-row-anggota') }}",
                type: "get",
                dataType: "html",
                data: {nama:nama, prodi:prodi, nidn:nidn, keanggotaan:keanggotaan, name:name, no:no},
                success: function(result){
                    $('#table_'+id).append(result);
                }
            })
        }
    </script>
@endsection
