<?php $this->load->view('partials/script_list.php'); ?>
    
<?php
    $this->load->view('partials/delete_modal.php');
?>

<div id="page-title" class="clearfix">

    <span style="font-size:24px;font-weight:bold;float:left;margin-top:5px;"><?php echo $nom; ?></span>

    <div class="item-content" style="float:right;">

        <button class="btn btn-inverse" id="nuevo">Nuevo</button>

        <a href="#myModal" data-toggle="modal" class="btn btn-inverse">Eliminar</a>

        <button class="btn btn-inverse" id="restore">Restaurar</button>

		<div style="float:right" id="import_result_box"></div>
		
		<form style="float:right" class="ajax-form" id="import_form" action="<?=base_url('/admin/pacientes/upload')?>" method="post" enctype="multipart/form-data">
			<input id="fileupload" class="hidden" type="file" name="files[]" value="" />
			
			<button id="file_select" style="margin-left: 4px" class="btn btn-inverse" value="submit">Importar</button>
		</form>
    </div>

</div>

<div class="row">
    <div class="span12">
        <div class="widget widget-table">
            <div class="widget-content">
                <div id="example_wrapper" class="dataTables_wrapper form-inline" role="grid">

                    <?php /* if(isset($message)) echo $message; */ ?>

                    <div class="row">

                        <?php
                            $this->load->view('partials/table_perpage.php');
                            $this->load->view('partials/search.php');
                        ?>

                    </div>

                    <?php
                    	$this->load->view('partials/table.php');
                        $this->load->view('partials/table_footer.php');
                    ?>

                </div>
            </div>
        </div>
    </div>
</div>

<div id="upload-loader" class="fs-loader">
	<div class="loading-spinner-image"></div>
</div>

<script type="text/javascript">
	function file_select_click( el )
	{
		$('#fileupload').click();
	}
	
	function file_uploaded( e, data )
	{
		$('#import_form').hide();
		$('#import_result_box').show();
		
		$.each(data.result.files, function (index, file)
		{
			if ( 'error' in file )
			{
				$('#progress').addClass( 'incomplete' );
				$('#import_result_box').html( file['error'] );
			}
			else
			{
				$('#import_result_box').html( file['result'] );
				
				window.location.reload(false);
			}
		});
		
		$('#upload-loader').hide();
	}
	
	function file_upload_start( e )
	{
		$('#upload-loader').show();
	}
	
	$(function()
	{
		kajax_bind_click( $('#file_select'), file_select_click );
		
		$("#fileupload").change(function()
		{
			$('#form_file_selected').text( $("#fileupload").val().replace(/^.*(\\|\/|\:)/, '') );
		});
		
		file_upload_init( $('#fileupload'), $('#import_form').attr('action'), file_uploaded, file_upload_start );
	})
</script>