{% extends 'template.html' %}
{% block subcontent %}
<div>
	<h2>List Kunjungan: <input type="text" id="date_picker" value="{{tgl}}">
		Cari: <input type="text" id="find"/>
	</h2>

	{% if data.length > 0 %}
	<table class="orderhistory data">
		<tr>
			<th>Antrian</th>
			<th>Jam</th>
			<th>No. RM</th>
			<th>Nama</th>
			<th>Usia</th>
			<th>Jns. Kel.</th>
			<th>Golongan</th>
			<th style="width:80px">Status</th>
			<th></th>
		</tr>
		{% for row in data %}
			<tr class="kunjungan_{{row.id}} orders" valign="top">
				<td>{{row.no_kunjungan}}</td>
				<td>{{row.jam}}</td>
				<td>{{row.no_rekmed}}</td>
				<td><abbr title="Alamat : {{row.alamat}} , Telp. {{row.tlp}}">{{row.nama}}</abbr></td>
				<td>{{row.usia}}</td>
				<td>{{row.sex}}</td>
				<td>{{row.golongan}}</td>
				<td class="status">{{row.status}}</td>
				<td class="histori_options">
					{% if row.status == 'antri' %}
					<button class="lanjut btn btn-success" idk="{{row.id}}">Periksa</button>
					{% else %}
					<button class="lanjut btn btn-warning" idk="{{row.id}}" disabled=disabled>Selesai</button>
					{% endif %}
				</td>
			</tr>
		{% endfor %}
	</table>
	<div id="current_time" year="{{current.year}}" month="{{current.mon}}" day="{{current.mday}}" hour="{{current.hours}}" minute="{{current.minutes}}" second="{{current.seconds}}"></div>
	{% else %}
		- Kunjungan Masih Kosong -<br/><br/>
	{% endif %}
</div>
{% endblock %}
{% block script %}
<script type="text/javascript" src="{% nav public %}js/glDatePicker.min.js"></script>
<script type="text/javascript">
	$(document).ready(function() {
		$("#find").keyup(function() {
			$this = $(this);
			$(".orders").hide();
			if ($this.val().trim() != '') {
				$(".orders").each(function() {
					$va = $(this).find('td');
					if ((
						$va.eq(3).text().toLowerCase().indexOf($this.val().toLowerCase()) >= 0 || 
						$va.eq(4).find('abbr').attr('title').toLowerCase().indexOf($this.val().toLowerCase()) >= 0 || 
						$va.eq(4).text().toLowerCase().indexOf($this.val().toLowerCase()) >= 0 || 
						$va.eq(5).text().toLowerCase().indexOf($this.val().toLowerCase()) >= 0)
					) {
						console.debug($va.eq(4).text().toLowerCase().indexOf($this.val().toLowerCase()));
						$(this).show();
					}
				});
			} else {
				$(".orders").show();
			}
		});
		$('.lanjut').on("click", function(){
			var idk = $(this).attr("idk");
			window.location='{% nav poli_periksa %}?idk='+idk;
		});
		$("#date_picker").glDatePicker({
			cssName: "android",
			selectedDate:new Date("{{tgl_js}}"),
			startDate: new Date("{{tgl_js}}"),
		    allowOld: true,
			onChange: function(target, newDate)
				{
					var month= ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Des"];
					target.val
					(
						newDate.getDate()  + "-" +
						month[newDate.getMonth()] + "-" +
						newDate.getFullYear() 
					);
					
					location.href = "{% nav poli_kunjungan %}?tgl=" + newDate.getDate()  + "-" + (newDate.getMonth() + 1) + "-" + newDate.getFullYear();
				}
		});
	});
	var elapsed_second = 0;
	
	function getTimer() {
		elapsed_second++;
		c = new Date(
				$("#current_time").attr('year'),
				$("#current_time").attr('month') -1,
				$("#current_time").attr('day'),
				$("#current_time").attr('hour'),
				$("#current_time").attr('minute'),
				$("#current_time").attr('second'));
				
		c.setSeconds(c.getSeconds() + elapsed_second); 
		
		$(".delivery_time").each(function() {
			d = new Date($(this).attr('year'),
						$(this).attr('month') -1,
						$(this).attr('day'),
						$(this).attr('hour'),
						$(this).attr('minute'),
						$(this).attr('second'));
			ms = c - d;
			
			x = ms /1000;
			second = Math.floor(x % 60);
			x /= 60;
			minute = Math.floor(x % 60);
			x /= 60;
			hour = Math.floor(x % 24);
			x /= 24;
			day = Math.floor(x % 24);
			
			hour = (day * 24) + hour;
			
			if (hour < 10) hour = "0" + Math.floor(hour);
			if (minute < 10) minute = "0" + Math.floor(minute);
			if (second < 10) second = "0" + Math.floor(second);
			
			$(this).text(hour+":"+minute+":"+second);
		});
	}
</script>
{% endblock %}