summaryrefslogtreecommitdiff
path: root/javascript/vdr_status.js
blob: 2a2a0d11a2304c0926b0d5f2f52ff42cb785732a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
 * Javascript functions for the status update box.
 * This file needs 'ajax.js' to be included on the pages.
 */

var vst_reload = true;
var vst_timer;
var vst_boxId = null;
var vst_url = null;

function LiveStatusAjaxRequest(url, containerid)
{
	if (vst_url == null)
		vst_url = url;
	if (vst_boxId == null)
		vst_boxId = containerid;

	var status = new LiveAjaxCall("text", url);
	status.oncomplete = function()
		{
			document.getElementById(containerid).innerHTML = this.xml.responseText;
			if (vst_reload)
				vst_timer = window.setTimeout("LiveStatusAjaxRequest('" + url + "', '" + containerid + "')", 1000);
		}
	status.onerror = function(message)
		{
			vst_reload = false;
			document.getElementById(containerid).innerHTML =
			'<div class="statuscontent>' +
				'<div class="st_header">' +
					'<div class="caption">ERROR</div>' +
					'<div class="now">&nbsp;<img id="statusReloadBtn" src="reload.png" alt="toggle reload on and off" onclick="LiveStatusToggleUpdate()" />&nbsp;ERROR</div>' +
				'</div>' +
				'<div class="st_content">' +
					'<div class="name">' + message + '</div>' +
				'</div>' +
			'</div>';
		}
	status.request("", "");
}

function LiveStatusToggleUpdate()
{
	if (vst_reload) {
		vst_reload = false;
		if (vst_timer != null)
			window.clearTimeout(vst_timer);
	}
	else {
		vst_reload = true;
		LiveStatusAjaxRequest(vst_url, vst_boxId);
	}
	var img = document.getElementById('statusReloadBtn');
	if (img != null) {
		// change image according to state.
		img.src = vst_reload ? 'stop.png' : 'reload.png';
	}
}