
<script>
	var dcStatus = 'unknown';

	function mobileRender() {
		$('#KD1').html(sensors[1].Value);
		$('#KD2').html(sensors[3].Value);
		$('#KD3').html(sensors[2].Value);

		dcStatus = 'normal';
		console.log(sensors);
		for (var i = 1; i <= 3; i++) {
			var sensor = sensors[i];

			console.log(sensor.Value)

			if (dcStatus == 'normal') {
				if (sensor.Value > 23.5) {
					dcStatus = 'warning';
				}
			}
			if (dcStatus == 'warning') {
				if (sensor.Value > 25) {
					dcStatus = 'critical';
				}
			}
		}
		console.log(dcStatus);
		$('#mobileDashboardLayout').removeClass('unknown');
		switch (dcStatus) {
			case 'normal':
				$('#mobileDashboardLayout').removeClass('warning').removeClass('critical');
				break;
			case 'warning':
				$('#mobileDashboardLayout').   addClass('warning').removeClass('critical');
				break;
			case 'critical':
				$('#mobileDashboardLayout').removeClass('warning').   addClass('critical');
				break;
		}
	}

	function updateMobileStatus() {
		$.ajax({
			cache:		false,
			dataType:	'json',
			url:		'/m.json',
			success:	function(data){
				sensors = data.sensors;
				mobileRender();
			},
		});
	}
</script>


<div id='mobileDashboardLayout'{{if .isMobile}} class='unknown' style='display:block'{{end}}>
	<table width='100%' height='100%'>
		<tr height='30%'>
			<td>
				{{ $sensor := index .sensors 1 }}
				<span id='KD1'>{{ $sensor.Value }}</span>
				{{if ne .mobileShowNames "false"}}<div class='comment'>{{ $sensor.FullName }}</div>{{end}}
			</td>
		</tr>
		<tr height='30%'>
			<td>
				{{ $sensor := index .sensors 3 }}
				<span id='KD2'>{{ $sensor.Value }}</span>
				{{if ne .mobileShowNames "false"}}<div class='comment'>{{ $sensor.FullName }}</div>{{end}}
			</td>
		</tr>
		<tr height='30%'>
			<td>
				{{ $sensor := index .sensors 2 }}
				<span id='KD3'>{{ $sensor.Value }}</span>
				{{if ne .mobileShowNames "false"}}<div class='comment'>{{ $sensor.FullName }}</div>{{end}}
			</td>
		</tr>
{{ if eq .mobileAutoupdate "toggle" }}
		<tr height='10%'{{if .isMobile}}{{else}} style='display:none'{{end}} onclick='autoupdatesToggle()'>
			<td style='font-size:16px'>
				<label for='autoupdate'>Включить автообновление:</label><input style='margin-left:5px' id='autoupdate' type='checkbox'>
			</td>
		</tr>
{{ end }}
	</table>
</div>
