<script type="text/javascript">
	
	$(function() {		
		$('#datatable_blocklist').DataTable( {
			"pageLength": 25,
			initComplete: function () {	
				var $table = $(this);			
				var $filter = $table.parents('.dataTables_wrapper').find('.dataTables_filter');
				
				$filter.find('input[type="search"]').attr('id','search_input');
				
				
				this.api().columns(6).every( function () {				
					var column = this;
					var wrap = $('<label />',{ 'class': 'status_select' })
											.html('<span>Status:   </span>')
											.css('margin','0 20px 0 0')
											.prependTo( $filter );
					var select = $('<select id="select_status"><option value="">ALL</option></select>')
												.append( '<option value="1">Blocked</option>' )
												.append( '<option value="0">Active</option>' )
												.addClass('form-control input-sm')
												.appendTo( wrap )
												.on( 'change', function () {
														var val = $.fn.dataTable.util.escapeRegex( $(this).val() );
														column.search( val ? '^'+val+'$' : '', true, false ).draw();
												})
												.val(1)
												.change();
					
				});
				
			}
		});
	
	});
	
	function updatestatus(userID, me){
		
		$(me).find('i.fa').removeClass('fa-check').addClass('fa-spinner fa-spin');
	
		var status = $('input[name=validity_' + userID + ']:radio:checked').val();
		//if (confirm("Are you sure?")) {
			
			$.ajax({
				type: "POST",
				url: "<?php echo base_url(); ?>block/updatestatus",
				data: {
					'userID' : userID,
					'validity' : status
				},
				dataType:'json',
				success: function(data){
					if(data.status == 'success'){
						
						location.reload();
						
					}
				}
			 });
		
		 //}
    	//return false;
	
	}
	
	function printblock(){
		
		$('#print_btn').attr('href','javascript:void(0);');
		var status = $.trim($('#select_status').val());
				status = (status == "") ? 'all' : Number(status);
		
		var search = $.trim($('#search_input').val());				
				search = (search !== "") ? search.replace(' ','%20') : 'all';
		
		var url = "<?php echo base_url() ?>block/printBlock/"+status+"/" + search;
		
		$('#print_btn').attr('target','_blank');
		$('#print_btn').attr('href',url);
		return true;
	}
	
</script>
<style>
 
 	.modal-content{
    	border-top-left-radius: 2em;
		border-top-right-radius: 2em;
		border-bottom-left-radius: 2em;
		border-bottom-right-radius: 2em;
	}
	.modal-header{
		color:#F0F;
	}
	
</style>

