Mercurial > hg > fapweb
comparison 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 |
comparison
equal
deleted
inserted
replaced
1062:7135c7b18bb9 | 1065:511147c1e119 |
---|---|
1 // | |
2 // FAPWeb - Simple Web-based Demoparty Management System | |
3 // Party main screen viewer | |
4 // (C) Copyright 2012-2017 Tecnic Software productions (TNSP) | |
5 // | |
6 | |
7 var failCount = 0; | |
8 var lastUpdate = 0; | |
9 var errorView = false; | |
10 | |
11 | |
12 function updateView(txt) | |
13 { | |
14 var view = document.getElementById("mainView"); | |
15 if (view && txt != false && txt != "") | |
16 view.innerHTML = txt; | |
17 } | |
18 | |
19 | |
20 function displayError() | |
21 { | |
22 // Increase failure count | |
23 if (++failCount >= 3 && !errorView) | |
24 { | |
25 errorView = true; | |
26 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>"); | |
27 } | |
28 } | |
29 | |
30 | |
31 // | |
32 // Update view when triggered by main tick | |
33 // | |
34 function viewChanged() | |
35 { | |
36 var msuccess2 = function(txt) | |
37 { | |
38 // Successfully fetched new data, initiate view update | |
39 updateView(txt); | |
40 } | |
41 | |
42 var msuccess1 = function(txt) | |
43 { | |
44 lastUpdate = txt; | |
45 jsSendPOSTRequest("action=get&type=slide", msuccess2, displayError); | |
46 } | |
47 | |
48 jsSendPOSTRequest("action=get&type=update", msuccess1, displayError); | |
49 } | |
50 | |
51 | |
52 // | |
53 // Main tick function, check for updates from server | |
54 // | |
55 var timeOutSet = false; | |
56 | |
57 function tickMain() | |
58 { | |
59 timeOutSet = false; | |
60 | |
61 var msuccess = function(txt) | |
62 { | |
63 failCount = 0; | |
64 if (txt == "changed") | |
65 { | |
66 viewChanged(); | |
67 if (!timeOutSet) | |
68 { | |
69 setTimeout("tickMain();", 250); | |
70 timeOutSet = true; | |
71 } | |
72 } | |
73 else | |
74 if (txt == "reload") | |
75 { | |
76 location.reload(); | |
77 } | |
78 else | |
79 { | |
80 if (!timeOutSet) | |
81 { | |
82 setTimeout("tickMain();", 500); | |
83 timeOutSet = true; | |
84 } | |
85 } | |
86 } | |
87 | |
88 var mfail = function(txt) | |
89 { | |
90 displayError(); | |
91 if (!timeOutSet) | |
92 { | |
93 setTimeout("tickMain();", 5000); | |
94 timeOutSet = true; | |
95 } | |
96 } | |
97 | |
98 jsSendPOSTRequest("action=check&lastUpdate="+lastUpdate, msuccess, mfail); | |
99 } | |
100 | |
101 setTimeout("tickMain();", 100); | |
102 viewChanged(); |