<div style="height:40px;">
	<button id="btnuploadbc25" >Upload bc25</button><button id="btndeletebc25" >Delete bc25</button>
</div>
<table id="tbluploadbc25"></table> <div id="ptbluploadbc25"></div>   
<script type="text/javascript">
    
    $(document).ready(function(){
		$("#btnuploadbc25").button().click(function(){
			$("#frmuploadbc25dlg").load('<?php echo base_url().'exim/ct_upload/view_bc25_upload_frm'; ?>',  {parmeter:'parameter'}, function() {
				$("#frmuploadbc25dlg").dialog({
					modal:true,
					width : 530,
					height : 230,
					buttons: {
						"Close": function() {  
							$(".ui-dialog-titlebar-close").trigger('click');  
							
						}
					},
					close : function(){
						$('#frmuploadbc25dlg').dialog("destroy"); 
						$(".frmuploadbc25dlg_cl").remove(); 
						$("body").append('<div id="frmuploadbc25dlg" title="UPLOAD FILE BC25" class="frmuploadbc25dlg_cl"></div>'); 
						jQuery("#tbluploadbc25").trigger('reloadGrid');

					},
					open: function(){
						$("body").unblock();
						
					}
				});
		
			});
		});
		
		$("#btndeletebc25").button().click(function(){
			var id = jQuery("#tbluploadbc25").jqGrid('getGridParam','selrow');
			if (id) { 
				var ret = jQuery("#tbluploadbc25").jqGrid('getRowData',id);
				
			} else {
				alert("Please Select Row");
				return false;
			};	
			var form_data = {
				id_bc25_upload:ret.id_bc25_upload,
				filename:ret.filename,
				tipe:ret.tipe
			
			};
			
			$("#dlgdeletefilebc25").dialog( "destroy" );
			$(".dlgdeletefilebc25cl").remove();
			$(".dlgdeletefilebc25cl").html('');
			$("body").append('<div id="dlgdeletefilebc25" title="Warning" class="dlgdeletefilebc25cl"><p>Apakah anda akan mendelete file ini?!?</p><br /> file = '+ ret.filename +'</div>');
			$("#dlgdeletefilebc25").dialog({
				height: 200,
				width: 250,
				modal: true,
				hide: 'Slide',
				autoOpen: 'false',
				buttons: {
					"CONFIRM": function() {
					$.ajax({
						url : "<?php echo base_url().'exim/ct_upload/deletefile_bc25'; ?>",
						type : 'POST',
						dataType: 'json',
						data : form_data,
						success: function(msg){
							if (msg.sts == '00'){
								alert(msg.desc);
								$("#dlgdeletefilebc25").dialog("close");
								$('#dlgdeletefilebc25').dialog("destroy"); 
								$(".dlgdeletefilebc25cl").remove(); 
								$('#tbluploadbc25').trigger('reloadGrid');
							} else { 
								alert(msg.sts+' '+msg.desc); 
								$("#dlgdeletefilebc25").dialog("close");
								$('#dlgdeletefilebc25').dialog("destroy"); 
								$(".dlgdeletefilebc25cl").remove(); 

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

					}
				},
				close : function(){
					$('#dlgdeletefilebc25').dialog("destroy"); 
					$(".dlgdeletefilebc25cl").remove(); 
					$("body").append('<div id="dlgdeletefilebc25" title="Warning" class="dlgdeletefilebc25cl"><p>Apakah anda akan mendelete file ini?!?</p></div>');     
					
				},
				open: function(){
					$("body").unblock();
					
				}
			});
		
		});
		
		var datePick = function (el) {
			$(el).datepicker({
				changeYear: true,
				changeMonth: true,
				showButtonPanel: true,
				onSelect: function () {
					
					if (this.id.substr(0, 3) === "gs_") {
                // in case of searching toolbar
					setTimeout(function(){
					jQuery("#tbluploadbc25").jqGrid()[0].triggerToolbar();
						}, 50);
					} else {
						// refresh the filter in case of
						// searching dialog
						$(this).trigger('change');
					}
				}    
			});
		};
		
		jQuery("#tbluploadbc25").jqGrid({
			url:'<?php echo base_url().'exim/ct_upload/data_uploadbc25'; ?>',
			mtype : "post",
			postData:{'q':'1'},
			datatype: "json",
			colNames:['ID','filename', 'date upload','status upload', 'tipe', 'create date', 'create by'],
			colModel:[
				{name:'id_bc25_upload',index:'id_bc25_upload', width:60, hidden:true},
				{name:'filename',index:'filename', width:160},
				{name:'date_upload',index:'date_upload', width:166,stype:"text",searchoptions:{dataInit:datePick, att:{title:'Select Date'}}},
				{name:'status_upload',index:'status_upload', width:106},
				{name:'tipe',index:'tipe', width:106},
				{name:'create_date',index:'create_date', width:166, hidden:false,stype:"text",searchoptions:{dataInit:datePick, att:{title:'Select Date'}}},
				{name:'create_by',index:'create_by', width:106, hidden:false},
			
				],
			rowNum:10,
			rowList:[10,20,30],
			pager: '#ptbluploadbc25',
			sortname: 'id_bc25_upload',
			viewrecords: true,
			sortorder: "desc",
			width: 960,
			height:300,
			jsonReader: { repeatitems : false },
			caption:"List of Files Upload",
			rownumbers: true,
			shrinkToFit: false,
			afterInsertRow: function(){
				
				
			},			
			gridComplete: function(){
				var rowIDs = jQuery("#tbluploadbc25").getDataIDs(); 
				var rowData = $("#tbluploadbc25").getRowData();
			
				for (var i = 0; i < rowData.length; i++) 
				{
				   var trElement = jQuery("#"+ rowIDs[i],jQuery('#tbluploadbc25'));
				   
					switch (rowData[i].status_upload) {
						
						case 'cancel':
						   trElement.css({"color":"green"});
						break;
						case 'Deleted':
						   trElement.css({"color":"red", "text-decoration": "line-through"});
						break;
						case 'DATA PROCESSED':
						   trElement.css({"color":"blue"});
						break;
						
						
					}
				}
			},
		}); 
		
		jQuery("#tbluploadbc25").jqGrid('navGrid','#ptbluploadbc25',{del:false,add:false,edit:false},{},{},{},{multipleSearch:false});
		jQuery("#tbluploadbc25").jqGrid('filterToolbar',{stringResult: true,searchOnEnter : false, defaultSearch: 'cn', ignoreCase: true});
		

	});
		  	
</script>

<div id="frmuploadbc25dlg" title="UPLOAD FILE BC 25" class="frmuploadbc25dlg_cl"></div>



	
	