<?php helper('form'); ?>

<table id="dglain" class="easyui-datagrid" title="Dokumen2 Data Dukung lain" style="width:100%;height:auto" toolbar="#toolbarlain" data-options="singleSelect:true,collapsible:true,rownumbers:true,fitColumns:true,url:'/doklain_data/<?php echo $user_id; ?>',method:'get'">
    <thead>
        <tr>
            <th data-options="field:'deskripsi',width:650,align:'left'">KETERANGAN</th>
            <th data-options="field:'linkfile',width:300,align:'center'">DATA DUKUNG</th>
        </tr>
    </thead>
</table>

<div id="toolbarlain">
    <?php if(in_array($role,array('admin','pegawai')) && $beda == 0) { ?>
    <a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="newlain()">Tambah Data</a>
    <a href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="hapuslain()">Hapus Data</a>
<?php } ?>
</div>

<div id="dlglain" class="easyui-dialog" style="width:400px;height:280px;padding:10px 20px" closed="true" buttons="#dlglain-buttons">
    <?php
    $attributes = array('id' => 'fmlain', 'class' => 'form-horizontal', 'role' => 'form');
    echo form_open_multipart('upload_lain', $attributes);
    ?>
    <div class="fitem">
        <label>Deskripsi:</label>
        <input name="deskripsi" class="easyui-textbox" required="true">
    </div>
    <div class="fitem">
        <label>Data Dukung:</label>
        <input type="file" name="filelain">
    </div>
    </form>
</div>

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


<div id="lainv" class="easyui-window" title=" " data-options="modal:false,closed:true" style="width:1000px;height:600px;padding:5px;">

</div>
    
    <!--
<div id="lainv" class="easyui-window" title=" " data-options="modal:true,closed:true" style="width:800px;height:auto;padding:5px;">
    <?php if (isset($data['sklantik_photo'])) { ?>
        <iframe width="100%" height="100%" style="border:0px;" src="<?php echo base_url(); ?>/assets/images/bawaslu/profile/<?php echo $data['sklantik_photo']; ?>"></iframe>
    <?php } ?>
</div>
    -->



<script>
    function newlain() {
        $('#dlglain').dialog('open').dialog('setTitle', 'Data Baru');
        $('#fmlain').form('clear');
        url = '/simpanlain';
    }




    function hapuslain() {

        var row = $('#dglain').datagrid('getSelected');
        if (row) {
            $.messager.confirm('Confirm', 'Yakin akan menghapus baris data ini?', function(r) {
                if (r) {
                    $.post('/hapuslain', {
                            id: row.id,
                            csrftoken_erb2021: '<?= csrf_hash() ?>'
                        },
                        function(result) {
                            if (result.success) {
                                $('#dglain').datagrid('reload'); // reload the user data
                            } else {
                                $.messager.show({ // show error message
                                    title: 'Error',
                                    msg: result.errorMsg
                                });
                            }
                        }, 'json');
                }
            });
        }

    }

    function lainview(ff) {
        $('#lainv').window('refresh', '/lainv/' + ff);
//        $('#lainv').window('fixed');
        $('#lainv').window('open');
    }



    function simpan_lain() {
        $('#fmlain').form('submit', {
            url: url,
            onSubmit: function(param) {
                param.csrftoken_erb2021 = '<?= csrf_hash() ?>';
                param.user_id = '<?php echo $user_id; ?>';
                return $(this).form('validate');
            },
            success: function(result) {
                if (result.errorMsg) {
                    alert(result.errorMsg);
                } else {
                    $('#dlglain').dialog('close');
                    $('#dglain').datagrid('reload');
                }
            }
        });

    }
</script>