<?php echo $this->extend('/template'); ?>
<?php echo $this->section('content') ?>

<head>
    <title>DAFTAR KORLAP</title>

</head>
<div class="rows">
    <div class="col-sm-7">
        <h3>
            <img src="<?php echo base_url(); ?>/assets/images/pemprovsmr/header_icon.png" width="35px">&nbsp;<b>DAFTAR KORLAP
            </b>
        </h3>
    </div>
    <div class="col-sm-5">
        <div id="rekap" style="text-align:right">REKAPITULASI</div>
    </div>
</div>


<table id="dg" title="KELOLA KORLAP" class="easyui-datagrid" style="width:100%;height:auto" url="/korlap_data" toolbar="#toolbar" rownumbers="true" fitColumns="true" singleSelect="true" data-options="
                queryParams: {'<?php echo csrf_token() ?>': '<?php echo csrf_hash() ?>'},
        ">
    <thead>
        <tr>
            <th field="nama" width="30">NAMA korlap</th>
            <th field="nowa" width="30" >NOMOR TELP/WA</th>
            <th field="statust" width="20" align="center">STATUS</th>
            <th field="aksi" width="20" align="center">AKSI</th>
        </tr>
    </thead>
</table>
<div id="toolbar">
    <a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="korlap_baru()">Tambah Korlap</a>
</div>

<div id="dlg" class="easyui-dialog" modal="true" style="width:500px;height:300px;padding:10px 20px" closed="true" buttons="#dlg-buttons">

    <form id="fm" method="post" enctype="multipart/form-data">
        <div class="fitem">
            <input name="nama" id="nama" style="width:100%;" label="Nama korlap" labelWidth="110px" labelPosition="left" class="easyui-textbox">
        </div>
        <div class="fitem">
            <input name="nowa" id="nowa" labelPosition="left" label="Nomor WA" class="easyui-textbox" labelWidth="110px" style="width:70%">
        </div>

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


<div id="dlg-buttons">
    <a href="javascript:void(0)" class="easyui-linkbutton c6" iconCls="icon-ok" onclick="korlap_simpan()" style="width:90px">Simpan</a>
    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')" style="width:90px">Cancel</a>
</div>

</div>



<script>
    $(document).ready(function() {

    });

    function korlap_baru() {
        $('#dlg').dialog('open').dialog('setTitle', 'Menambah korlap Baru');
        $('#fm').form('clear');
        url = '/korlap_simpan';
    }

    function korlap_edit(id) {
        $.ajax({
            type: 'post',
            url: "/korlapeditdata",
            data: {
                id: id,
                "<?= csrf_token() ?>": "<?= csrf_hash() ?>"

            },
            success: function(data) {
                var respon = $.parseJSON(data);
                $('#dlg').dialog('open').dialog('setTitle', 'Edit korlap');
                $('#fm').form('clear');
                $('#fm').form('load', respon);
                //id exdokumen diganti jika ada filenya 
                url = "/korlap_update/" + id;
            }

        });

    }

    function korlap_simpan() {
        $('#fm').form('submit', {
            url: url,
            onSubmit: function(param) {
                param.csrftoken_erb2021 = '<?= csrf_hash() ?>';
                return $(this).form('validate');
            },

            success: function(result) {
                var respon = $.parseJSON(result);

                if (respon.success !== true) {
                    alert(respon.pesan);
                } else {
                    $('#dg').datagrid('reload'); // reload the user data
                    $('#dlg').dialog('close'); // close the dialog
                    //alert('Penyimpanan Berhasil');
                    $('#dlg').dialog('close'); // close the dialog
                }
            }
        });

    }

    function korlap_destroy(id) {
        $.messager.confirm('Confirm', 'Yakin akan menghapus Data ini. Jika ya maka Data ini akan dihapus secara permanen?', function(r) {
            if (r) {
                $.ajax({
                    type: 'post',
                    url: "<?php echo base_url(); ?>/korlap_destroy",
                    data: {
                        id: id,
                        "<?= csrf_token() ?>": "<?= csrf_hash() ?>"
                    },
                    success: function(data) {
                        var respon = $.parseJSON(data);
                        console.log(respon);
                        if (respon.code == 1)
                            $('#dg').datagrid('reload');
                    },
                    error: function() {
                        alert('Tidak Dapat Dihapus karena korlap sudah di Ada yang memesan');
                    }

                });
            }
        });
    }


    function korlap_status(id, st) {
        $.ajax({
            type: 'post',
            url: "/korlap_status",
            data: {
                id: id,
                st: st,
                "<?= csrf_token() ?>": "<?= csrf_hash() ?>"

            },
            success: function(data) {
                $('#dg').datagrid('reload');
            }

        });

    }
</script>

<script>
      $(function() {
        var dg = $('#dg').datagrid();
        dg.datagrid('enableFilter', [{
                field: 'nama',
                type: 'textbox'
            },{
                field:'nowa', type:'textbox'
            },{
                field:'aksi', type:'label'
            } 

            ]);
    });

</script>

<?php echo $this->endSection() ?>