diff options
Diffstat (limited to 'javascript')
-rw-r--r-- | javascript/Makefile | 2 | ||||
-rw-r--r-- | javascript/ajax.js | 15 | ||||
-rw-r--r-- | javascript/vdr_status.js | 58 |
3 files changed, 59 insertions, 16 deletions
diff --git a/javascript/Makefile b/javascript/Makefile index 5419c64..36582e6 100644 --- a/javascript/Makefile +++ b/javascript/Makefile @@ -16,7 +16,7 @@ VDRDIR ?= ../../../.. ### The object files (add further files here): OBJS = alphaAPI.o domLib.o domTT_drag.o domTT.o fadomatic.o \ - treeview.o ajax.o + treeview.o ajax.o vdr_status.o ### Default rules: diff --git a/javascript/ajax.js b/javascript/ajax.js index 4db64e5..4da2b8d 100644 --- a/javascript/ajax.js +++ b/javascript/ajax.js @@ -66,18 +66,3 @@ function LiveSimpleAjaxRequest(url, param, value) xml.onerror = function(message) { alert(message); } xml.request(param, value); }; - -function LiveStatusAjaxRequest(url, containerid) -{ - var xml = new LiveAjaxCall("text", url); - xml.oncomplete = function() - { - document.getElementById(containerid).innerHTML = this.xml.responseText; - window.setTimeout("LiveStatusAjaxRequest('" + url + "', '" + containerid + "')", 1000); - } - xml.onerror = function(message) - { - document.getElementById(containerid).innerHTML = "<div>ERROR: " + message + "</div>"; - } - xml.request("", ""); -} diff --git a/javascript/vdr_status.js b/javascript/vdr_status.js new file mode 100644 index 0000000..2a2a0d1 --- /dev/null +++ b/javascript/vdr_status.js @@ -0,0 +1,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"> <img id="statusReloadBtn" src="reload.png" alt="toggle reload on and off" onclick="LiveStatusToggleUpdate()" /> 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'; + } +} |