#!/mod/bin/jimsh

source /mod/webif/lib/setup
jqplugin iphone-style-checkboxes enadis
header

puts {
<script type="text/javascript">

$(document).ready(function() {
	$('input:checkbox').iphoneStyle();
	// Don't allow turning off the web server from within the web server..
	$('input:checkbox[name=mongoose][class=toggle]').disable();

	$(':checkbox').change(function() {
		if ($(this).attr('name') == 'mongoose' &&
		    !$(this).is(':checked'))
			alert(
		    'Note that mongoose is the web server service that ' +
		    'provides this web interface. If you disable auto-start ' +
		    'then the web interface will not be available when the ' +
		    'Humax is restarted.');
		var url = '/cgi-bin/service.jim?action=' +
		    escape($(this).attr('class')) +
		    '&service=' +
		    escape($(this).attr('name'));
		$('#result_txt').load(url, function() {
			if ($('#results').is(":visible") == false)
			{
				$('#results').show('slow');
				$('#results').delay(3000).hide('slow');
			}
		});
	});
});

</script>

<h1>Service Management</h1>
<div id=results class=shadowbox style="width: 90%; display: none; margin: 1 0 1em 0">
<div>
<pre id=result_txt>
Results...
</pre>
</div>
</div>

<table class=borders cellpadding=5>
<tr class=greenshade>
<th>Service</th>
<th>Auto Startup</th>
<th>Status</th>
</tr>
}

set services [split [exec /mod/bin/service mlist]]

foreach service $services {
	lassign [split $service ":"] name installed auto running

	if {$name eq "mongoose"} continue

	puts "<tr><td class=even>$name</td>"
	if (!$installed) {
		puts "<td colspan=2><i>Not installed</i></td></tr>"
		continue
	}

	puts -nonewline "<td><input type=checkbox class=auto name=\"$name\""
	if ($auto) { puts -nonewline " checked" }
	puts "></td>"

	puts -nonewline "<td><input type=checkbox class=toggle name=\"$name\""
	if ($running) { puts -nonewline " checked" }
	puts "></td>"

	puts "</tr>"
}

puts {
</table>
}

footer

