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

<?= $this->section('title') ?>Data Nasabah - <?= 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">Potensi Wilayah</li>
    <li class="breadcrumb-item">Data Nasabah</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-12">
        <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 Nasabah</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()') ?>&nbsp;
                        </li>
                        <li class="nav-item">
                            <?= form_button('read', '<i class="fal fa-eye"></i>', 'show_data()') ?>&nbsp;
                        </li>
                        <?php if ($ubah == 1) { ?>
                        <li class="nav-item">
                            <?= form_button('update', '<i class="fal fa-edit"></i>', 'edit_data()') ?>&nbsp;
                        </li>
                        <?php } ?>
                        <?php if ($hapus == 1) { ?>
                        <li class="nav-item">
                            <?= form_button('delete', '<i class="fal fa-trash-alt"></i>', 'delete_data()') ?>
                        </li>
                        <?php } ?>
                    </ul>
                </div><!-- end toolbar -->
            </div><!-- end panel hdr -->

            <div class="panel-container show">
                <div class="panel-content">
                    <div id="panelfit" data-options="border:false">
                        <!-- grid start -->
                        <table id="datagrid" toolbar="#toolbar" url="<?= site_url('potensiwilayah/datanasabah/datagrid') ?>" 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_calon',sortable:true">Nama Nasabah</th>
                                    <th data-options="field:'no_cif',sortable:true,width:100,align:'center'">No CIF</th>
                                    <th data-options="field:'nik',sortable:true,width:150,align:'center'">NIK</th>
                                    <th data-options="field:'tgl_lahir',sortable:true,width:100,align:'center'">Tgl Lahir</th>
                                    <th data-options="field:'emailx',sortable:true,width:150">Email</th>
                                    <th data-options="field:'no_wa',sortable:true,width:100">No WA</th>
                                    <th data-options="field:'tgl_closing',sortable:true,width:100,align:'center'">Tgl Closing</th>
                                    <th data-options="field:'nama_giat',sortable:true">Nama Kegiatan</th>
                                    <th data-options="field:'nama_lokasi',sortable:true">Nama Lokasi</th>
                                    <th data-options="field:'username',sortable:true,width:120">Direkam Oleh</th>
                                    <th data-options="field:'username_closing',sortable:true,width:120">Closing Oleh</th>
                                    <th data-options="field:'wkt_clo',sortable:true,width:150,align:'center'">Waktu Closing</th>
                                </tr>
                            </thead>
                        </table>
                        <!-- grid end -->
                    </div><!-- end panel fit -->
                </div><!-- end panel content -->
            </div><!-- end panel container -->
        </div><!-- end panel 1 -->
    </div><!-- end col-xl-6 -->
</div><!-- end row -->
<?= $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').panel({
            height:height - 520
        });
    }
</script>

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

/*reload datagrid nasabah*/
function reload_datagrid()
{
    $('#datagrid').datagrid('removeFilterRule');
    $('#datagrid').datagrid('load');
}

function show_data()
{
    var row = $('#datagrid').datagrid('getSelected');
    if (row) {
        var id = row.id;
        window.location.href = '<?= $link_show ?>' + id;
    } else {
        $.messager.alert('<?= lang('App.warning') ?>','<?= lang('App.select_data') ?>','warning');
    }
}
</script>

<script type="text/javascript">
<?php if ($ubah == 1) { ?>
//FUNCTION EDIT
function edit_data()
{
    var row = $('#datagrid').datagrid('getSelected');
    if (row) {
      var id = row.id;
      window.location.href = '<?= $link_ubah ?>' + id;
    } else {
      $.messager.alert('<?= lang('App.warning') ?>','<?= lang('App.select_data') ?>','warning');
    }
}
<?php } ?>
</script>

<script type="text/javascript">
<?php if ($hapus == 1) { ?>
//FUNCTION HAPUS
function delete_data()
{
    var rows = $('#datagrid').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 ?>',
                    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').datagrid('reload');
                        manualx();
                        toastr.success(res.message, 'Updated!!', {timeOut: 3000});
                    }
                });
            }
        });
    } else {
      $.messager.alert('<?= lang('App.warning') ?>','<?= lang('App.select_data') ?>','warning');
    }
}
</script>
<?php } ?>
<?= $this->endSection() ?>
<!-- pageScripts section end-->
