Annotation of embedaddon/coova-chilli/www/chilliController.js, revision 1.1.1.1
1.1 misho 1: chilliController.onUpdate = updateUI ;
2: chilliController.onError = handleError ;
3: chilliClock.onTick = function () { }
4:
5: if (!window.queryObj) {
6: window.queryObj = new Object();
7: window.location.search.replace(new RegExp("([^?=&]+)(=([^&]*))?","g"), function($0,$1,$2,$3) { queryObj[$1] = $3; });
8: }
9:
10: chilliController.queryObj = window.queryObj;
11:
12: function ie_getElementsByTagName(str) {
13: if (str=="*") return document.all;
14: else return document.all.tags(str);
15: }
16:
17: if (document.all)
18: document.getElementsByTagName = ie_getElementsByTagName;
19:
20: function hidePage(page) {
21: var e = document.getElementById(page);
22: if (e != null) e.style.display='none';
23: }
24:
25: function showPage(page) {
26: var e = document.getElementById(page);
27: if (e != null) e.style.display='inline';
28: }
29:
30: function setElementValue(elem, val, forceHTML) {
31: var e = document.getElementById(elem);
32: if (e != null) {
33: var node = e;
34: if (!forceHTML && node.firstChild) {
35: node = node.firstChild;
36: node.nodeValue = val;
37: } else {
38: node.innerHTML = val;
39: }
40: }
41: }
42:
43: chilliClock.onChange = function ( newval ) {
44: setElementValue("sessionTime", chilliController.formatTime(newval));
45: }
46:
47: function updateUI (cmd ) {
48: log ( "Update UI is called. chilliController.clientState = " + chilliController.clientState ) ;
49:
50: clearTimeout ( delayTimer );
51:
52: if ( chilliController.redir ) {
53: if (chilliController.redir.originalURL != null &&
54: chilliController.redir.originalURL != '') {
55: setElementValue('originalURL', '<a target="_blank" href="'+chilliController.redir.originalURL+
56: '">'+chilliController.redir.originalURL+'</a>', true);
57: }
58: if (chilliController.redir.redirectionURL != null &&
59: chilliController.redir.redirectionURL != '') {
60: setElementValue('redirectionURL', chilliController.redir.redirectionURL);
61: }
62: }
63:
64: if ( chilliController.message ) {
65: setElementValue('logonMessage', chilliController.message);
66: chilliController.message = null;
67: chilliController.refresh();
68: }
69:
70: if ( chilliController.location ) {
71: setElementValue('locationName', chilliController.location.name);
72: chilliController.location = null;
73: }
74:
75: if ( chilliController.clientState == 0 ) {
76: showLogonPage();
77: }
78:
79: if ( chilliController.clientState == 1 ) {
80: if ( chilliController.statusURL ) {
81: chilliController.statusWindow = window.open(chilliController.statusURL, "");
82: } else {
83: showStatusPage();
84: }
85: }
86:
87: if (chilliController.redir.redirectionURL) {
88: //chilliController.nextWindow = window.open(chilliController.redir.redirectionURL,'nextURL');
89: window.location.href = chilliController.redir.redirectionURL;
90: chilliController.redir.redirectionURL = null;
91: }
92:
93: if ( chilliController.clientState == 2 ) showWaitPage();
94: }
95:
96: function handleError( code ) {
97: clearTimeout(delayTimer);
98: //showErrorPage(code);
99: }
100:
101: /* Action triggered when buttons are pressed */
102: function connect() {
103: var username = document.getElementById('username').value ;
104: var password = document.getElementById('password').value ;
105:
106: if (username == null || username == '')
107: return setElementValue('logonMessage', 'Username is required');
108:
109: showWaitPage(1000);
110: chilliController.logon( username , password ) ;
111: }
112:
113: function disconnect() {
114: if (confirm("Are you sure you want to disconnect now?")) {
115: chilliClock.stop();
116: showWaitPage(1000);
117: chilliController.logoff();
118: }
119: return false;
120: }
121:
122: /* User interface pages update */
123: function showLogonPage() {
124: if (chilliController.openid)
125: showPage('openIDSelect');
126: showPage("logonPage");
127: hidePage("statusPage");
128: hidePage("waitPage");
129: hidePage("errorPage");
130: }
131:
132: function showStatusPage() {
133: hidePage("logonPage");
134: showPage("statusPage");
135: hidePage("waitPage");
136: hidePage("errorPage");
137:
138: // Update message
139: if ( chilliController.message ) {
140: setElementValue("statusMessage", chilliController.message);
141: }
142:
143: // Update session
144: setElementValue("sessionId",
145: chilliController.session.sessionId ?
146: chilliController.session.sessionId :
147: "Not available");
148:
149: setElementValue("startTime",
150: chilliController.session.startTime ?
151: chilliController.session.startTime :
152: "Not available");
153:
154: setElementValue("sessionTimeout",
155: chilliController.formatTime(chilliController.session.sessionTimeout, 'unlimited'));
156:
157: setElementValue("idleTimeout",
158: chilliController.formatTime(chilliController.session.idleTimeout, 'unlimited'));
159:
160: setElementValue("maxInputOctets",
161: chilliController.formatBytes(chilliController.session.maxInputOctets));
162: setElementValue("maxOutputOctets",
163: chilliController.formatBytes(chilliController.session.maxOutputOctets));
164: setElementValue("maxTotalOctets",
165: chilliController.formatBytes(chilliController.session.maxTotalOctets));
166:
167: // Update accounting
168: setElementValue("sessionTime",
169: chilliController.formatTime(chilliController.accounting.sessionTime));
170:
171: setElementValue("idleTime",
172: chilliController.formatTime(chilliController.accounting.idleTime));
173:
174: setElementValue("inputOctets" , chilliController.formatBytes(chilliController.accounting.inputOctets));
175: setElementValue("outputOctets", chilliController.formatBytes(chilliController.accounting.outputOctets));
176:
177: chilliClock.resync (chilliController.accounting.sessionTime);
178: }
179:
180: function showOpenIDForm(e)
181: {
182: var form = document.getElementById('openIDForm');
183: var x = document.createElement('div');
184: x.style.display = 'block';
185: x.style.position = 'absolute';
186: x.style.top = e.y - 25;
187: x.style.left = e.x + 25;
188: x.style.xIndex = 2;
189: x.innerHTML = form.innerHTML;
190: document.body.appendChild(x);
191: }
192:
193: function openID() {
194: var openIDSelect = document.getElementById('openIDSelect');
195:
196: openIDSelect.onclick = function(e) {
197: if (!e) e = window.event;
198: e.stopPropagation;
199: showOpenIDForm(e);
200: };
201:
202: var openIDForm = document.getElementById('openIDForm');
203:
204: openIDForm.onclick = function(e) {
205: if (!e) e = window.event;
206: e.stopPropagation;
207: };
208:
209: document.onclick = closeOpenIDForm();
210: }
211:
212: function closeOpenIDForm() {
213: hidePage('openIDForm');
214: }
215:
216: function showWaitPage(delay) {
217: /* Wait for delay */
218: clearTimeout(delayTimer);
219: if (typeof(delay) == 'number' && (delay > 10)) {
220: delayTimer= setTimeout('showWaitPage(0)' , delay);
221: return;
222: }
223:
224: /* show the waitPage */
225: hidePage("logonPage");
226: hidePage("statusPage");
227: showPage("waitPage");
228: hidePage("errorPage");
229: }
230:
231: function showErrorPage( str ) {
232: setTimeout('chilliController.refresh()', 15000);
233:
234: hidePage("logonPage");
235: hidePage("statusPage");
236: hidePage("waitPage");
237: showPage("errorPage");
238: setElementValue("errorMessage", str);
239: }
240:
241: var chillijsWindowOnLoad = window.onload;
242: var delayTimer; // global reference to delayTimer
243: window.onload = function() {
244: if (chillijsWindowOnLoad)
245: chillijsWindowOnLoad();
246:
247: var logonForm = document.getElementById('logonForm');
248:
249: var head = document.getElementsByTagName("head")[0];
250: if (head == null) head = document.body;
251:
252: if (logonForm == null) {
253: logonForm = document.getElementById('loginForm');
254: }
255:
256: if (logonForm == null) {
257: try {
258: logonForm = document.createElement('div');
259: logonForm.setAttribute('id', 'logonForm');
260: logonForm.setAttribute('name', 'logonForm');
261: var thisScript = document.getElementById('chillijs');
262: if (thisScript != null) {
263: thisScript.parentNode.insertBefore(logonForm, thisScript);
264: } else {
265: document.body.appendChild(logonForm);
266: }
267: } catch(exception) {
268: document.body.innerHTML += "<div id='logonForm'></div>";
269: }
270: logonForm = document.getElementById('logonForm');
271: }
272:
273: if (logonForm.innerHTML == '') {
274: if (head != null) {
275: var script = document.createElement('script');
276: script.id = 'chilliform';
277: script.type = 'text/javascript';
278: script.src = 'http://'+chilliController.host+':'+chilliController.port+'/www/chilliform.chi';
279: head.appendChild(script);
280: } else {
281: logonForm.innerHTML='Error loading generic login form';
282: }
283: }
284:
285: showWaitPage();
286: setTimeout('chilliController.refresh()', 500);
287: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>