<div class="box-header">
        <h3 class="box-title"><span class="glyphicon glyphicon-th-large"></span>&nbsp;&nbsp;KELOLA USER (PENGGUNA) & ROLE (PERAN)</h3>
</div>
      <table id="dg" title="" class="easyui-datagrid" style="width:100%;"
            url="<?php echo base_url(); ?>adm/manuserdata";
            toolbar="#toolbarmanuser"
            rownumbers="true" fitColumns="true" striped="true" nowrap="false" singleSelect="true">
        <thead>
            <tr>
                <th field="id" width="5%" align="center">ID USER</th>
                <th field="username" width="15%">NAMA USER</th>				
                <th field="nama_lengkap" width="20%">NAMA LENGKAP</th>				
                <th field="email" width="15%">EMAIL</th>				
                <th field="no_telp" width="10%">NO TELEPON</th>				
                <th field="role" width="10%">ROLE</th>	
                <th field="unitkerja" width="25%">UNIT KERJA</th>	

            </tr>
        </thead>
    </table>

    <div id="toolbarmanuser">
        <a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="manusernew()">Menambah Pengguna / User</a>
        <a href="#" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="manuseredit()">Edit Pengguna / User</a>
        <a href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="manuserdestroy()">Hapus Data Pengguna</a>
    </div>
	
</div>	



	    <div id="dlg" class="easyui-dialog" style="width:600px;height:450px;padding:5px 5px"
            closed="true" buttons="#dlg-buttons">
        <div class="ftitle"></div>
        <form id="fmmanuser" method="post" novalidate>

            <div class="fitem">
            <input name="username" class="easyui-textbox" label="USERNAME:" labelPosition="left" multiline="false" 
			value="" style="width:90%;">
			</div>
		
            <div class="fitem">
            <input name="password" class="easyui-passwordbox" label="PASSWORD:" labelPosition="left" multiline="false" style="width:80%;" 
			value="" >
			</div>

            <div class="fitem">
            <input id="role"  name='role' class="easyui-combobox"  required="true" 
            data-options="
            label:'ROLE/PERAN',
             labelPosition:'left',
             width:'80%',
             panelHeight:'auto',
             valueField: 'role',
             textField: 'role',
             url: '<?php echo base_url(); ?>master/get_role'
         ">
         </div>



            <div class="fitem">
            <input name="nama_lengkap" class="easyui-textbox" label="NAMA PENGGUNA" labelPosition="left" multiline="false" style="width:70%;" 
			value="" >
			</div>

		<div class="fitem">
            <input name="email" class="easyui-textbox"  required="true" validType="email"  label="e-MAIL" labelPosition="left" multiline="false" style="width:80%;" 
			value="" >
			</div>
            <div class="fitem">
            <input name="no_telp" class="easyui-textbox" label="NO TELP" labelPosition="left" multiline="false" style="width:80%;" 
			value="" >
			</div>

            <div class="fitem">
            <input id="id_unitkerja"  name='id_unitkerja' class="easyui-combobox" data-options="
            label:'Unit Kerja',
             labelPosition:'left',
             width:'80%',
             valueField: 'id',
             textField: 'unitkerja',
             url: '<?php echo base_url(); ?>adm/get_unitkerja'
         ">
         </div>






         </div>


			
        </form>
    </div>

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



<script type="text/javascript">

$(document).ready(function(){
//    alert('aaaaa');
    checkForChanges();
	$(".sidebar-toggle").click(function(){
			checkForChanges();
    });
	

});    



		
		var url;
		function manusernew(){
			$('#dlg').dialog('open').dialog('setTitle','Entri baru');
			$('#fmmanuser').form('clear');
            url = "<?php echo base_url(); ?>adm/manusersimpan";
		}
		
		function manuseredit(){
			var row = $('#dg').datagrid('getSelected');
			if (row){
				$('#dlg').dialog('open').dialog('setTitle','Edit Entri');
				$('#fmmanuser').form('load',row);
				url = "<?php echo base_url(); ?>adm/manuserupdate/"+row.id;
			}
		}
			
		function manusersimpan(){
		
			$('#fmmanuser').form('submit',{
				url: url,
				onSubmit: function(param){
					return $(this).form('validate');
					},

				success: function(result){

					var result = eval('('+result+')');
					
					if (result.errorMsg){
                        alert(result.errorMsg);

//						$.messager.show({
//							title: 'Error',
//							msg: result.errorMsg
//					});

					} else {
						$('#dg').datagrid('reload');	// reload the user data
						alert(result.success);
						$('#dlg').dialog('close');		// close the dialog
					}
				}
                

			});

		}

		
		function manuserdestroy(){
			var row = $('#dg').datagrid('getSelected');
			if (row){
				var idd = row.id;
				$.messager.confirm('Confirm','Yakin akan menghapus baris ini?',function(r){
					if (r){
						$.post("<?php echo base_url(); ?>adm/manuserdestroy",{id:idd},function(result){
						if (result.success){
							$('#dg').datagrid('reload');	// reload the user data
							$('#dlg').dialog('close');		// close the dialog
							} else {
								$.messager.show({	// show error message
									title: 'Error',
									msg: result.errorMsg
								});
							}
						},'json');
					}
				});

			}
		}
		

</script>





<style>
	        .icon-add{
           background:url("<?php echo base_url(); ?>/assets/admin/plugins/jeasyui/themes/icons/edit_add.png") no-repeat center center;
        }
        .icon-edit{
           background:url("<?php echo base_url(); ?>/assets/admin/plugins/jeasyui/themes/icons/pencil.png") no-repeat center center;
        }
        .icon-remove{
           background:url("<?php echo base_url(); ?>/assets/admin/plugins/jeasyui/themes/icons/edit_remove.png") no-repeat center center;
        }
        
        .textbox-label { width:150px; }
</style>