4 * Copyright (C) 2006-2009 Matteo Nastasi
5 * mailto: nastasi@alternativeoutput.it
6 * matteo.nastasi@milug.org
7 * web: http://www.alternativeoutput.it
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.
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.
26 data = [ [ flags, name ], ... ]
30 var l_list_all = 0x00;
31 var l_list_auth = 0x01;
32 var l_list_isol = 0x02;
34 function state_add(flags)
40 if ((flags & 0xf00) != 0) {
42 // MLANG 4,12,16,20,24,28
46 tit = (g_lang == 'en' ? "I'm doing a break" : "sono in pausa");
50 tit = (g_lang == 'en' ? "I'm away" : "sono fuori");
54 tit = (g_lang == 'en' ? "Dog time" : "sono a spasso col cane");
58 tit = (g_lang == 'en' ? "I'm eating" : "sto mangiando");
62 tit = (g_lang == 'en' ? "I'm working" : "sono a lavoro");
66 tit = (g_lang == 'en' ? "I'm smoking a sigarett (and keeping a cancer)" : "sto fumando una sigaretta (e facendomi venire il cancro)");
70 tit = (g_lang == 'en' ? "I'm here!" : "sono presente!");
73 name = "st_rabbit.png";
74 tit = (g_lang == 'en' ? "Rabbit time" : "sono a spasso col coniglio");
80 content += ' <img title="'+tit+'" class="unbo" src="img/'+name+'">';
87 var standup_data_old = null;
90 // appendChild , removeChild
92 function table_add(curtag, td)
97 // console.log("wt: "+curtag.tagName);
99 if (curtag.tagName.toLowerCase() == "div" ||
100 curtag.tagName.toLowerCase() == "table") {
101 curtag = curtag.firstChild;
103 else if (curtag.tagName.toLowerCase() == "tbody") {
109 } while (curtag != null);
111 curtag = tbody.firstChild;
114 if (curtag.tagName.toLowerCase() == "tr") {
115 if (curtag.firstChild != null) {
116 curtag = curtag.firstChild;
120 curtag.appendChild(td);
124 else if (curtag.tagName.toLowerCase() == "td") {
125 if (curtag.nextSibling != null) {
126 curtag = curtag.nextSibling;
131 curtag.parentNode.appendChild(td);
136 curtag = curtag.parentNode.nextSibling;
141 curtag = curtag.parentNode;
144 } while (curtag != null);
146 tr = document.createElement("tr");
148 tbody.appendChild(tr);
153 function spcs(c1, c2, n)
158 for (i = 0 ; i < n ; i++) {
169 function table_walk(curtag)
172 // console.log("wt: "+curtag.tagName);
173 if (curtag.tagName.toLowerCase() == "div" ||
174 curtag.tagName.toLowerCase() == "table" ||
175 curtag.tagName.toLowerCase() == "tbody") {
176 curtag = curtag.firstChild;
178 else if (curtag.tagName.toLowerCase() == "tr") {
179 if (curtag.firstChild != null)
180 curtag = curtag.firstChild;
181 else if (curtag.tagName != '')
182 curtag = curtag.nextSibling;
186 else if (curtag.tagName.toLowerCase() == "td") {
187 if (curtag.nextSibling != null)
188 curtag = curtag.nextSibling;
190 if (curtag.parentNode.nextSibling != null && curtag.parentNode.nextSibling.tagName != '')
191 curtag = curtag.parentNode.nextSibling;
199 } while (curtag != null && curtag.tagName.toLowerCase() != "td");
203 alert("outtag == null");
205 alert("outtag: "+curtag.tagName);
210 function j_stand_tdcont(el)
228 content += state_add(el[0]);
233 function j_stand_cont(ddata)
237 var st = 0, name = "";
242 if (g_listen & l_list_isol) {
245 for (i = 0, ii = 0 ; ii < ddata.length ; ii++) {
246 if ((ddata[ii][0] & 0x02) == 0) {
249 data[i++] = ddata[ii];
255 if (standup_data_old == null || data.length < 4) {
256 // if (standup_data_old == null) {
258 content = '<table cols="'+(data.length < 4 ? data.length : 4)+'" class="table_standup">';
259 for (i = 0 ; i < data.length ; i++) {
262 content += '<td id="'+i+'" class="room_standup">';
263 content += j_stand_tdcont(data[i]);
271 content += '</table>';
273 $("standup").innerHTML = content;
275 // console.log("inizio");
276 // for (i = 0 , curtag = table_walk($("standup")) ; curtag != null ; curtag = table_walk(curtag), i++ ) {
277 // console.log("inloop["+i+"]: "+curtag.tagName+" ID: "+curtag.id);
279 // console.log("fine "+i);
281 // walktable($("standup"), nextag);
282 // console.log($("standup").firstChild);
283 // console.log($("standup").firstChild.firstChild.firstChild.firstChild);
285 // log_walk($("standup"));
287 standup_data_old = data;
290 var idx_del, arr_add, idx_mod, arr_mod;
291 var idx_del_n = 0, idx_add_n = 0, idx_mod_n = 0;
293 var i_del, i_mod, i_add;
296 idx_del = new Array();
297 arr_add = new Array();
298 map_add = new Array();
299 idx_mod = new Array();
300 arr_mod = new Array();
301 map_cur = new Array();
303 // find removed entries
304 for (i = 0 ; i < standup_data_old.length ; i++) {
305 for (e = 0 ; e < data.length ; e++) {
306 if (standup_data_old[i][1] == data[e][1]) {
310 if (e == data.length) {
311 idx_del[idx_del_n++] = i;
315 /* modified entries */
316 if (standup_data_old[i][0] != data[e][0]) {
317 arr_mod[idx_mod_n] = data[e];
318 idx_mod[idx_mod_n++] = i;
325 for (e = 0 ; e < data.length ; e++) {
326 for (i = 0 ; i < standup_data_old.length ; i++) {
327 if (data[e][1] == standup_data_old[i][1] ) {
331 if (i == standup_data_old.length) {
332 // console.log("ADD: "+data[e][1]);
333 arr_add[idx_add_n] = data[e];
334 map_add[idx_add_n++] = e;
338 // TODO: qui travaso add in del
341 // alert("del: ["+j_stand_tdcont(standup_data_old[idx_del[i_del]])+"]");
342 for (i = 0 , i_del = 0, i_mod = 0, i_add = 0, curtag = table_walk($("standup")) ; curtag != null ; curtag = table_walk(curtag), i++ ) {
343 // console.log("cur.id: "+curtag.id);
345 // alert("i: "+i+" tagname: "+curtag.tagName+" innerHTML: ["+curtag.innerHTML+"]");
346 // console.log("inloop["+i+"]: "+curtag.tagName+" ID: "+curtag.id);
347 if (curtag.innerHTML == "") {
348 // console.log("innerHTML == none");
349 if (i_add < idx_add_n) {
350 // console.log(" to be new");
351 // console.log(" add: CONT:"+j_stand_tdcont(arr_add[i_add]));
352 curtag.innerHTML = j_stand_tdcont(arr_add[i_add]);
353 curtag.id = map_add[i_add];
358 // else if (i_del < idx_del_n && curtag.innerHTML == j_stand_tdcont(standup_data_old[idx_del[i_del]])) {
359 else if (i_del < idx_del_n && curtag.id == idx_del[i_del]) {
360 // console.log("to be cancel["+i+"]: ID: "+curtag.id);
361 if (i_add < idx_add_n) {
362 // console.log(" to be new");
363 // console.log(" add: CONT:"+j_stand_tdcont(arr_add[i_add]));
364 curtag.innerHTML = j_stand_tdcont(arr_add[i_add]);
365 curtag.id = map_add[i_add];
369 // console.log(" to be del");
370 curtag.innerHTML = "";
375 // else if (i_mod < idx_mod_n && curtag.innerHTML == j_stand_tdcont(standup_data_old[idx_mod[i_mod]])) {
376 else if (i_mod < idx_mod_n && curtag.id == idx_mod[i_mod]) {
377 // console.log(" to be mod");
378 // console.log("mod: "+idx_mod[i_mod]+ " CONT:"+j_stand_tdcont(arr_mod[i_mod]));
379 curtag.innerHTML = j_stand_tdcont(arr_mod[i_mod]);
380 curtag.id = map_cur[curtag.id];
384 curtag.id = map_cur[curtag.id];
386 // console.log("fineloop");
388 for (i ; i_add < idx_add_n ; i_add++, i++) {
389 // console.log("ADD: "+i+" arr_add: "+ arr_add[i_add][1]);
390 td = document.createElement("td");
391 td.className = "room_standup";
392 td.id = map_add[i_add];
393 td.innerHTML = j_stand_tdcont(arr_add[i_add]);
395 table_add($("standup"), td);
398 standup_data_old = data;
401 // $("esco").innerHTML = '<input class="button" name="logout" value="Esco." onclick="esco_cb();" type="button">';
405 window.onbeforeunload = null;
406 window.onunload = null;
413 function j_tab_cont(table_idx, data)
418 for (i = 0 ; i < data.length ; i++) {
419 if (data[i][0] & 0x01)
422 if (data[i][0] & 0x02)
425 content += data[i][1];
427 if (data[i][0] & 0x02)
430 if (data[i][0] & 0x01)
432 content += state_add(data[i][0]);
436 $("table"+table_idx).innerHTML = content;
439 function j_tab_act_cont(idx, act)
443 $("table_act"+idx).innerHTML = '<input type="button" class="button" name="xhenter'+idx+'" value="'+(g_lang == 'en' ? "Sit down." : "Mi siedo.")+'" onclick="act_sitdown('+idx+');">';
445 else if (act == 'sitreser') {
446 // <img class="nobo" title="tavolo riservato agli utenti registrati" style="display: inline; margin-right: 80px;" src="img/okauth.png">
448 $("table_act"+idx).innerHTML = '<input type="button" style="background-repeat: no-repeat; background-position: center; background-image: url(\'img/okauth.png\');" class="button" name="xhenter'+idx+'" value="'+(g_lang == 'en' ? "Sit down." : "Mi siedo.")+'" onclick="act_sitdown('+idx+');">';
450 else if (act == 'wake') {
452 $("table_act"+idx).innerHTML = '<input type="button" class="button" name="xwakeup" value="'+(g_lang == 'en' ? "Wake up." : "Mi alzo.")+'" onclick="act_wakeup();">';
454 else if (act == 'reserved') {
456 $("table_act"+idx).innerHTML = '<img class="nobo" title="'+(g_lang == 'en' ? "reserved table for authenticated users only" : "tavolo riservato agli utenti registrati")+'" style="margin-right: 20px;" src="img/onlyauth.png">';
459 $("table_act"+idx).innerHTML = '';
463 function j_login_manager(form)
467 if (form.elements['passid'].value == '')
471 // console.log("richiesta token");
473 token = server_request('mesg', 'getchallenge', 'cli_name', encodeURIComponent(form.elements['nameid'].value));
474 tokens = token.split('|');
476 // console.log('XX token: '+token);
477 // console.log(tokens);
481 token = calcMD5(tokens[1]+calcMD5(form.elements['passid'].value));
483 form.elements['passid_private'].value = token;
484 form.elements['passid'].value = ""; // FIXME da sost con la stessa len di A
492 function login_formtext_hilite()
494 formtext_hilite($("nameid"));
495 formtext_hilite($("passid"));
496 formsub_hilite($("sub"));
499 function login_init()
502 login_formtext_hilite();
505 function warrant_formtext_hilite(form)
508 formtext_hilite($("nameid"));
509 formtext_hilite($("emailid"));
510 formsub_hilite($("subid"));
511 formsub_hilite($("cloid"));
513 formtext_hilite(form.elements['name']);
514 formtext_hilite(form.elements['email']);
515 formsub_hilite(form.elements['sub']);
516 formsub_hilite(form.elements['clo']);
519 function mesgtoadm_formtext_hilite(form)
522 formtext_hilite($("subjid"));
523 formtext_hilite($("mesgid"));
524 formsub_hilite($("subid"));
525 formsub_hilite($("cloid"));
527 formtext_hilite(form.elements['subj']);
528 formtext_hilite(form.elements['mesg']);
529 formsub_hilite(form.elements['sub']);
530 formsub_hilite(form.elements['clo']);
534 function j_check_email(email)
536 if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email))
541 function j_authbox(form)
546 if (form.elements['realsub'].value == "chiudi") {
547 $('authbox').style.visibility = "hidden";
551 if (form.elements['name'].value == '' || j_check_email(form.elements['email'].value) == false) {
554 (g_lang == 'en' ? "<br><b>nickname</b> and/or <b>e-mail</b> fields are invalid;<br>please, fix them." :
555 "<br>I campi <b>nickname</b> e/o <b>e-mail</b> non sono validi;<br> correggeteli per favore."),
556 1, (g_lang == 'en' ? "close" : "chiudi"), 280, 100);
560 // submit the request
561 token = server_request('mesg', 'warranty',
562 'cli_name', encodeURIComponent(form.elements['name'].value),
563 'cli_email', encodeURIComponent(form.elements['email'].value) );
565 $('authbox').style.visibility = "hidden";
566 form.elements['name'].value = "";
567 form.elements['email'].value = "";
575 function authbox(w, h)
581 box.style.zIndex = 200;
582 box.style.width = w+"px";
583 box.style.marginLeft = -parseInt(w/2)+"px";
584 box.style.height = h+"px";
585 box.style.top = parseInt((document.body.clientHeight - h) / 2) + document.body.scrollTop;
587 warrant_formtext_hilite($('auth_form'));
589 box.style.visibility = "visible";
593 function j_mesgtoadmbox(form)
598 if (form.elements['realsub'].value == "chiudi") {
599 $('mesgtoadmbox').style.visibility = "hidden";
603 if (form.elements['mesg'].value == '' || form.elements['subj'].value == '') {
605 no = new notify(gst, (g_lang == 'en' ? "<br><b>subject</b> and the <b>message</b> cannot be void;<br>please, fix them." :
606 "<br>Il <b>soggetto</b> e il <b>messaggo</b> non possono essere vuoti;<br>correggeteli per favore."), 1,
607 (g_lang == 'en' ? "close" : "chiudi"), 280, 100);
611 // submit the request
612 token = server_request('mesg', 'mesgtoadm',
613 'cli_subj', encodeURIComponent(form.elements['subj'].value),
614 'cli_mesg', encodeURIComponent(form.elements['mesg'].value) );
616 $('mesgtoadmbox').style.visibility = "hidden";
617 form.elements['subj'].value = "";
618 form.elements['mesg'].value = "";
626 function mesgtoadmbox(w, h)
630 box = $('mesgtoadmbox');
632 box.style.zIndex = 200;
633 box.style.width = w+"px";
634 box.style.marginLeft = -parseInt(w/2)+"px";
635 box.style.height = h+"px";
636 box.style.top = parseInt((document.body.clientHeight - h) / 2) + document.body.scrollTop;
638 mesgtoadm_formtext_hilite($('mesgtoadm_form'));
640 box.style.visibility = "visible";
641 $('mesgtoadm_form').elements['subj'].focus();
644 function j_pollbox(form)
649 // submit the request
651 for (i = 0 ; i < form.elements.length ; i++) {
652 if (form.elements[i].checked == true)
655 if (i == form.elements.length) {
657 no = new notify(gst, (g_lang == 'en' ? "<br>You must choose ah item;<br> please, fix it." :
658 "<br>Non hai espresso nessuna preferenza;<br> correggi per favore."), 1,
659 (g_lang == 'en' ? "close" : "chiudi"), 280, 100);
663 choose = form.elements[i].value;
665 token = server_request('mesg', 'poll',
666 'cli_choose', encodeURIComponent(choose) );
669 // TODO: mesg to user
670 // $('mesgtoadmbox').style.visibility = "hidden";
681 function list_set(what, is_update, info)
683 // console.log(what);
686 var old_st = readCookie("CO_list");
688 if (what == 'auth') {
689 $('list_auth').style.color = 'red';
690 $('list_isol').style.color = 'black';
691 $('list_all').style.color = 'black';
692 if (old_st == 'isolation')
694 g_listen = l_list_auth;
696 else if (what == 'isolation') {
697 $('list_auth').style.color = 'black';
698 $('list_isol').style.color = 'red';
699 $('list_all').style.color = 'black';
700 if (old_st != 'isolation')
702 g_listen = l_list_isol;
705 $('list_auth').style.color = 'black';
706 $('list_isol').style.color = 'black';
707 $('list_all').style.color = 'red';
708 if (old_st == 'isolation')
710 g_listen = l_list_all;
713 set_checked_value($('ra_listen_auth'), what);
714 set_checked_value($('ra_listen_isol'), what);
715 set_checked_value($('ra_listen_all'), what);
717 $('list_info').innerHTML = info;
719 createCookie("CO_list", what, 24*365, cookiepath);
723 if (relo || !is_update) {
724 for (i = g_tables_auth_n ; i < g_tables_n ; i++) {
727 $('tr_noauth'+i).style.display = (what == 'isolation' ? 'none' : '');
730 $('td_noauth'+i).style.display = (what == 'isolation' ? 'none' : '');
732 if (what == 'isolation') {
740 // ricalculation of standup area
741 if (standup_data_old != null) {
742 standup_data = standup_data_old;
743 standup_data_old = null;
744 j_stand_cont(standup_data);
750 function sideslide(domobj, height, step)
755 this.domobj = domobj;
756 this.height = height;
762 sideslide.prototype = {
777 this.id = setTimeout(function () { instant.sideslide_cb(); }, this.twait);
780 sideslide_cb: function() {
783 if (this.st == 'wait') {
786 this.id = setInterval(function () { instant.sideslide_cb(); }, 100);
788 else if (this.st == 'scroll') {
789 this.scroll += (this.step / 10);
790 if (this.scroll >= this.height - this.step) {
793 this.domobj.scrollTop = this.scroll;
795 if (this.countdown == 0) {
798 this.id = setTimeout(function () { instant.sideslide_cb(); }, this.twait);
805 if (this.id != null) {
806 clearInterval(this.id);