<?= $this->extend('template/layout') ?>

<?= $this->section('title') ?>Data Provinsi <?= env('app.name') ?><?= $this->endSection() ?>

<!-- main section start-->
<?= $this->section('main') ?>
<?php
    $uri      = current_url(true);
    $segment1 = $uri->setSilent()->getSegment(1);
    $segment2 = $uri->setSilent()->getSegment(2);
    $segment3 = $uri->setSilent()->getSegment(3);
?>
<!-- Breadcumb -->
<ol class="breadcrumb page-breadcrumb">
    <li class="breadcrumb-item"><a href="javascript:void(0);"><?= env('app.name') ?></a></li>
    <li class="breadcrumb-item"><?= ucfirst($segment1) ?></li>
    <li class="breadcrumb-item">Data Provinsi</li>
    <li class="position-absolute pos-top pos-right d-none d-sm-block"><span class="js-get-date"></span></li>
</ol>

<div class="row">
    <div class="col-xl-6">
        <div id="panel-1" class="panel">
            <div class="panel-hdr border-faded border-top-1 border-right-0 border-left-0 shadow-0">
                <h2>Data Provinsi</h2>
                <div class="panel-toolbar pr-3">
                    <ul class="nav nav-pills border-bottom-0" role="tablist">
                        <li class="nav-item">
                            <?= form_button('reload', '<i class="fal fa-sync"></i>', 'reload_datagrid_prov()') ?>&nbsp;
                        </li>
                        <li class="nav-item">
                            <?= form_button('read', '<i class="fal fa-eye"></i>', 'show_prov()') ?>&nbsp;
                        </li>
                        <?php if ($rekam == 1) { ?>
                        <li class="nav-item">
                            <?= form_button('create', '<i class="fal fa-plus"></i>', 'new_prov()') ?>&nbsp;
                        </li>
                        <?php } ?>
                        <?php if ($ubah == 1) { ?>
                        <li class="nav-item">
                            <?= form_button('update', '<i class="fal fa-edit"></i>', 'edit_prov()') ?>&nbsp;
                        </li>
                        <?php } ?>
                        <?php if ($hapus == 1) { ?>
                        <li class="nav-item">
                            <?= form_button('delete', '<i class="fal fa-trash-alt"></i>', 'delete_prov()') ?>
                        </li>
                        <?php } ?>
                    </ul>
                </div>
            </div><!-- end panel hdr -->

            <div class="panel-container show">
                <div class="panel-content">
                    <div id="panelfit-1" data-options="border:false">
                        <!-- grid start -->
                        <table id="datagrid_prov" toolbar="#toolbar_modul" url="<?= site_url('referensi/pdkprov/datagrid_prov') ?>" data-options="nowrap:true,striped:false,ctrlSelect:true,rownumbers:true,pagination:true,multiSort:true,remoteFilter:true,remoteSort:true,pageSize:10,pageList:[10,20,50,100],clientPaging:false,fit:true">
                            <thead data-options="frozen:true">
                                <tr>
                                    <th data-options="field:'ck',checkbox:true"></th>
                                </tr>
                            </thead>
                            <thead>
                                <tr>
                                    <th data-options="field:'nama_prov',sortable:true,width:300">Nama Provinsi</th>
                                    <th data-options="field:'nama_alt',sortable:true,width:200">Nama Alt</th>
                                    <th data-options="field:'kode',sortable:true,align:'center',width:70">Kode</th>
                                </tr>
                            </thead>
                        </table>
                        <!-- grid end -->
                    </div>
                </div>
            </div><!-- end panel main content -->
        </div>
    </div>

    <div class="col-xl-6">
        <div id="panel-2" class="panel">
            <div class="panel-hdr border-faded border-top-1 border-right-0 border-left-0 shadow-0">
                <h2>Data Kabupaten/Kota</h2>
                <div class="panel-toolbar pr-3">
                    <ul class="nav nav-pills border-bottom-0" role="tablist">
                        <li class="nav-item">
                            <?= form_button('reload', '<i class="fal fa-sync"></i>', 'reload_datagrid_kako()') ?>&nbsp;
                        </li>
                        <li class="nav-item">
                            <?= form_button('read', '<i class="fal fa-eye"></i>', 'show_kako()') ?>&nbsp;
                        </li>
                        <?php if ($rekam == 1) { ?>
                        <li class="nav-item">
                            <?= form_button('create', '<i class="fal fa-plus"></i>', 'new_kako()') ?>&nbsp;
                        </li>
                        <?php } ?>
                        <?php if ($ubah == 1) { ?>
                        <li class="nav-item">
                            <?= form_button('update', '<i class="fal fa-edit"></i>', 'edit_kako()') ?>&nbsp;
                        </li>
                        <?php } ?>
                        <?php if ($hapus == 1) { ?>
                        <li class="nav-item">
                            <?= form_button('delete', '<i class="fal fa-trash-alt"></i>', 'delete_kako()') ?>
                        </li>
                        <?php } ?>
                    </ul>
                </div>
            </div><!-- end panel hdr -->

            <div class="panel-container show">
                <div class="panel-content">
                    <div id="panelfit-2" data-options="border:false">
                        <!-- grid start -->
                        <table id="datagrid_kako" toolbar="#toolbar_kako" url="<?= site_url('referensi/pdkprov/datagrid_kako') ?>" data-options="nowrap:true,striped:false,ctrlSelect:true,rownumbers:true,pagination:true,multiSort:true,remoteFilter:true,remoteSort:true,pageSize:10,pageList:[10,20,50,100],clientPaging:false,fit:true" style="min-height: 300px;">
                            <thead data-options="frozen:true">
                                <tr>
                                    <th data-options="field:'ck',checkbox:true"></th>
                                </tr>
                            </thead>
                            <thead>
                                <tr>
                                    <th data-options="field:'nama_prov',sortable:true,width:200">Nama Provinsi</th>
                                    <th data-options="field:'nama_kako',sortable:true,width:200">Nama Kabupaten/Kota</th>
                                    <th data-options="field:'nama_alt',sortable:true,width:150">Nama Alt</th>
                                    <th data-options="field:'kode',sortable:true,align:'center',width:70">Kode</th>
                                </tr>
                            </thead>
                        </table>
                        <!-- grid end -->
                    </div>
                </div>
            </div><!-- end panel main content -->
        </div>
    </div>
