4 * Copyright (C) 2006-2012 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)
36 var content = "", supercont = "";
37 var st, superst, name = "", supername = "", supersfx = "";
38 var tit = "", supertit = "";
41 if ((flags & 0xf00) != 0) {
43 // MLANG 4,12,16,20,24,28
47 tit = (g_lang == 'en' ? "I'm doing a break" : "sono in pausa");
51 tit = (g_lang == 'en' ? "I'm away" : "sono fuori");
55 tit = (g_lang == 'en' ? "Dog time" : "sono a spasso col cane");
59 tit = (g_lang == 'en' ? "I'm eating" : "sto mangiando");
63 tit = (g_lang == 'en' ? "I'm working" : "sono a lavoro");
67 tit = (g_lang == 'en' ? "I'm smoking a sigarett (and keeping a cancer)" : "sto fumando una sigaretta (e facendomi venire il cancro)");
71 tit = (g_lang == 'en' ? "I'm here!" : "sono presente!");
74 name = "st_rabbit.png";
75 tit = (g_lang == 'en' ? "Rabbit time" : "sono a spasso col coniglio");
78 name = "st_soccer.png";
79 tit = (g_lang == 'en' ? "Soccer time" : "c'รจ la partita!!");
83 tit = (g_lang == 'en' ? "Children time" : "ho il pupo da accudire");
87 tit = (g_lang == 'en' ? "Mop time" : "sto rassettando");
94 if ((flags & 0xf0000) != 0) {
95 superst = flags & 0xf0000;
102 supername = "superuser"+supersfx+".png";
103 supertit = (g_lang == 'en' ? "Brisk Supporter" : "Brisk Supporter");
108 if (supername != "") {
109 content += ' <img title="'+supertit+'" class="inline" src="img/'+supername+'">';
113 content += ' <img title="'+tit+'" class="inline" src="img/'+name+'">';
119 var standup_data_old = null;
122 // appendChild , removeChild
124 function table_add(curtag, td)
126 var tbody = null, tr, ct;
129 // console.log("wt: "+curtag.tagName);
131 if (curtag.tagName.toLowerCase() == "div" ||
132 curtag.tagName.toLowerCase() == "table") {
133 curtag = curtag.firstChild;
135 else if (curtag.tagName.toLowerCase() == "tbody") {
141 } while (curtag != null);
143 curtag = tbody.firstChild;
146 if (curtag.tagName.toLowerCase() == "tr") {
147 if (curtag.firstChild != null) {
148 curtag = curtag.firstChild;
152 curtag.appendChild(td);
156 else if (curtag.tagName.toLowerCase() == "td") {
157 if (curtag.nextSibling != null) {
158 curtag = curtag.nextSibling;
163 curtag.parentNode.appendChild(td);
168 curtag = curtag.parentNode.nextSibling;
173 curtag = curtag.parentNode;
176 } while (curtag != null);
178 tr = document.createElement("tr");
180 tbody.appendChild(tr);
185 function spcs(c1, c2, n)
190 for (i = 0 ; i < n ; i++) {
201 function table_walk(curtag)
204 // console.log("wt: "+curtag.tagName);
205 if (curtag.tagName.toLowerCase() == "div" ||
206 curtag.tagName.toLowerCase() == "table" ||
207 curtag.tagName.toLowerCase() == "tbody") {
208 curtag = curtag.firstChild;
210 else if (curtag.tagName.toLowerCase() == "tr") {
211 if (curtag.firstChild != null)
212 curtag = curtag.firstChild;
213 else if (curtag.tagName != '')
214 curtag = curtag.nextSibling;
218 else if (curtag.tagName.toLowerCase() == "td") {
219 if (curtag.nextSibling != null)
220 curtag = curtag.nextSibling;
222 if (curtag.parentNode.nextSibling != null && curtag.parentNode.nextSibling.tagName != '')
223 curtag = curtag.parentNode.nextSibling;
231 } while (curtag != null && curtag.tagName.toLowerCase() != "td");
235 alert("outtag == null");
237 alert("outtag: "+curtag.tagName);
242 function j_stand_tdcont(el)
244 return (user_dec_and_state(el));
247 function j_stand_cont(ddata)
251 var st = 0, name = "";
256 if (g_listen & l_list_isol) {
259 for (i = 0, ii = 0 ; ii < ddata.length ; ii++) {
260 if ((ddata[ii][0] & 0x02) == 0) {
263 data[i++] = ddata[ii];
269 if (standup_data_old == null || data.length < 4) {
270 // if (standup_data_old == null) {
272 content = '<table cols="'+(data.length < 4 ? data.length : 4)+'" class="table_standup">';
273 for (i = 0 ; i < data.length ; i++) {
276 content += '<td id="'+i+'" class="room_standup">';
277 content += j_stand_tdcont(data[i]);
285 content += '</table>';
287 $("standup").innerHTML = content;
289 // console.log("inizio");
290 // for (i = 0 , curtag = table_walk($("standup")) ; curtag != null ; curtag = table_walk(curtag), i++ ) {
291 // console.log("inloop["+i+"]: "+curtag.tagName+" ID: "+curtag.id);
293 // console.log("fine "+i);
295 // walktable($("standup"), nextag);
296 // console.log($("standup").firstChild);
297 // console.log($("standup").firstChild.firstChild.firstChild.firstChild);
299 // log_walk($("standup"));
301 standup_data_old = data;
304 var idx_del, arr_add, idx_mod, arr_mod;
305 var idx_del_n = 0, idx_add_n = 0, idx_mod_n = 0;
307 var i_del, i_mod, i_add;
310 idx_del = new Array();
311 arr_add = new Array();
312 map_add = new Array();
313 idx_mod = new Array();
314 arr_mod = new Array();
315 map_cur = new Array();
317 // find removed entries
318 for (i = 0 ; i < standup_data_old.length ; i++) {
319 for (e = 0 ; e < data.length ; e++) {
320 if (standup_data_old[i][1] == data[e][1]) {
324 if (e == data.length) {
325 idx_del[idx_del_n++] = i;
329 /* modified entries */
330 if (standup_data_old[i][0] != data[e][0]) {
331 arr_mod[idx_mod_n] = data[e];
332 idx_mod[idx_mod_n++] = i;
339 for (e = 0 ; e < data.length ; e++) {
340 for (i = 0 ; i < standup_data_old.length ; i++) {
341 if (data[e][1] == standup_data_old[i][1] ) {
345 if (i == standup_data_old.length) {
346 // console.log("ADD: "+data[e][1]);
347 arr_add[idx_add_n] = data[e];
348 map_add[idx_add_n++] = e;
352 // TODO: qui travaso add in del
355 // alert("del: ["+j_stand_tdcont(standup_data_old[idx_del[i_del]])+"]");
356 for (i = 0 , i_del = 0, i_mod = 0, i_add = 0, curtag = table_walk($("standup")) ; curtag != null ; curtag = table_walk(curtag), i++ ) {
357 // console.log("cur.id: "+curtag.id);
359 // alert("i: "+i+" tagname: "+curtag.tagName+" innerHTML: ["+curtag.innerHTML+"]");
360 // console.log("inloop["+i+"]: "+curtag.tagName+" ID: "+curtag.id);
361 if (curtag.innerHTML == "") {
362 // console.log("innerHTML == none");
363 if (i_add < idx_add_n) {
364 // console.log(" to be new");
365 // console.log(" add: CONT:"+j_stand_tdcont(arr_add[i_add]));
366 curtag.innerHTML = j_stand_tdcont(arr_add[i_add]);
367 curtag.id = map_add[i_add];
372 // else if (i_del < idx_del_n && curtag.innerHTML == j_stand_tdcont(standup_data_old[idx_del[i_del]])) {
373 else if (i_del < idx_del_n && curtag.id == idx_del[i_del]) {
374 // console.log("to be cancel["+i+"]: ID: "+curtag.id);
375 if (i_add < idx_add_n) {
376 // console.log(" to be new");
377 // console.log(" add: CONT:"+j_stand_tdcont(arr_add[i_add]));
378 curtag.innerHTML = j_stand_tdcont(arr_add[i_add]);
379 curtag.id = map_add[i_add];
383 // console.log(" to be del");
384 curtag.innerHTML = "";
389 // else if (i_mod < idx_mod_n && curtag.innerHTML == j_stand_tdcont(standup_data_old[idx_mod[i_mod]])) {
390 else if (i_mod < idx_mod_n && curtag.id == idx_mod[i_mod]) {
391 // console.log(" to be mod");
392 // console.log("mod: "+idx_mod[i_mod]+ " CONT:"+j_stand_tdcont(arr_mod[i_mod]));
393 curtag.innerHTML = j_stand_tdcont(arr_mod[i_mod]);
394 curtag.id = map_cur[curtag.id];
398 curtag.id = map_cur[curtag.id];
400 // console.log("fineloop");
402 for (i ; i_add < idx_add_n ; i_add++, i++) {
403 // console.log("ADD: "+i+" arr_add: "+ arr_add[i_add][1]);
404 td = document.createElement("td");
405 td.className = "room_standup";
406 td.id = map_add[i_add];
407 td.innerHTML = j_stand_tdcont(arr_add[i_add]);
409 table_add($("standup"), td);
412 standup_data_old = data;
415 // $("esco").innerHTML = '<input class="button" name="logout" value="Esco." onclick="esco_cb();" type="button">';
419 window.onbeforeunload = null;
420 window.onunload = null;
427 function j_tab_cont(table_idx, data)
432 for (i = 0 ; i < data.length ; i++) {
433 // content += user_decorator(data[i]);
434 // content += state_add(data[i][0]);
435 content += j_stand_tdcont(data[i]);
439 $("table"+table_idx).innerHTML = content;
442 function j_tab_act_cont(idx, act)
446 $("table_act"+idx).innerHTML = '<input type="button" class="button" name="xhenter'+idx+'" value="'+(g_lang == 'en' ? "Sit down." : "Mi siedo.")+'" onclick="act_sitdown('+idx+');">';
448 else if (act == 'sitreser') {
449 // <img class="nobo" title="tavolo riservato agli utenti registrati" style="display: inline; margin-right: 80px;" src="img/okauth.png">
451 $("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+');">';
453 else if (act == 'wake') {
455 $("table_act"+idx).innerHTML = '<input type="button" class="button" name="xwakeup" value="'+(g_lang == 'en' ? "Wake up." : "Mi alzo.")+'" onclick="act_wakeup();">';
457 else if (act == 'reserved') {
459 $("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">';
462 $("table_act"+idx).innerHTML = '';
466 function j_login_manager(form)
470 if (form.elements['passid'].value == '')
474 // console.log("richiesta token");
476 token = server_request('mesg', 'getchallenge', 'cli_name', encodeURIComponent(form.elements['nameid'].value));
477 tokens = token.split('|');
479 // console.log('XX token: '+token);
480 // console.log(tokens);
484 token = calcMD5(tokens[1]+calcMD5(form.elements['passid'].value));
486 form.elements['passid_private'].value = token;
487 form.elements['passid'].value = ""; // FIXME da sost con la stessa len di A
495 function login_formtext_hilite()
497 formtext_hilite($("nameid"));
498 formtext_hilite($("passid"));
499 formsub_hilite($("sub"));
502 function login_init()
505 login_formtext_hilite();
508 function warrant_formtext_hilite(form)
511 formtext_hilite($("nameid"));
512 formtext_hilite($("emailid"));
513 formsub_hilite($("subid"));
514 formsub_hilite($("cloid"));
516 formtext_hilite(form.elements['name']);
517 formtext_hilite(form.elements['email']);
518 formsub_hilite(form.elements['sub']);
519 formsub_hilite(form.elements['clo']);
522 function mesgtoadm_formtext_hilite(form)
525 formtext_hilite($("subjid"));
526 formtext_hilite($("mesgid"));
527 formsub_hilite($("subid"));
528 formsub_hilite($("cloid"));
530 formtext_hilite(form.elements['subj']);
531 formtext_hilite(form.elements['mesg']);
532 formsub_hilite(form.elements['sub']);
533 formsub_hilite(form.elements['clo']);
537 function j_check_email(email)
539 if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email))
544 function j_authbox(form)
549 if (form.elements['realsub'].value == "chiudi") {
550 $('authbox').style.visibility = "hidden";
554 if (form.elements['name'].value == '' || j_check_email(form.elements['email'].value) == false) {
557 (g_lang == 'en' ? "<br><b>nickname</b> and/or <b>e-mail</b> fields are invalid;<br>please, fix them." :
558 "<br>I campi <b>nickname</b> e/o <b>e-mail</b> non sono validi;<br> correggeteli per favore."),
559 1, (g_lang == 'en' ? "close" : "chiudi"), 280, 100);
563 // submit the request
564 token = server_request('mesg', 'warranty',
565 'cli_name', encodeURIComponent(form.elements['name'].value),
566 'cli_email', encodeURIComponent(form.elements['email'].value) );
568 $('authbox').style.visibility = "hidden";
569 form.elements['name'].value = "";
570 form.elements['email'].value = "";
578 function authbox(w, h)
584 box.style.zIndex = 200;
585 box.style.width = w+"px";
586 box.style.marginLeft = -parseInt(w/2)+"px";
587 box.style.height = h+"px";
588 box.style.top = parseInt((document.body.clientHeight - h) / 2) + document.body.scrollTop;
590 warrant_formtext_hilite($('auth_form'));
592 box.style.visibility = "visible";
596 function j_mesgtoadmbox(form)
601 if (form.elements['realsub'].value == "chiudi") {
602 $('mesgtoadmbox').style.visibility = "hidden";
606 if (form.elements['mesg'].value == '' || form.elements['subj'].value == '') {
608 no = new notify(gst, (g_lang == 'en' ? "<br><b>subject</b> and the <b>message</b> cannot be void;<br>please, fix them." :
609 "<br>Il <b>soggetto</b> e il <b>messaggo</b> non possono essere vuoti;<br>correggeteli per favore."), 1,
610 (g_lang == 'en' ? "close" : "chiudi"), 280, 100);
614 // submit the request
615 token = server_request('mesg', 'mesgtoadm',
616 'cli_subj', encodeURIComponent(form.elements['subj'].value),
617 'cli_mesg', encodeURIComponent(form.elements['mesg'].value) );
619 $('mesgtoadmbox').style.visibility = "hidden";
620 form.elements['subj'].value = "";
621 form.elements['mesg'].value = "";
629 function mesgtoadmbox(w, h)
633 box = $('mesgtoadmbox');
635 box.style.zIndex = 200;
636 box.style.width = w+"px";
637 box.style.marginLeft = -parseInt(w/2)+"px";
638 box.style.height = h+"px";
639 box.style.top = parseInt((document.body.clientHeight - h) / 2) + document.body.scrollTop;
641 mesgtoadm_formtext_hilite($('mesgtoadm_form'));
643 box.style.visibility = "visible";
644 $('mesgtoadm_form').elements['subj'].focus();
647 function j_pollbox(form)
652 // submit the request
654 for (i = 0 ; i < form.elements.length ; i++) {
655 if (form.elements[i].checked == true)
658 if (i == form.elements.length) {
660 no = new notify(gst, (g_lang == 'en' ? "<br>You must choose ah item;<br> please, fix it." :
661 "<br>Non hai espresso nessuna preferenza;<br> correggi per favore."), 1,
662 (g_lang == 'en' ? "close" : "chiudi"), 280, 100);
666 choose = form.elements[i].value;
668 token = server_request('mesg', 'poll',
669 'cli_choose', encodeURIComponent(choose) );
672 // TODO: mesg to user
673 // $('mesgtoadmbox').style.visibility = "hidden";
684 function list_set(what, is_update, info)
686 // console.log(what);
689 var old_st = readCookie("CO_list");
691 if (what == 'auth') {
692 $('list_auth').style.color = 'red';
693 $('list_isol').style.color = 'black';
694 $('list_all').style.color = 'black';
695 if (old_st == 'isolation')
697 g_listen = l_list_auth;
699 else if (what == 'isolation') {
700 $('list_auth').style.color = 'black';
701 $('list_isol').style.color = 'red';
702 $('list_all').style.color = 'black';
703 if (old_st != 'isolation')
705 g_listen = l_list_isol;
708 $('list_auth').style.color = 'black';
709 $('list_isol').style.color = 'black';
710 $('list_all').style.color = 'red';
711 if (old_st == 'isolation')
713 g_listen = l_list_all;
716 set_checked_value($('ra_listen_auth'), what);
717 set_checked_value($('ra_listen_isol'), what);
718 set_checked_value($('ra_listen_all'), what);
720 $('list_info').innerHTML = info;
722 createCookie("CO_list", what, 24*365, cookiepath);
726 if (relo || !is_update) {
727 for (i = g_tables_auth_n ; i < g_tables_n ; i++) {
730 $('tr_noauth'+i).style.display = (what == 'isolation' ? 'none' : '');
733 $('td_noauth'+i).style.display = (what == 'isolation' ? 'none' : '');
735 if (what == 'isolation') {
743 // ricalculation of standup area
744 if (standup_data_old != null) {
745 standup_data = standup_data_old;
746 standup_data_old = null;
747 j_stand_cont(standup_data);
753 function sideslide(domobj, height, step)
758 this.domobj = domobj;
759 this.height = height;
765 sideslide.prototype = {
780 this.id = setTimeout(function () { instant.sideslide_cb(); }, this.twait);
783 sideslide_cb: function() {
786 if (this.st == 'wait') {
789 this.id = setInterval(function () { instant.sideslide_cb(); }, 100);
791 else if (this.st == 'scroll') {
792 this.scroll += (this.step / 10);
793 if (this.scroll >= this.height - this.step) {
796 this.domobj.scrollTop = this.scroll;
798 if (this.countdown == 0) {
801 this.id = setTimeout(function () { instant.sideslide_cb(); }, this.twait);
808 if (this.id != null) {
809 clearInterval(this.id);