comparison show.php @ 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 f188caaedf0f
children 5f92fa5e683a
comparison
equal deleted inserted replaced
1062:7135c7b18bb9 1065:511147c1e119
15 15
16 cmPrintPageHeader("PARTY INFORMATION DISPLAY SYSTEM", "", FALSE); 16 cmPrintPageHeader("PARTY INFORMATION DISPLAY SYSTEM", "", FALSE);
17 stCommonAJAX("showajax.php", "show.php"); 17 stCommonAJAX("showajax.php", "show.php");
18 ?> 18 ?>
19 19
20 <!-- ========================== -->
21
22 <noscript> 20 <noscript>
23 <div class="notice"> 21 <div class="notice">
24 <h1>Javascript required</h1> 22 <h1>Javascript required</h1>
25 <p> 23 <p>
26 The compo system page requires Javascript to be enabled for the AJAX functionality. 24 The compo system page requires Javascript to be enabled for the AJAX functionality.
30 </div> 28 </div>
31 </noscript> 29 </noscript>
32 30
33 <div class="showView" id="mainView"></div> 31 <div class="showView" id="mainView"></div>
34 32
35 <!-- ========================== --> 33 <script type="text/javascript" src="show.js"></script>
36
37 <script type="text/javascript">
38
39 var failCount = 0;
40 var lastUpdate = 0;
41 var errorView = false;
42
43
44 function updateView(txt)
45 {
46 var view = document.getElementById("mainView");
47 if (view && txt != false && txt != "")
48 view.innerHTML = txt;
49 }
50
51
52 function displayError()
53 {
54 // Increase failure count
55 if (++failCount >= 3 && !errorView)
56 {
57 errorView = true;
58 updateView("<div class=\"slideHeader\"><div class=\"slideHeaderDiv\"></div></div><div class=\"slideText\"><div class=\"guru\">Software Failure.&nbsp;&nbsp;&nbsp;Press left mouse button to continue.<br />Guru Meditation #00000004.0000AAC0</div></div>");
59 }
60 }
61
62
63 //
64 // Update view when triggered by main tick
65 //
66 function viewChanged()
67 {
68 var msuccess2 = function(txt)
69 {
70 // Successfully fetched new data, initiate view update
71 updateView(txt);
72 }
73
74 var msuccess1 = function(txt)
75 {
76 lastUpdate = txt;
77 jsSendPOSTRequest("action=get&type=slide", msuccess2, displayError);
78 }
79
80 jsSendPOSTRequest("action=get&type=update", msuccess1, displayError);
81 }
82
83
84 //
85 // Main tick function, check for updates from server
86 //
87 var timeOutSet = false;
88
89 function tickMain()
90 {
91 timeOutSet = false;
92
93 var msuccess = function(txt)
94 {
95 failCount = 0;
96 if (txt == "changed")
97 {
98 viewChanged();
99 if (!timeOutSet)
100 {
101 setTimeout("tickMain();", 250);
102 timeOutSet = true;
103 }
104 }
105 else
106 if (txt == "reload")
107 {
108 location.reload();
109 }
110 else
111 {
112 if (!timeOutSet)
113 {
114 setTimeout("tickMain();", 500);
115 timeOutSet = true;
116 }
117 }
118 }
119
120 var mfail = function(txt)
121 {
122 displayError();
123 if (!timeOutSet)
124 {
125 setTimeout("tickMain();", 5000);
126 timeOutSet = true;
127 }
128 }
129
130 jsSendPOSTRequest("action=check&lastUpdate="+lastUpdate, msuccess, mfail);
131 }
132
133 setTimeout("tickMain();", 100);
134 viewChanged();
135
136 </script>
137 <? 34 <?
138 cmPrintPageFooter(FALSE); 35 cmPrintPageFooter(FALSE);
139 ?> 36 ?>