</div>

<!-- MODAL MODUL -->
<div id="modal-prov" class="modal fade default-example-modal-left" data-backdrop="static" tabindex="-1" style="display: none;" aria-hidden="true">
    <div class="modal-dialog modal-dialog-left">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title h4" id="mod-ptitle"></h5>
            </div>
            
            <div id="form-konten-prov"></div>            
        </div>
    </div>
</div><!-- END MODAL MODUL -->

<!-- MODAL MENU -->
<div id="modal-kako" class="modal fade default-example-modal-right" data-backdrop="static" tabindex="-1" style="display: none;" aria-hidden="true">
    <div class="modal-dialog modal-dialog-right">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title h4" id="mod-ktitle"></h5>
            </div>
            
            <div id="form-konten-kako"></div>            
        </div>
    </div>
</div><!-- END MODAL MENU -->

<?= $this->endSection() ?>
<!-- main section end-->

<!-- pageScripts section start-->
<?= $this->section('pageScripts') ?>

<script type="text/javascript" src="<?= base_url('smart/dist/adlte/jquery-easyui-1.10.17/jquery.easyui.min.js') ?>"></script>
<script type="text/javascript" src="<?= base_url('smart/dist/adlte/jquery-easyui-1.10.17/datagrid-filter-1.0.6/datagrid-filter.js') ?>"></script>

<script type="text/javascript">
   $(document).ready(function () {
        adjustpanelfit();
    })

    $(window).resize(function() {
        adjustpanelfit();
    });

    function adjustpanelfit(){
        var height = $(window).height();
        $('#panelfit-1, #panelfit-2').panel({
            height:height - 520
        });
    }
</script>

<script type="text/javascript">
    /*datagrid modul =====================================*/
    var datagrid_prov = $('#datagrid_prov').datagrid({
        queryParams: {
            "<?= csrf_token() ?>": "<?= csrf_hash() ?>",
        },
        onDblClickRow : function(index,row){
            show_child();
        }
    });
    datagrid_prov.datagrid('enableFilter');

    /*reload datagrid modul*/
    function reload_datagrid_prov()
    {
        $('#datagrid_prov').datagrid('removeFilterRule');
        $('#datagrid_prov').datagrid('load');
    }

    function show_prov()
    {
        var row = $('#datagrid_prov').datagrid('getSelected');
        if (row) {
            var id_prov = row.id;
            $('#mod-ptitle').html('Detail Provinsi');
            $('#form-konten-prov').load('<?= base_url('referensi/pdkprov/show_prov/') ?>' + id_prov);
            $('#modal-prov').modal('show');
        } else {
            $.messager.alert('<?= lang('App.warning') ?>','<?= lang('App.select_data') ?>','warning');
        }
    }

    function show_kako()
    {
        var row = $('#datagrid_kako').datagrid('getSelected');
        if (row) {
            var id_kako = row.id;
            $('#mod-ktitle').html('Detail Kabupaten/Kota');
            $('#form-konten-kako').load('<?= base_url('referensi/pdkprov/show_kako/') ?>' + id_kako);
            $('#modal-kako').modal('show');
        } else {
            $.messager.alert('<?= lang('App.warning') ?>','<?= lang('App.select_data') ?>','warning');
        }
    }

    //double klik row prov tarik data kako
    function show_child()
    {
        var row = $('#datagrid_prov').datagrid('getSelected');
        if (row) {
            var id_prov = row.id;
            $.ajax({
                url: '<?= base_url('referensi/pdkprov/datagrid_kako') ?>',
                type: "post",
                dataType: 'json',
                data: {
                    id_prov: id_prov,
                    "<?= csrf_token() ?>": "<?= csrf_hash() ?>",
                },
                error: function (xhr, status, message) {
                    $.messager.alert(status,message,'warning');
                },
                success: function(res) {
                    $('#datagrid_kako').datagrid('loadData', res);
                }
            });
        } else {
          $.messager.alert('<?= lang('App.warning') ?>','<?= lang('App.select_data') ?>','warning');
        }
    }

    /*datagrid menu =====================================*/
    var datagrid_kako = $('#datagrid_kako').datagrid({
        queryParams: {
            "<?= csrf_token() ?>": "<?= csrf_hash() ?>",
        },
        onDblClickRow : function(index,row){
            show_menu();
        }
    });
    datagrid_kako.datagrid('enableFilter');

    /*reload datagrid menu*/
    function reload_datagrid_kako()
    {
        $('#datagrid_kako').datagrid('removeFilterRule');
        $('#datagrid_kako').datagrid('load');
    }   
