missing g_listen entry substitution fixed
[brisk.git] / web / ticker.js
1 /*
2  *  brisk - ticker.js
3  *
4  *  Copyright (C) 2006-2012 Matteo Nastasi
5  *                          mailto: nastasi@alternativeoutput.it 
6  *                                  matteo.nastasi@milug.org
7  *                          web: http://www.alternativeoutput.it
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful, but
15  * WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABLILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * General Public License for more details. You should have received a
18  * copy of the GNU General Public License along with this program; if
19  * not, write to the Free Software Foundation, Inc, 59 Temple Place -
20  * Suite 330, Boston, MA 02111-1307, USA.
21  *
22  */
23
24 function train(anc) {
25     var box;
26     this.anc = anc;
27        
28     box = document.createElement("div");
29     box.className = "train";
30     box.id = "train";
31     box.style.left = "0px";
32     box.style.width = "0px";
33     box.style.height = "0px";
34     box.anc = this;
35     
36     addEvent(box, "mouseover", function() { this.anc.stop_move(); } );
37     addEvent(box, "mouseout", function() { this.anc.start_move(); } );
38
39     this.box = box;
40     this.anc.appendChild(box);
41
42 }
43
44 train.prototype = {
45     anc: null,
46     first: null,
47     box: null,
48     notebox: null,
49     width: 0,
50     deltat: 250,
51     deltas: 10,
52     xend: 0,
53     timout: null,
54     clickable: false,
55
56     show: function()
57     {
58         $('tickbut').style.visibility = "hidden";
59         $('tickbut').style.width = "0px";
60
61         this.clickable = true;
62         this.box.style.visibility = "visible";
63         for (cur = this.first ; cur != null ; cur = cur.next) {
64             cur.box.style.borderColor = "green green green green";
65         }
66     },
67
68     hide: function()
69     {
70         $('tickbut').style.visibility = "visible";
71         $('tickbut').style.width = "20px";
72
73         this.clickable = false;
74         this.box.style.visibility = "visible";
75
76         for (cur = this.first ; cur != null ; cur = cur.next) {
77             if (cur.notebox != null) {
78                 cur.cb_mouseout();
79             }
80             cur.box.style.borderColor = "gray gray gray gray";
81         }
82            
83     },
84
85     hide_noauth: function()
86     {
87         for (cur = this.first ; cur != null ; cur = cur.next) {
88             if (cur.table >= g_tables_auth_n) {
89                 cur.hide();
90             }
91         }           
92     },
93
94     show_noauth: function()
95     {
96         for (cur = this.first ; cur != null ; cur = cur.next) {
97             if (cur.table >= g_tables_auth_n) {
98                 cur.show();
99             }
100         }           
101     },
102
103     add: function(table, title)
104     {
105         var last, wag, curx;
106         var dostart = 0;
107
108         for (cur = this.first ; cur != null ; cur = cur.next) {
109             if (cur.table == table)
110                 return;
111         }
112
113         wag = new wagon(this, table, title);
114         if (this.first == null) {
115             this.first = wag;
116             dostart = 1;
117         }
118         else {
119             for (cur = this.first ; cur.next != null ; cur = cur.next);
120             cur.next = wag;
121         }
122
123         this.redraw();
124         this.xend = -this.widthbox_get();
125
126         if (dostart) {
127             this.start();
128         }
129
130     },
131
132     rem: function(table)
133     {
134         var prev = null, remo = null;
135
136         if (this.first == null) {
137             return;
138         }
139    
140         if (this.first.table == table) {
141             remo = this.first;
142         }
143
144         for (cur = this.first ; cur != null ; cur = cur.next) {
145             // recalculate the width and replace wagons
146             if (cur.table == table) {
147                 remo = cur;
148                 break;
149             }
150         }
151
152         if (remo != null) {
153             remo.box.className = "wagon_disable";
154             removeEvent(remo.box, "mouseover", function() { this.anc.cb_mouseover(); } );
155             removeEvent(remo.box, "click",     function() { this.anc.cb_click(); } );
156             setTimeout(function(){ arguments[0][0].shut_wagon(arguments[0]); }, 3000, [ this, remo ]);
157         }
158
159         this.redraw();
160     },
161
162     rem_obj: function(obj)
163     {
164         var prev = null, remo = null;
165
166         if (this.first == null) {
167             return;
168         }
169    
170
171         if (this.first == obj) {
172             remo = this.first;
173             this.first = this.first.next;
174         }
175
176         for (cur = this.first ; cur != null ; cur = cur.next) {
177             // recalculate the width and replace wagons
178             if (cur == obj) {
179                 remo = cur;
180                 
181                 if (prev != null) {
182                    prev.next = cur.next;
183                 }
184                 break;
185             }
186             prev = cur;
187         }
188
189         this.redraw();
190
191         if (this.first == null) {
192             clearTimeout(this.timout);
193             this.timout = null;
194         }
195     },
196
197     stop_move: function()
198     {
199         this.deltas = 0;
200     },
201
202     start_move: function()
203     {
204         this.deltas = 10;
205     },
206
207     shut_wagon: function(args)
208     {
209         var curw;
210
211         obj = arguments[0][0];
212         wag = arguments[0][1];
213
214         if (wag.shut_step == 0) {
215             wag.box.className = "wagon_disable";
216             wag.shut_step = 1;
217         }
218         else {
219             if (wag.shut_step == 1) {
220                 wag.w = wag.widthbox_get();
221                 wag.box.className = "wagon_disable2";
222                 wag.box.style.padding = "0px";
223                 wag.box.style.width =  (wag.w-2)+"px";
224                 wag.box.style.height = (wag.h-2)+"px"; // 2 for border width
225                 wag.table = "";
226                 wag.box.innerHTML = "";
227                 wag.shut_step = 2;
228             }
229             curw = wag.widthbox_get() - 10;
230             wag.w = curw + 2; // 2 for border pixels
231             if (curw <= 0) {
232                 wag.cb_mouseout();
233
234                 obj.box.removeChild(wag.box);
235                 obj.rem_obj(wag);
236
237                 return;
238             }
239             else {
240                 wag.box.style.width = curw+"px";
241                 wag.box.style.padding = "0px";
242             }
243         }
244         this.redraw();
245         setTimeout(function(){ arguments[0][0].shut_wagon(arguments[0]);  }, 250, [ obj, wag ]);
246     },
247
248     redraw: function()
249     {
250         var maxw = 0, maxh = 0, curh;
251
252         for (cur = this.first ; cur != null ; cur = cur.next) {
253             // recalculate the width and replace wagons
254             maxw += 2 + (maxw == 0 ? 0 : 2) + cur.width_get();
255             curh = cur.height_get();
256             maxh = (maxh < curh ? curh : maxh);
257         }
258         maxh += 2;
259         curx = 0;
260         
261         for (cur = this.first ; cur != null ; cur = cur.next) {
262             // recalculate the width and replace wagons
263             cur.left_set(curx);
264             curx += cur.width_get() + 4;
265         }
266
267         this.box.style.width = maxw+"px";
268         this.box.style.height = maxh+"px";
269     },
270
271     resetx: function()
272     {
273         this.deltas = 10;
274
275         this.box.style.left = this.anc.offsetWidth+"px";
276     },
277
278
279     start: function()
280     {
281         this.resetx();
282         if (this.timout == null) {
283             this.timout = setTimeout(function(obj){ obj.animate(); }, this.deltat, this);
284         }
285     },
286
287     animate: function()
288     {
289        this.box.style.left = (parseInt(this.box.style.left) - this.deltas)+"px";
290
291 //        if (parseInt(this.box.style.left) >= this.xend) {
292 //             this.timout = setTimeout(function(obj){ obj.animate(); }, this.deltat, this);
293 //         }
294 //         else {
295 //             this.box.style.left = this.anc.offsetWidth+"px";
296 //             this.timout = setTimeout(function(obj){ obj.animate(); }, this.deltat, this);
297 //         }
298        if (parseInt(this.box.style.left) < this.xend) {
299            this.box.style.left = this.anc.offsetWidth+"px";
300        }
301        this.timout = setTimeout(function(obj){ obj.animate(); }, this.deltat, this);
302     },
303
304     widthbox_get: function()
305     {
306         return (this.box.offsetWidth);
307     },
308
309     heightbox_get: function()
310     {
311         return (this.box.offsetHeight);
312     },
313
314     widthanc_get: function()
315     {
316         return (this.anc.offsetWidth);
317     },
318
319     heightanc_get: function()
320     {
321         return (this.anc.offsetHeight);
322     }
323 } // train class end
324
325
326
327 function wagon(anc, table, title) {
328     var box;
329     var othis = this;
330     this.anc = anc;
331     
332     box = document.createElement("div");
333     box.className = "wagon";
334     box.anc = this;
335     if (anc.clickable == false)
336         box.style.borderColor = "gray gray gray gray";
337     this.table = table;
338     this.title = title;
339     box.innerHTML = "Tavolo&nbsp;"+table;
340     this.box = box;
341     this.box.setAttribute("title", unescapeHTML(title));
342     
343     addEvent(this.box, "mouseover", function() { this.anc.cb_mouseover(); } );
344     addEvent(this.box, "mouseout",  function() { this.anc.cb_mouseout(); }  );
345     addEvent(this.box, "click",     function() { this.anc.cb_click(); }     );
346
347     
348     if (g_prefs.listen & l_list_isol && table >= g_tables_auth_n) {
349         this.box.style.visibility = "hidden";
350     }
351     this.anc.box.appendChild(box);
352
353     this.w = this.widthbox_get();
354     this.h = this.heightbox_get();
355 }
356
357 wagon.prototype = {
358     prev: null,
359     next: null,
360     table: 55,
361     anc: null,
362     w: 0,
363     h: 0,
364     x: 0,
365     box: null,
366     shut_step: 0, 
367
368     show: function()
369     {
370         this.box.style.visibility = "visible";
371     },
372
373     hide: function()
374     {
375         this.box.style.visibility = "hidden";
376     },
377     
378
379     width_get: function()
380     {
381         return (this.w);
382     },
383
384     height_get: function()
385     {
386         return (this.h);
387     },
388
389     widthbox_get: function()
390     {
391         return (this.box.offsetWidth);
392     },
393
394     heightbox_get: function()
395     {
396         return (this.box.offsetHeight);
397     },
398
399     widthnotebox_get: function()
400     {
401         return (this.notebox.offsetWidth);
402     },
403
404     heightnotebox_get: function()
405     {
406         return (this.notebox.offsetHeight);
407     },
408
409     left_set: function(x)
410     {
411         this.box.style.left  = x+"px";
412     },
413
414     cb_click: function()
415     { 
416         if (this.anc.clickable == true) {
417             act_sitdown(this.table);
418         }
419     },
420
421     cb_mouseover: function()
422     {
423         var notebox, deltax;
424
425         notebox = document.createElement("div");
426         notebox.className = "notebox";
427         notebox.id = "wagon_note";
428
429         notebox.innerHTML = $("table"+this.table).innerHTML;
430         $("room_standup_orig").appendChild(notebox);
431         
432         deltax = 0;
433         deltax = parseInt(getStyle(this.anc.box, "left", "left")) +
434                    parseInt(getStyle(this.box, "left", "left")) +
435                    ((this.box.offsetWidth - notebox.offsetWidth) / 2);
436         
437         notebox.style.left = deltax + "px";
438         notebox.style.top = (-10 -notebox.offsetHeight)+"px";
439         notebox.style.visibility = "visible";
440         notebox.anc = this;
441     
442         this.notebox = notebox;
443
444         return;
445     },
446
447     cb_mouseout: function()
448     {
449         if (this.notebox != null) {
450             $("room_standup_orig").removeChild(this.notebox);
451             this.notebox = null;
452         }
453     }
454
455 } // wagon class end