<div style="height:40px;">
<input type="hidden" id="id_sat" />
<table>
	<tr><td>KODE PEL SATUAN AS400</td><td>:</td><td><input id="kode_sat_coo" onkeyup="javascript:return cUpper(this);"/></td></tr>
	<tr><td>NAMA PEL SATUAN AS400</td><td>:</td><td><input id="nama_sat_coo"/></td></tr>
	<tr><td>KODE PEL SATUAN BC</td><td>:</td><td><input id="kdsat" onkeyup="javascript:return cUpper(this);" /></td></tr>
	<tr><td>NAMA PEL SATUAN BC</td><td>:</td><td><input id="nama_sat"/></td></tr>
</table>
<div><button id="coo_sat_new">NEW</button><button id="coo_sat_save">SAVE</button><button id="coo_sat_del">DELETE</button></div>
<table id="tbl_data_coo_sat"></table> <div id="ptbl_data_coo_sat"></div>   	
</div>
<script type="text/javascript">
    function cUpper(cObj)
	{
		cObj.value=cObj.value.toUpperCase();
	}	
    $(document).ready(function(){
		jQuery("#tbl_data_coo_sat").jqGrid({
			url:'<?php echo base_url().'exim/ct_upload_coo/tbl_coo_sat'; ?>',
			mtype : "post",
			postData:{'q':'1'},
			datatype: "json",
			colNames:['ID','Kode AS400', 'NAMA AS400','KODE BC','NAMA BC'],
			colModel:[
				{name:'id_sat',index:'id_sat', width:60, hidden:true},
				{name:'kode_sat_coo',index:'kode_sat_coo', width:120},
				{name:'nama_sat_coo',index:'nama_sat_coo', width:160},
				{name:'kdsat',index:'kdsat', width:99},
				{name:'nama_sat',index:'nama_sat', width:160}
			
				],
			rowNum:20,
			rowList:[20,50100],
			pager: '#ptbl_data_coo_sat',
			sortname: 'id_sat',
			viewrecords: true,
			sortorder: "desc",
			width: '',
			height:200,
			jsonReader: { repeatitems : false },
			caption:"DATA sat COO",
			rownumbers: true,
			shrinkToFit: false,
			afterInsertRow: function(){
				
				
			},			
			gridComplete: function(){
				var rowIDs = jQuery("#tbl_data_coo_sat").getDataIDs(); 
				var rowData = $("#tbl_data_coo_sat").getRowData();
			
				
			},
			onSelectRow: function(ids) {
				var ret = jQuery("#tbl_data_coo_sat").jqGrid('getRowData',ids);
				$("#id_sat").val(ret.id_sat);
				$("#kode_sat_coo").val(ret.kode_sat_coo);
				$("#nama_sat_coo").val(ret.nama_sat_coo);
				$("#kdsat").val(ret.kdsat);
				$("#nama_sat").val(ret.nama_sat);
			}	
		}); 
		
		jQuery("#tbl_data_coo_sat").jqGrid('navGrid','#ptbl_data_coo_sat',{del:false,add:false,edit:false},{},{},{},{multipleSearch:false});
		jQuery("#tbl_data_coo_sat").jqGrid('filterToolbar',{stringResult: true,searchOnEnter : false, defaultSearch: 'cn', ignoreCase: true});
		
		$("#coo_sat_new").click(function(){
			$("#id_sat").val("");
			$("#kode_sat_coo").val("");
			$("#nama_sat_coo").val("");
			$("#kdsat").val("");
			$("#nama_sat").val("");
			jQuery("#tbl_data_coo_sat").jqGrid('resetSelection');
			$("#kode_sat_coo").focus();
		});
		
		$("#coo_sat_save").click(function(){
			if($("#id_sat").val() != ''){
				var upd = " UPDATE ";
			} else {
				var upd = " PENAMBAHAN ";
			}
			var form_data  = {
				id_sat:$("#id_sat").val(),
				kode_sat_coo:$("#kode_sat_coo").val(),
				nama_sat_coo:$("#nama_sat_coo").val(),
				kdsat:$("#kdsat").val(),
				nama_sat:$("#nama_sat").val(),
			}
			$("#dlgcoo_sat").dialog( "destroy" );
			$(".dlgcoo_satcl").remove();
			$(".dlgcoo_satcl").html('');
			$("body").append('<div id="dlgcoo_sat" title="Warning" class="dlgcoo_satcl"><p>Apakah anda akan melakukan' +  upd + ' DATA sat?</p><br /></div>');
			$("#dlgcoo_sat").dialog({
				height: 200,
				width: 350,
				modal: true,
				hide: 'Slide',
				autoOpen: 'false',
				buttons: {
					"CONFIRM": function() {
					$.ajax({
						url :'<?php echo base_url().'exim/ct_upload_coo/update_coo_sat'; ?>',
						type : 'POST',
						dataType: 'json',
						data : form_data,
						success: function(msg){
							if (msg.sts == '00'){
								alert(msg.desc);
								$("#dlgcoo_sat").dialog("close");
								$('#dlgcoo_sat').dialog("destroy"); 
								$(".dlgcoo_satcl").remove(); 
								$('#tbl_data_coo_sat').trigger('reloadGrid');
							} else { 
								alert(msg.sts+msg.desc);
								$("#dlgcoo_sat").dialog("close");
								$('#dlgcoo_sat').dialog("destroy"); 
								$(".dlgcoo_satcl").remove(); 		

							}
						}
					});
				},
				"CANCEL": function() {
						$( "#dlgcoo_sat" ).dialog( "close" );

					}
				},
				close : function(){
					$('#dlgcoo_sat').dialog("destroy"); 
					$(".dlgcoo_satcl").remove(); 
					$("body").append('<div id="dlgcoo_sat" title="Warning" class="dlgcoo_satcl"><p>Apakah anda akan Memproses Data ini Menjadi Data BC23?</p></div>');     
					
				},
				open: function(){
					$("body").unblock();
					
				}
			});
			
			
		});
		
		$("#coo_sat_del").click(function(){
			
			if($("#id_sat").val() != ''){
				var upd = " DELETE ";
			} else {
				alert("ID TIDAK BOLEH KOSONG, PILIH DAHULU DATANYA");
				return false;
			}
			var form_data  = {
				id_sat:$("#id_sat").val()
			}
			$("#dlgcoo_sat_del").dialog( "destroy" );
			$(".dlgcoo_sat_delcl").remove();
			$(".dlgcoo_sat_delcl").html('');
			$("body").append('<div id="dlgcoo_sat_del" title="Warning" class="dlgcoo_sat_delcl"><p>Apakah anda akan melakukan' +  upd + ' DATA sat?</p><br /></div>');
			$("#dlgcoo_sat_del").dialog({
				height: 200,
				width: 350,
				modal: true,
				hide: 'Slide',
				autoOpen: 'false',
				buttons: {
					"CONFIRM": function() {
					$.ajax({
						url :'<?php echo base_url().'exim/ct_upload_coo/coo_sat_del'; ?>',
						type : 'POST',
						dataType: 'json',
						data : form_data,
						success: function(msg){
							if (msg.sts == '00'){
								alert(msg.desc);
								$("#dlgcoo_sat_del").dialog("close");
								$('#dlgcoo_sat_del').dialog("destroy"); 
								$(".dlgcoo_sat_delcl").remove(); 
								$('#tbl_data_coo_sat').trigger('reloadGrid');
							} else { 
								alert(msg.sts+msg.desc);
								$("#dlgcoo_sat_del").dialog("close");
								$('#dlgcoo_sat_del').dialog("destroy"); 
								$(".dlgcoo_sat_delcl").remove(); 		

							}
						}
					});
				},
				"CANCEL": function() {
						$( "#dlgcoo_sat_del" ).dialog( "close" );

					}
				},
				close : function(){
					$('#dlgcoo_sat_del').dialog("destroy"); 
					$(".dlgcoo_sat_delcl").remove(); 
					$("body").append('<div id="dlgcoo_sat_del" title="Warning" class="dlgcoo_sat_delcl"><p>Apakah anda akan Memproses Data ini Menjadi Data BC23?</p></div>');     
					
				},
				open: function(){
					$("body").unblock();
					
				}
			});
		
		});

	});
		  	
</script>



	
	