annotate showajax.js.php @ 1069:5f92fa5e683a

Refactor how the "AJAX" stuff works.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 24 Jan 2017 17:25:48 +0200
parents
children 76e11ae923a7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1069
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1 <?php
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
2 header("Content-Type: application/javascript");
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
3 require_once "mconfig.inc.php";
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
4 require_once "msite.inc.php";
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
5 require_once "msession.inc.php";
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
6 ?>
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
7 //
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
8 // FAPWeb - Simple Web-based Demoparty Management System
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
9 // Party main screen viewer
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
10 // (C) Copyright 2012-2017 Tecnic Software productions (TNSP)
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
11 //
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
12 <?php
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
13 stCommonAJAX("showajax.php", "show.php");
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
14 ?>
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
15
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
16 var failCount = 0;
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
17 var lastUpdate = 0;
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
18 var errorView = false;
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
19
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
20
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
21 function updateView(txt)
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
22 {
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
23 var view = document.getElementById("mainView");
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
24 if (view && txt != false && txt != "")
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
25 view.innerHTML = txt;
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
26 }
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
27
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
28
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
29 function displayError()
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
30 {
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
31 // Increase failure count
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
32 if (++failCount >= 3 && !errorView)
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
33 {
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
34 errorView = true;
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
35 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>");
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
36 }
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
37 }
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
38
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
39
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
40 //
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
41 // Update view when triggered by main tick
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
42 //
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
43 function viewChanged()
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
44 {
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
45 var msuccess2 = function(txt)
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
46 {
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
47 // Successfully fetched new data, initiate view update
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
48 updateView(txt);
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
49 }
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
50
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
51 var msuccess1 = function(txt)
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
52 {
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
53 lastUpdate = txt;
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
54 jsSendPOSTRequest("action=get&type=slide", msuccess2, displayError);
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
55 }
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
56
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
57 jsSendPOSTRequest("action=get&type=update", msuccess1, displayError);
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
58 }
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
59
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
60
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
61 function setTickUpdate(qtime)
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
62 {
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
63 if (!timeOutSet)
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
64 {
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
65 timeOutSet = true;
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
66 setTimeout(function() { tickMain(); }, qtime);
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
67 }
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
68 }
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
69
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
70
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
71 //
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
72 // Main tick function, check for updates from server
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
73 //
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
74 function tickMain()
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
75 {
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
76 timeOutSet = false;
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
77
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
78 var msuccess = function(txt)
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
79 {
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
80 failCount = 0;
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
81 if (txt == "changed")
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
82 {
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
83 viewChanged();
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
84 setTickUpdate(250);
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
85 }
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
86 else
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
87 if (txt == "reload")
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
88 {
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
89 location.reload();
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
90 }
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
91 else
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
92 {
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
93 setTickUpdate(500);
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
94 }
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
95 }
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
96
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
97 var mfail = function(txt)
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
98 {
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
99 displayError();
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
100 setTickUpdate(5000);
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
101 }
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
102
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
103 jsSendPOSTRequest("action=check&lastUpdate="+lastUpdate, msuccess, mfail);
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
104 }
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
105
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
106 var timeOutSet = false;
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
107
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
108 document.addEventListener("DOMContentLoaded",
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
109 function ()
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
110 {
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
111 setTickUpdate(100);
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
112 viewChanged();
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
113 });
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
114