<?php
$this->load->helper("url");
$d=array("tituloApp"=>"Citas","menu"=>"");

$this->parser->parse("html/page/v2/header",$d);
$this->parser->parse("html/page/v2/bar",$d);
$parse["menu"]=$this->load->view("html/page/v2/php/menuHClinica",$d,true);
$parse["tituloApp"]=!isset($tituloApp)?$d["tituloApp"]:$tituloApp;
$this->parser->parse("html/page/v2/navigation",$parse);
?>
<div class="row">
	<div class="col-md-12 col-lg-12">
		<div class="box box-primary">
			<div class="box-header">
				<button type="button" id="btnNueva" class="btn btn-success"><i class="fa fa-calendar fa-lg">&nbsp;</i>Nueva Cita</button>
    			<button type="button" class="btn btn-success" onclick="mostrarCalendario()">Calendario citas</button>
    		</div>
    		<div class="box-body">
    			<table id="listCita" class="table table-sm table-bordered table-striped dt-responsive table-hover table-active">
        			<thead class="thead-dark">
        				<tr>
        					<th>Asunto</th>
        					<th>Fecha-Hora Atención</th>
        					<th>Fecha de Alta</th>
        					<th>Situación</th>
        					<th>Acciones</th>
        				</tr>				
        			</thead>
        			<tbody>
        			</tbody>
        		</table>
    		</div>
		</div>
	</div>
</div>
<?php 
$this->load->view("html/page/v2/prefooter");?>
<script>
$(document).ready(function(){
	$("#btnNueva").click(function(){
		$(location).attr("href",path+"clinica/citaC/formCita");
	});

	var listCita=$("#listCita").DataTable({
		select : true,
		dom: "Bfrtip",
		buttons : ["New","List"],
		"createdRow": function ( row, data, index ) {
            /*if ( data[5].replace(/[\$,]/g, '') * 1 > 150000 ) {
                $('td', row).eq(5).addClass('highlight');
            }*/
            $('td', row).eq(2).addClass('text-primary');
            $('td', row).eq(2).click(function(){
                console.log(data[2]);
            });
        },
		"paging":true,
		"searching":true,
		"destroy":true,
		//"data":res.citas,
		"ajax":{
			"url":path+"clinica/citaC/getAllCitas",
			"method":"POST",
			"dataSrc":function(res){
        		return res.citas;
        	},"error":function(res){
  			  console.log(res.responseText);
    		}
		},
		"columns":[
			//editable:[[0,"asunto"]],
			{"data":"asunto","editable":true},
			{"data":"fechaAtencion"},
			{"data":"fechaAlta","searchable": false},
			{data:"situacion"},
			{data:function(data,row){
				//alert(row);
				var editarCita="editarCita('"+data.idCita+"')";
				return "<button title='Ver cita' onclick="+editarCita+" class='btn btn-sm btn-primary'><i class='fa fa-eye'></i></button> "+
				"<button class='btn btn-sm btn-danger cancelar-cita'><i class='fa fa-trash'></i></button>";
			}}
		]
	});

	//$("#listCita").Tabledit();
	/*$.ajax({url:path+"/clinica/citac/getAllCitas",
		data:{},
		method:"POST",
		dataType:"JSON",
		success:function(res){
			console.log(res);
			var listCita=$("#listCita").DataTable({
				"paging":true,
				"searching":true,
				"destroy":true,
				"data":res.citas,
				"columns":[
					{"data":"asunto"},
					{"data":"fechaAtencion"},
					{"data":"fechaAlta","searchable": false},
					{data:"situacion"},
					{data:function(data){
						var editarCita="editarCita('"+data.idCita+"')";
						return "<button onclick="+editarCita+" class='btn btn-warning'><i class='fa fa-pencil'></i></button> "+
						"<button class='btn btn-danger cancelar-cita'><i class='fa fa-trash'></i></button>";
					}}
				]
			});
	  },error:function(res){
		  console.log(res.responseText);
	  }});*/
});
function editarCita(id)
{
	$(location).attr("href",path+"clinica/citaC/formCita/"+id);
}
function mostrarCalendario()
{
	$(location).attr("href",path+"clinica/citaC/calendarioCitas");
}
</script>
<?php
$this->load->view("html/page/v2/footer");
?>