<script type="text/javascript">  
theight=$( document ).height()-50; 
function setdg(){
	$('#dg').datagrid({ 
		height:theight,
		striped:true,
		toolbar:"#toolbar",
		fit:true,
		fitColumns:false,
		singleSelect:true,
		rownumbers:true,		
		pagination:true,
		pageSize:100,
		pageList:[100,200,300,400,500],
		columns:[[  
			{field:'id',width:100,hidden:true},
			{field:'code_group_user',width:100,hidden:true},
			{field:'nama_user',title:'Username'},
			{field:'pass',title:'Password'},
			{field:'name_group_user',title:'User Group'},
			{field:'access_rights',title:'Hak Akses',align:'center',
				formatter:function(value,row,index){
					var det = '<a href="<?php echo base_url() . 'user/hakakses/'; ?>'+row.code_group_user+'/'+row.id+'" class="easyui-linkbutton" iconCls="icon-edit" plain="true">Ubah</a>';
					return det;
				}
			}
			// {field:'NmPrshn',title:'Company',width:600}
		]],
		onBeforeLoad: function (data) {
		  var panel = $(this).datagrid("getPanel");
		  // here is to add the css style
		  panel.css("border","0");
		},
		url: '<?=site_url($this->modul)?>/getPage'
	});
}

function cari(q){
	$('#dg').datagrid({
		queryParams:{q:q}		
	});
}

var url;
function tambah(){
	$('#dlg').dialog('open').dialog('setTitle','Tambah <?=$title?>');
	$('#fm').form('clear');
	$("[name=kd_jns_kelamin]").val(["L"]);
	url = '<?=site_url($this->modul)?>/getform/add';
}

function ubah(){
	var row = $('#dg').datagrid('getSelected');
	$('#empl_id').combogrid({  
		editable:false  
    });  
	if (row){
		$('#dlg').dialog('open').dialog('setTitle','Ubah <?=$title?>');
		$('#fm').form('load',row);
		url = '<?=site_url($this->modul)?>/getform/edit';
	}
}

function simpan(){
	$('#fm').form('submit',{
		url: url,
		onSubmit: function(){				
			return $(this).form('validate');
		},
		success: function(result){
			//alert(result);
			var result = eval('('+result+')');
			if (result.success){
				$('#dlg').dialog('close');		// close the dialog
				$('#dg').datagrid('reload');	// reload the operator data
				$.messager.show({
					title: 'Info',
					msg: result.msg
				});
			} else {
				$.messager.show({
					title: 'Error',
					msg: result.msg
				});
			}
		}
	});
}

function validasi(strings){
	var i=0;
	var ch='';
	
	num=0;
	ucase=0;
	lcase=0;
	while (i <= strings.length){
		character = strings.charAt(i);
		if (!isNaN(character * 1)){
			num=1;
		}else{
			if (character == character.toUpperCase()) {
				ucase=1;
			}
			if (character == character.toLowerCase()){
				lcase=1;
			}
		}
		i++;
	}
	if (num==0 || ucase==0 || lcase==0){ 
		return false; 
	} else {
		return true;
	}
}

function hapus(){
	var row = $('#dg').datagrid('getSelected');
	if (row){
		$.messager.confirm('Confirm','Apakah anda yakin akan menghapus data ini?',function(r){
			if (r){
				$.post('<?=site_url($this->modul)?>/del',{id:row.id},function(result){
					var result = eval('('+result+')');
					if (result.success){
						$('#dg').datagrid('reload');	// reload the operator data
						$.messager.show({
							title: 'Info',
							msg: result.msg
						});
					} else {
						$.messager.show({	// show error message
							title: 'Error',
							msg: result.msg
						});
					}
				});
			}
		});
	}
}

function aksi(cmd){
	var opts = $('#dg').datagrid('options');
	q=$("#q").val();
	//alert(cmd);
	if (cmd=='print'){
		var win = window.open('<?=site_url($this->modul)?>/aksi/'+cmd+'?q='+q+'&page='+opts.pageNumber+'&rows='+opts.pageSize,'Popup','toolbar=no, location=no,status=no,menubar=no,scrollbars=yes,resizable=no');
		win.print();
	} else {
		openurl('<?=site_url($this->modul)?>/aksi/'+cmd+'?'+
		'q='+q+'&'+
		'page='+opts.pageNumber+'&'+
		'rows='+opts.pageSize);
	}
}

</script>