Mercurial > hg > fapweb
diff show.js @ 1065:511147c1e119
Move some of the show.php javascript code to show.js.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 24 Jan 2017 13:13:48 +0200 |
parents | |
children | 82ecea33c477 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/show.js Tue Jan 24 13:13:48 2017 +0200 @@ -0,0 +1,102 @@ +// +// FAPWeb - Simple Web-based Demoparty Management System +// Party main screen viewer +// (C) Copyright 2012-2017 Tecnic Software productions (TNSP) +// + +var failCount = 0; +var lastUpdate = 0; +var errorView = false; + + +function updateView(txt) +{ + var view = document.getElementById("mainView"); + if (view && txt != false && txt != "") + view.innerHTML = txt; +} + + +function displayError() +{ + // Increase failure count + if (++failCount >= 3 && !errorView) + { + errorView = true; + updateView("<div class=\"slideHeader\"><div class=\"slideHeaderDiv\"></div></div><div class=\"slideText\"><div class=\"guru\">Software Failure. Press left mouse button to continue.<br />Guru Meditation #00000004.0000AAC0</div></div>"); + } +} + + +// +// Update view when triggered by main tick +// +function viewChanged() +{ + var msuccess2 = function(txt) + { + // Successfully fetched new data, initiate view update + updateView(txt); + } + + var msuccess1 = function(txt) + { + lastUpdate = txt; + jsSendPOSTRequest("action=get&type=slide", msuccess2, displayError); + } + + jsSendPOSTRequest("action=get&type=update", msuccess1, displayError); +} + + +// +// Main tick function, check for updates from server +// +var timeOutSet = false; + +function tickMain() +{ + timeOutSet = false; + + var msuccess = function(txt) + { + failCount = 0; + if (txt == "changed") + { + viewChanged(); + if (!timeOutSet) + { + setTimeout("tickMain();", 250); + timeOutSet = true; + } + } + else + if (txt == "reload") + { + location.reload(); + } + else + { + if (!timeOutSet) + { + setTimeout("tickMain();", 500); + timeOutSet = true; + } + } + } + + var mfail = function(txt) + { + displayError(); + if (!timeOutSet) + { + setTimeout("tickMain();", 5000); + timeOutSet = true; + } + } + + jsSendPOSTRequest("action=check&lastUpdate="+lastUpdate, msuccess, mfail); +} + +setTimeout("tickMain();", 100); +viewChanged();