</script>

<?php if ($rekam == 1) { ?>
<!-- FUNCTION REKAM -->
<script type="text/javascript">
    //tampilkan form rekam prov
    function new_prov()
    {
        $('#mod-ptitle').html('Rekam Provinsi');
        $('#form-konten-prov').load('<?= $link_rekam_prov ?>');
        $('#modal-prov').modal('show');
    }

    //tampilkan form rekam kako
    function new_kako()
    {
        $('#mod-ktitle').html('Rekam Kabupaten/Kota');
        $('#form-konten-kako').load('<?= $link_rekam_kako ?>');
        $('#modal-kako').modal('show');
    }
</script>
<?php } ?>

<?php if ($ubah == 1) { ?>
<!-- FUNCTION UBAH -->
<script type="text/javascript">
    //tampilkan form edit prov
    function edit_prov()
    {
        var row = $('#datagrid_prov').datagrid('getSelected');
        if (row) {
          var id_prov = row.id;
          $('#mod-ptitle').html('Edit Provinsi');
          $('#form-konten-prov').load('<?= $link_ubah_prov ?>' + id_prov);
          $('#modal-prov').modal('show');
        } else {
          $.messager.alert('<?= lang('App.warning') ?>','<?= lang('App.select_data') ?>','warning');
        }
    }

    //tampilkan form edit kako
    function edit_kako()
    {
        var row = $('#datagrid_kako').datagrid('getSelected');
        if (row) {
          var id_kako = row.id;
          $('#mod-ktitle').html('Edit Kabupaten/Kota');
          $('#form-konten-kako').load('<?= $link_ubah_kako ?>' + id_kako);
          $('#modal-kako').modal('show');
        } else {
          $.messager.alert('<?= lang('App.warning') ?>','<?= lang('App.select_data') ?>','warning');
        }
    }
</script>
<?php } ?>

<?php if ($hapus == 1) { ?>
<!-- FUNCTION HAPUS -->
<script type="text/javascript">
    //Hapus Modul
    function delete_prov()
    {
        var rows = $('#datagrid_prov').datagrid('getSelections');
        var ids = [];
        for(var j=0;j<rows.length;j++){
            ids[j] = rows[j].id;
        }
        if (ids.length > 0) {
            $.messager.confirm('<?= lang('App.delete') ?>', '<?= lang('App.delete') ?> ' + rows.length + ' data ?', function(r){
                if (r){
                    $.ajax({
                        url: '<?= $link_hapus_prov ?>',
                        type: "post",
                        dataType: 'json',
                        data: {
                            ids: ids,
                            "<?= csrf_token() ?>": "<?= csrf_hash() ?>",
                        },
                        error: function (xhr, status, message) {
                            $.messager.alert(status,message,'warning');
                        },
                        success: function(res) {
                            $('#datagrid_prov').datagrid('reload');
                            $('#datagrid_kako').datagrid('reload');
                            toastr.success(res.message, 'Updated!!', {timeOut: 3000});
                        }
                    });
                }
            });
        } else {
          $.messager.alert('<?= lang('App.warning') ?>','<?= lang('App.select_data') ?>','warning');
        }
    } //End Hapus Modul

    //Hapus Menu
    function delete_kako()
    {
        var rows = $('#datagrid_kako').datagrid('getSelections');
        var ids = [];
        for(var j=0;j<rows.length;j++){
            ids[j] = rows[j].id;
        }
        if (ids.length > 0) {
            $.messager.confirm('<?= lang('App.delete') ?>', '<?= lang('App.delete') ?> ' + rows.length + ' data ?', function(r){
                if (r){
                    $.ajax({
                        url: '<?= $link_hapus_kako ?>',
                        type: "post",
                        dataType: 'json',
                        data: {
                            ids: ids,
                            "<?= csrf_token() ?>": "<?= csrf_hash() ?>",
                        },
                        error: function (xhr, status, message) {
                            $.messager.alert(status,message,'warning');
                        },
                        success: function(res) {
                            $('#datagrid_kako').datagrid('reload');
                            toastr.success(res.message, 'Updated!!', {timeOut: 3000});
                        }
                    });
                }
            });
        } else {
          $.messager.alert('<?= lang('App.warning') ?>','<?= lang('App.select_data') ?>','warning');
        }
    } //End Hapus Menu
</script>
<?php } ?>

<?= $this->endSection() ?>
<!-- pageScripts section end-->