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!");
76 content += ' <img title="'+tit+'" class="unbo" src="img/'+name+'">';
83 var standup_data_old = null;
86 // appendChild , removeChild
88 function table_add(curtag, td)
93 // console.log("wt: "+curtag.tagName);
95 if (curtag.tagName.toLowerCase() == "div" ||
96 curtag.tagName.toLowerCase() == "table") {
97 curtag = curtag.firstChild;
99 else if (curtag.tagName.toLowerCase() == "tbody") {
105 } while (curtag != null);
107 curtag = tbody.firstChild;
110 if (curtag.tagName.toLowerCase() == "tr") {
111 if (curtag.firstChild != null) {
112 curtag = curtag.firstChild;
116 curtag.appendChild(td);
120 else if (curtag.tagName.toLowerCase() == "td") {
121 if (curtag.nextSibling != null) {
122 curtag = curtag.nextSibling;
127 curtag.parentNode.appendChild(td);
132 curtag = curtag.parentNode.nextSibling;
137 curtag = curtag.parentNode;
140 } while (curtag != null);
142 tr = document.createElement("tr");
144 tbody.appendChild(tr);
149 function spcs(c1, c2, n)
154 for (i = 0 ; i < n ; i++) {
165 function table_walk(curtag)
168 // console.log("wt: "+curtag.tagName);
169 if (curtag.tagName.toLowerCase() == "div" ||
170 curtag.tagName.toLowerCase() == "table" ||
171 curtag.tagName.toLowerCase() == "tbody") {
172 curtag = curtag.firstChild;
174 else if (curtag.tagName.toLowerCase() == "tr") {
175 if (curtag.firstChild != null)
176 curtag = curtag.firstChild;
177 else if (curtag.tagName != '')
178 curtag = curtag.nextSibling;
182 else if (curtag.tagName.toLowerCase() == "td") {
183 if (curtag.nextSibling != null)
184 curtag = curtag.nextSibling;
186 if (curtag.parentNode.nextSibling != null && curtag.parentNode.nextSibling.tagName != '')
187 curtag = curtag.parentNode.nextSibling;
195 } while (curtag != null && curtag.tagName.toLowerCase() != "td");
199 alert("outtag == null");
201 alert("outtag: "+curtag.tagName);
206 function j_stand_tdcont(el)
224 content += state_add(el[0]);
229 function j_stand_cont(ddata)
233 var st = 0, name = "";
238 if (g_listen & l_list_isol) {
241 for (i = 0, ii = 0 ; ii < ddata.length ; ii++) {
242 if ((ddata[ii][0] & 0x02) == 0) {
245 data[i++] = ddata[ii];
251 if (standup_data_old == null || data.length < 4) {
252 // if (standup_data_old == null) {
254 content = '<table cols="'+(data.length < 4 ? data.length : 4)+'" class="table_standup">';
255 for (i = 0 ; i < data.length ; i++) {
258 content += '<td id="'+i+'" class="room_standup">';
259 content += j_stand_tdcont(data[i]);
267 content += '</table>';
269 $("standup").innerHTML = content;
271 // console.log("inizio");
272 // for (i = 0 , curtag = table_walk($("standup")) ; curtag != null ; curtag = table_walk(curtag), i++ ) {
273 // console.log("inloop["+i+"]: "+curtag.tagName+" ID: "+curtag.id);
275 // console.log("fine "+i);
277 // walktable($("standup"), nextag);
278 // console.log($("standup").firstChild);
279 // console.log($("standup").firstChild.firstChild.firstChild.firstChild);
281 // log_walk($("standup"));
283 standup_data_old = data;
286 var idx_del, arr_add, idx_mod, arr_mod;
287 var idx_del_n = 0, idx_add_n = 0, idx_mod_n = 0;
289 var i_del, i_mod, i_add;
292 idx_del = new Array();
293 arr_add = new Array();
294 map_add = new Array();
295 idx_mod = new Array();
296 arr_mod = new Array();
297 map_cur = new Array();
299 // find removed entries
300 for (i = 0 ; i < standup_data_old.length ; i++) {
301 for (e = 0 ; e < data.length ; e++) {
302 if (standup_data_old[i][1] == data[e][1]) {
306 if (e == data.length) {
307 idx_del[idx_del_n++] = i;
311 /* modified entries */
312 if (standup_data_old[i][0] != data[e][0]) {
313 arr_mod[idx_mod_n] = data[e];
314 idx_mod[idx_mod_n++] = i;
321 for (e = 0 ; e < data.length ; e++) {
322 for (i = 0 ; i < standup_data_old.length ; i++) {
323 if (data[e][1] == standup_data_old[i][1] ) {
327 if (i == standup_data_old.length) {
328 // console.log("ADD: "+data[e][1]);
329 arr_add[idx_add_n] = data[e];
330 map_add[idx_add_n++] = e;
334 // TODO: qui travaso add in del
337 // alert("del: ["+j_stand_tdcont(standup_data_old[idx_del[i_del]])+"]");
338 for (i = 0 , i_del = 0, i_mod = 0, i_add = 0, curtag = table_walk($("standup")) ; curtag != null ; curtag = table_walk(curtag), i++ ) {
339 // console.log("cur.id: "+curtag.id);
341 // alert("i: "+i+" tagname: "+curtag.tagName+" innerHTML: ["+curtag.innerHTML+"]");
342 // console.log("inloop["+i+"]: "+curtag.tagName+" ID: "+curtag.id);
343 if (curtag.innerHTML == "") {
344 // console.log("innerHTML == none");
345 if (i_add < idx_add_n) {
346 // console.log(" to be new");
347 // console.log(" add: CONT:"+j_stand_tdcont(arr_add[i_add]));
348 curtag.innerHTML = j_stand_tdcont(arr_add[i_add]);
349 curtag.id = map_add[i_add];
354 // else if (i_del < idx_del_n && curtag.innerHTML == j_stand_tdcont(standup_data_old[idx_del[i_del]])) {
355 else if (i_del < idx_del_n && curtag.id == idx_del[i_del]) {
356 // console.log("to be cancel["+i+"]: ID: "+curtag.id);
357 if (i_add < idx_add_n) {
358 // console.log(" to be new");
359 // console.log(" add: CONT:"+j_stand_tdcont(arr_add[i_add]));
360 curtag.innerHTML = j_stand_tdcont(arr_add[i_add]);
361 curtag.id = map_add[i_add];
365 // console.log(" to be del");
366 curtag.innerHTML = "";
371 // else if (i_mod < idx_mod_n && curtag.innerHTML == j_stand_tdcont(standup_data_old[idx_mod[i_mod]])) {
372 else if (i_mod < idx_mod_n && curtag.id == idx_mod[i_mod]) {
373 // console.log(" to be mod");
374 // console.log("mod: "+idx_mod[i_mod]+ " CONT:"+j_stand_tdcont(arr_mod[i_mod]));
375 curtag.innerHTML = j_stand_tdcont(arr_mod[i_mod]);
376 curtag.id = map_cur[curtag.id];
380 curtag.id = map_cur[curtag.id];
382 // console.log("fineloop");
384 for (i ; i_add < idx_add_n ; i_add++, i++) {
385 // console.log("ADD: "+i+" arr_add: "+ arr_add[i_add][1]);
386 td = document.createElement("td");
387 td.className = "room_standup";
388 td.id = map_add[i_add];
389 td.innerHTML = j_stand_tdcont(arr_add[i_add]);
391 table_add($("standup"), td);
394 standup_data_old = data;
397 // $("esco").innerHTML = '<input class="button" name="logout" value="Esco." onclick="esco_cb();" type="button">';
401 window.onbeforeunload = null;
402 window.onunload = null;
409 function j_tab_cont(table_idx, data)
414 for (i = 0 ; i < data.length ; i++) {
415 if (data[i][0] & 0x01)
418 if (data[i][0] & 0x02)
421 content += data[i][1];
423 if (data[i][0] & 0x02)
426 if (data[i][0] & 0x01)
428 content += state_add(data[i][0]);
432 $("table"+table_idx).innerHTML = content;
435 function j_tab_act_cont(idx, act)
439 $("table_act"+idx).innerHTML = '<input type="button" class="button" name="xhenter'+idx+'" value="'+(g_lang == 'en' ? "Sit down." : "Mi siedo.")+'" onclick="act_sitdown('+idx+');">';
441 else if (act == 'sitreser') {
442 // <img class="nobo" title="tavolo riservato agli utenti registrati" style="display: inline; margin-right: 80px;" src="img/okauth.png">
444 $("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+');">';
446 else if (act == 'wake') {
448 $("table_act"+idx).innerHTML = '<input type="button" class="button" name="xwakeup" value="'+(g_lang == 'en' ? "Wake up." : "Mi alzo.")+'" onclick="act_wakeup();">';
450 else if (act == 'reserved') {
452 $("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">';
455 $("table_act"+idx).innerHTML = '';
459 function j_login_manager(form)
463 if (form.elements['passid'].value == '')
467 // console.log("richiesta token");
469 token = server_request('mesg', 'getchallenge', 'cli_name', encodeURIComponent(form.elements['nameid'].value));
470 tokens = token.split('|');
472 // console.log('XX token: '+token);
473 // console.log(tokens);
477 token = calcMD5(tokens[1]+calcMD5(form.elements['passid'].value));
479 form.elements['passid_private'].value = token;
480 form.elements['passid'].value = ""; // FIXME da sost con la stessa len di A
488 function login_formtext_hilite()
490 formtext_hilite($("nameid"));
491 formtext_hilite($("passid"));
492 formsub_hilite($("sub"));
495 function login_init()
498 login_formtext_hilite();
501 function warrant_formtext_hilite(form)
504 formtext_hilite($("nameid"));
505 formtext_hilite($("emailid"));
506 formsub_hilite($("subid"));
507 formsub_hilite($("cloid"));
509 formtext_hilite(form.elements['name']);
510 formtext_hilite(form.elements['email']);
511 formsub_hilite(form.elements['sub']);
512 formsub_hilite(form.elements['clo']);
515 function mesgtoadm_formtext_hilite(form)
518 formtext_hilite($("subjid"));
519 formtext_hilite($("mesgid"));
520 formsub_hilite($("subid"));
521 formsub_hilite($("cloid"));
523 formtext_hilite(form.elements['subj']);
524 formtext_hilite(form.elements['mesg']);
525 formsub_hilite(form.elements['sub']);
526 formsub_hilite(form.elements['clo']);
530 function j_check_email(email)
532 if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email))
537 function j_authbox(form)
542 if (form.elements['realsub'].value == "chiudi") {
543 $('authbox').style.visibility = "hidden";
547 if (form.elements['name'].value == '' || j_check_email(form.elements['email'].value) == false) {
550 (g_lang == 'en' ? "<br><b>nickname</b> and/or <b>e-mail</b> fields are invalid;<br>please, fix them." :
551 "<br>I campi <b>nickname</b> e/o <b>e-mail</b> non sono validi;<br> correggeteli per favore."),
552 1, (g_lang == 'en' ? "close" : "chiudi"), 280, 100);
556 // submit the request
557 token = server_request('mesg', 'warranty',
558 'cli_name', encodeURIComponent(form.elements['name'].value),
559 'cli_email', encodeURIComponent(form.elements['email'].value) );
561 $('authbox').style.visibility = "hidden";
562 form.elements['name'].value = "";
563 form.elements['email'].value = "";
571 function authbox(w, h)
577 box.style.zIndex = 200;
578 box.style.width = w+"px";
579 box.style.marginLeft = -parseInt(w/2)+"px";
580 box.style.height = h+"px";
581 box.style.top = parseInt((document.body.clientHeight - h) / 2) + document.body.scrollTop;
583 warrant_formtext_hilite($('auth_form'));
585 box.style.visibility = "visible";
589 function j_mesgtoadmbox(form)
594 if (form.elements['realsub'].value == "chiudi") {
595 $('mesgtoadmbox').style.visibility = "hidden";
599 if (form.elements['mesg'].value == '' || form.elements['subj'].value == '') {
601 no = new notify(gst, (g_lang == 'en' ? "<br><b>subject</b> and the <b>message</b> cannot be void;<br>please, fix them." :
602 "<br>Il <b>soggetto</b> e il <b>messaggo</b> non possono essere vuoti;<br>correggeteli per favore."), 1,
603 (g_lang == 'en' ? "close" : "chiudi"), 280, 100);
607 // submit the request
608 token = server_request('mesg', 'mesgtoadm',
609 'cli_subj', encodeURIComponent(form.elements['subj'].value),
610 'cli_mesg', encodeURIComponent(form.elements['mesg'].value) );
612 $('mesgtoadmbox').style.visibility = "hidden";
613 form.elements['subj'].value = "";
614 form.elements['mesg'].value = "";
622 function mesgtoadmbox(w, h)
626 box = $('mesgtoadmbox');
628 box.style.zIndex = 200;
629 box.style.width = w+"px";
630 box.style.marginLeft = -parseInt(w/2)+"px";
631 box.style.height = h+"px";
632 box.style.top = parseInt((document.body.clientHeight - h) / 2) + document.body.scrollTop;
634 mesgtoadm_formtext_hilite($('mesgtoadm_form'));
636 box.style.visibility = "visible";
637 $('mesgtoadm_form').elements['subj'].focus();
640 function j_pollbox(form)
645 // submit the request
647 for (i = 0 ; i < form.elements.length ; i++) {
648 if (form.elements[i].checked == true)
651 if (i == form.elements.length) {
653 no = new notify(gst, (g_lang == 'en' ? "<br>You must choose ah item;<br> please, fix it." :
654 "<br>Non hai espresso nessuna preferenza;<br> correggi per favore."), 1,
655 (g_lang == 'en' ? "close" : "chiudi"), 280, 100);
659 choose = form.elements[i].value;
661 token = server_request('mesg', 'poll',
662 'cli_choose', encodeURIComponent(choose) );
665 // TODO: mesg to user
666 // $('mesgtoadmbox').style.visibility = "hidden";
677 function list_set(what, is_update, info)
679 // console.log(what);
682 var old_st = readCookie("CO_list");
684 if (what == 'auth') {
685 $('list_auth').style.color = 'red';
686 $('list_isol').style.color = 'black';
687 $('list_all').style.color = 'black';
688 if (old_st == 'isolation')
690 g_listen = l_list_auth;
692 else if (what == 'isolation') {
693 $('list_auth').style.color = 'black';
694 $('list_isol').style.color = 'red';
695 $('list_all').style.color = 'black';
696 if (old_st != 'isolation')
698 g_listen = l_list_isol;
701 $('list_auth').style.color = 'black';
702 $('list_isol').style.color = 'black';
703 $('list_all').style.color = 'red';
704 if (old_st == 'isolation')
706 g_listen = l_list_all;
708 $('list_info').innerHTML = info;
710 createCookie("CO_list", what, 24*365, cookiepath);
714 if (relo || !is_update) {
715 for (i = g_tables_auth_n ; i < g_tables_n ; i++) {
718 $('tr_noauth'+i).style.display = (what == 'isolation' ? 'none' : '');
721 $('td_noauth'+i).style.display = (what == 'isolation' ? 'none' : '');
723 // ricalculation of standup area
724 if (standup_data_old != null) {
725 standup_data = standup_data_old;
726 standup_data_old = null;
727 j_stand_cont(standup_data);
732 function sideslide(domobj, height, step)
737 this.domobj = domobj;
738 this.height = height;
744 sideslide.prototype = {
759 this.id = setTimeout(function () { instant.sideslide_cb(); }, this.twait);
762 sideslide_cb: function() {
765 if (this.st == 'wait') {
768 this.id = setInterval(function () { instant.sideslide_cb(); }, 100);
770 else if (this.st == 'scroll') {
771 this.scroll += (this.step / 10);
772 if (this.scroll >= this.height - this.step) {
775 this.domobj.scrollTop = this.scroll;
777 if (this.countdown == 0) {
780 this.id = setTimeout(function () { instant.sideslide_cb(); }, this.twait);
787 if (this.id != null) {
788 clearInterval(this.id);