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 function state_add(flags)
36 if ((flags & 0xf00) != 0) {
38 // MLANG 4,12,16,20,24,28
42 tit = (g_lang == 'en' ? "I'm doing a break" : "sono in pausa");
46 tit = (g_lang == 'en' ? "I'm away" : "sono fuori");
50 tit = (g_lang == 'en' ? "Dog time" : "sono a spasso col cane");
54 tit = (g_lang == 'en' ? "I'm eating" : "sto mangiando");
58 tit = (g_lang == 'en' ? "I'm working" : "sono a lavoro");
62 tit = (g_lang == 'en' ? "I'm smoking a sigarett (and keeping a cancer)" : "sto fumando una sigaretta (e facendomi venire il cancro)");
66 tit = (g_lang == 'en' ? "I'm here!" : "sono presente!");
72 content += ' <img title="'+tit+'" class="unbo" src="img/'+name+'">';
79 var standup_data_old = null;
82 // appendChild , removeChild
84 function table_add(curtag, td)
89 // console.log("wt: "+curtag.tagName);
91 if (curtag.tagName.toLowerCase() == "div" ||
92 curtag.tagName.toLowerCase() == "table") {
93 curtag = curtag.firstChild;
95 else if (curtag.tagName.toLowerCase() == "tbody") {
101 } while (curtag != null);
103 curtag = tbody.firstChild;
106 if (curtag.tagName.toLowerCase() == "tr") {
107 if (curtag.firstChild != null) {
108 curtag = curtag.firstChild;
112 curtag.appendChild(td);
116 else if (curtag.tagName.toLowerCase() == "td") {
117 if (curtag.nextSibling != null) {
118 curtag = curtag.nextSibling;
123 curtag.parentNode.appendChild(td);
128 curtag = curtag.parentNode.nextSibling;
133 curtag = curtag.parentNode;
136 } while (curtag != null);
138 tr = document.createElement("tr");
140 tbody.appendChild(tr);
145 function spcs(c1, c2, n)
150 for (i = 0 ; i < n ; i++) {
161 function table_walk(curtag)
164 // console.log("wt: "+curtag.tagName);
165 if (curtag.tagName.toLowerCase() == "div" ||
166 curtag.tagName.toLowerCase() == "table" ||
167 curtag.tagName.toLowerCase() == "tbody") {
168 curtag = curtag.firstChild;
170 else if (curtag.tagName.toLowerCase() == "tr") {
171 if (curtag.firstChild != null)
172 curtag = curtag.firstChild;
173 else if (curtag.tagName != '')
174 curtag = curtag.nextSibling;
178 else if (curtag.tagName.toLowerCase() == "td") {
179 if (curtag.nextSibling != null)
180 curtag = curtag.nextSibling;
182 if (curtag.parentNode.nextSibling != null && curtag.parentNode.nextSibling.tagName != '')
183 curtag = curtag.parentNode.nextSibling;
191 } while (curtag != null && curtag.tagName.toLowerCase() != "td");
195 alert("outtag == null");
197 alert("outtag: "+curtag.tagName);
202 function j_stand_tdcont(el)
220 content += state_add(el[0]);
225 function j_stand_cont(data)
229 var st = 0, name = "";
232 if (standup_data_old == null || data.length < 4) {
233 // if (standup_data_old == null) {
235 content = '<table cols="'+(data.length < 4 ? data.length : 4)+'" class="table_standup">';
236 for (i = 0 ; i < data.length ; i++) {
239 content += '<td id="'+i+'" class="room_standup">';
240 content += j_stand_tdcont(data[i]);
246 content += '</table>';
248 $("standup").innerHTML = content;
250 // console.log("inizio");
251 // for (i = 0 , curtag = table_walk($("standup")) ; curtag != null ; curtag = table_walk(curtag), i++ ) {
252 // console.log("inloop["+i+"]: "+curtag.tagName+" ID: "+curtag.id);
254 // console.log("fine "+i);
256 // walktable($("standup"), nextag);
257 // console.log($("standup").firstChild);
258 // console.log($("standup").firstChild.firstChild.firstChild.firstChild);
260 // log_walk($("standup"));
262 standup_data_old = data;
265 var idx_del, arr_add, idx_mod, arr_mod;
266 var idx_del_n = 0, idx_add_n = 0, idx_mod_n = 0;
268 var i_del, i_mod, i_add;
271 idx_del = new Array();
272 arr_add = new Array();
273 map_add = new Array();
274 idx_mod = new Array();
275 arr_mod = new Array();
276 map_cur = new Array();
278 // find removed entries
279 for (i = 0 ; i < standup_data_old.length ; i++) {
280 for (e = 0 ; e < data.length ; e++) {
281 if (standup_data_old[i][1] == data[e][1]) {
285 if (e == data.length) {
286 idx_del[idx_del_n++] = i;
290 /* modified entries */
291 if (standup_data_old[i][0] != data[e][0]) {
292 arr_mod[idx_mod_n] = data[e];
293 idx_mod[idx_mod_n++] = i;
300 for (e = 0 ; e < data.length ; e++) {
301 for (i = 0 ; i < standup_data_old.length ; i++) {
302 if (data[e][1] == standup_data_old[i][1] ) {
306 if (i == standup_data_old.length) {
307 // console.log("ADD: "+data[e][1]);
308 arr_add[idx_add_n] = data[e];
309 map_add[idx_add_n++] = e;
313 // TODO: qui travaso add in del
316 // alert("del: ["+j_stand_tdcont(standup_data_old[idx_del[i_del]])+"]");
317 for (i = 0 , i_del = 0, i_mod = 0, i_add = 0, curtag = table_walk($("standup")) ; curtag != null ; curtag = table_walk(curtag), i++ ) {
318 // console.log("cur.id: "+curtag.id);
320 // alert("i: "+i+" tagname: "+curtag.tagName+" innerHTML: ["+curtag.innerHTML+"]");
321 // console.log("inloop["+i+"]: "+curtag.tagName+" ID: "+curtag.id);
322 if (curtag.innerHTML == "") {
323 // console.log("innerHTML == none");
324 if (i_add < idx_add_n) {
325 // console.log(" to be new");
326 // console.log(" add: CONT:"+j_stand_tdcont(arr_add[i_add]));
327 curtag.innerHTML = j_stand_tdcont(arr_add[i_add]);
328 curtag.id = map_add[i_add];
333 // else if (i_del < idx_del_n && curtag.innerHTML == j_stand_tdcont(standup_data_old[idx_del[i_del]])) {
334 else if (i_del < idx_del_n && curtag.id == idx_del[i_del]) {
335 // console.log("to be cancel["+i+"]: ID: "+curtag.id);
336 if (i_add < idx_add_n) {
337 // console.log(" to be new");
338 // console.log(" add: CONT:"+j_stand_tdcont(arr_add[i_add]));
339 curtag.innerHTML = j_stand_tdcont(arr_add[i_add]);
340 curtag.id = map_add[i_add];
344 // console.log(" to be del");
345 curtag.innerHTML = "";
350 // else if (i_mod < idx_mod_n && curtag.innerHTML == j_stand_tdcont(standup_data_old[idx_mod[i_mod]])) {
351 else if (i_mod < idx_mod_n && curtag.id == idx_mod[i_mod]) {
352 // console.log(" to be mod");
353 // console.log("mod: "+idx_mod[i_mod]+ " CONT:"+j_stand_tdcont(arr_mod[i_mod]));
354 curtag.innerHTML = j_stand_tdcont(arr_mod[i_mod]);
355 curtag.id = map_cur[curtag.id];
359 curtag.id = map_cur[curtag.id];
361 // console.log("fineloop");
363 for (i ; i_add < idx_add_n ; i_add++, i++) {
364 // console.log("ADD: "+i+" arr_add: "+ arr_add[i_add][1]);
365 td = document.createElement("td");
366 td.className = "room_standup";
367 td.id = map_add[i_add];
368 td.innerHTML = j_stand_tdcont(arr_add[i_add]);
370 table_add($("standup"), td);
373 standup_data_old = data;
376 // $("esco").innerHTML = '<input class="button" name="logout" value="Esco." onclick="esco_cb();" type="button">';
380 window.onbeforeunload = null;
381 window.onunload = null;
388 function j_tab_cont(table_idx, data)
393 for (i = 0 ; i < data.length ; i++) {
394 if (data[i][0] & 0x01)
397 if (data[i][0] & 0x02)
400 content += data[i][1];
402 if (data[i][0] & 0x02)
405 if (data[i][0] & 0x01)
407 content += state_add(data[i][0]);
411 $("table"+table_idx).innerHTML = content;
414 function j_tab_act_cont(idx, act)
418 $("table_act"+idx).innerHTML = '<input type="button" class="button" name="xhenter'+idx+'" value="'+(g_lang == 'en' ? "Sit down." : "Mi siedo.")+'" onclick="act_sitdown('+idx+');">';
420 else if (act == 'sitreser') {
421 // <img class="nobo" title="tavolo riservato agli utenti registrati" style="display: inline; margin-right: 80px;" src="img/okauth.png">
423 $("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+');">';
425 else if (act == 'wake') {
427 $("table_act"+idx).innerHTML = '<input type="button" class="button" name="xwakeup" value="'+(g_lang == 'en' ? "Wake up." : "Mi alzo.")+'" onclick="act_wakeup();">';
429 else if (act == 'reserved') {
431 $("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">';
434 $("table_act"+idx).innerHTML = '';
438 function j_login_manager(form)
442 if (form.elements['passid'].value == '')
446 // console.log("richiesta token");
448 token = server_request('mesg', 'getchallenge', 'cli_name', encodeURIComponent(form.elements['nameid'].value));
449 tokens = token.split('|');
451 // console.log('XX token: '+token);
452 // console.log(tokens);
456 token = calcMD5(tokens[1]+calcMD5(form.elements['passid'].value));
458 form.elements['passid_private'].value = token;
459 form.elements['passid'].value = ""; // FIXME da sost con la stessa len di A
467 function login_formtext_hilite()
469 formtext_hilite($("nameid"));
470 formtext_hilite($("passid"));
471 formsub_hilite($("sub"));
474 function login_init()
477 login_formtext_hilite();
480 function warrant_formtext_hilite(form)
483 formtext_hilite($("nameid"));
484 formtext_hilite($("emailid"));
485 formsub_hilite($("subid"));
486 formsub_hilite($("cloid"));
488 formtext_hilite(form.elements['name']);
489 formtext_hilite(form.elements['email']);
490 formsub_hilite(form.elements['sub']);
491 formsub_hilite(form.elements['clo']);
494 function mesgtoadm_formtext_hilite(form)
497 formtext_hilite($("subjid"));
498 formtext_hilite($("mesgid"));
499 formsub_hilite($("subid"));
500 formsub_hilite($("cloid"));
502 formtext_hilite(form.elements['subj']);
503 formtext_hilite(form.elements['mesg']);
504 formsub_hilite(form.elements['sub']);
505 formsub_hilite(form.elements['clo']);
509 function j_check_email(email)
511 if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email))
516 function j_authbox(form)
521 if (form.elements['realsub'].value == "chiudi") {
522 $('authbox').style.visibility = "hidden";
526 if (form.elements['name'].value == '' || j_check_email(form.elements['email'].value) == false) {
529 (g_lang == 'en' ? "<br><b>nickname</b> and/or <b>e-mail</b> fields are invalid;<br>please, fix them." :
530 "<br>I campi <b>nickname</b> e/o <b>e-mail</b> non sono validi;<br> correggeteli per favore."),
531 1, (g_lang == 'en' ? "close" : "chiudi"), 280, 100);
535 // submit the request
536 token = server_request('mesg', 'warranty',
537 'cli_name', encodeURIComponent(form.elements['name'].value),
538 'cli_email', encodeURIComponent(form.elements['email'].value) );
540 $('authbox').style.visibility = "hidden";
541 form.elements['name'].value = "";
542 form.elements['email'].value = "";
550 function authbox(w, h)
556 box.style.zIndex = 200;
557 box.style.width = w+"px";
558 box.style.marginLeft = -parseInt(w/2)+"px";
559 box.style.height = h+"px";
560 box.style.top = parseInt((document.body.clientHeight - h) / 2) + document.body.scrollTop;
562 warrant_formtext_hilite($('auth_form'));
564 box.style.visibility = "visible";
568 function j_mesgtoadmbox(form)
573 if (form.elements['realsub'].value == "chiudi") {
574 $('mesgtoadmbox').style.visibility = "hidden";
578 if (form.elements['mesg'].value == '' || form.elements['subj'].value == '') {
580 no = new notify(gst, (g_lang == 'en' ? "<br><b>subject</b> and the <b>message</b> cannot be void;<br>please, fix them." :
581 "<br>Il <b>soggetto</b> e il <b>messaggo</b> non possono essere vuoti;<br>correggeteli per favore."), 1,
582 (g_lang == 'en' ? "close" : "chiudi"), 280, 100);
586 // submit the request
587 token = server_request('mesg', 'mesgtoadm',
588 'cli_subj', encodeURIComponent(form.elements['subj'].value),
589 'cli_mesg', encodeURIComponent(form.elements['mesg'].value) );
591 $('mesgtoadmbox').style.visibility = "hidden";
592 form.elements['subj'].value = "";
593 form.elements['mesg'].value = "";
601 function mesgtoadmbox(w, h)
605 box = $('mesgtoadmbox');
607 box.style.zIndex = 200;
608 box.style.width = w+"px";
609 box.style.marginLeft = -parseInt(w/2)+"px";
610 box.style.height = h+"px";
611 box.style.top = parseInt((document.body.clientHeight - h) / 2) + document.body.scrollTop;
613 mesgtoadm_formtext_hilite($('mesgtoadm_form'));
615 box.style.visibility = "visible";
616 $('mesgtoadm_form').elements['subj'].focus();
619 function j_pollbox(form)
624 // submit the request
626 for (i = 0 ; i < form.elements.length ; i++) {
627 if (form.elements[i].checked == true)
630 if (i == form.elements.length) {
632 no = new notify(gst, (g_lang == 'en' ? "<br>You must choose ah item;<br> please, fix it." :
633 "<br>Non hai espresso nessuna preferenza;<br> correggi per favore."), 1,
634 (g_lang == 'en' ? "close" : "chiudi"), 280, 100);
638 choose = form.elements[i].value;
640 token = server_request('mesg', 'poll',
641 'cli_choose', encodeURIComponent(choose) );
644 // TODO: mesg to user
645 // $('mesgtoadmbox').style.visibility = "hidden";
656 function list_set(what, setco, info)
658 if (what == 'auth') {
659 $('list_auth').style.color = 'red';
660 $('list_all').style.color = 'black';
663 $('list_auth').style.color = 'black';
664 $('list_all').style.color = 'red';
666 $('list_info').innerHTML = info;
668 createCookie("CO_list", what, 24*365, cookiepath);
672 function sideslide(domobj, height, step)
677 this.domobj = domobj;
678 this.height = height;
684 sideslide.prototype = {
699 this.id = setTimeout(function () { instant.sideslide_cb(); }, this.twait);
702 sideslide_cb: function() {
705 if (this.st == 'wait') {
708 this.id = setInterval(function () { instant.sideslide_cb(); }, 100);
710 else if (this.st == 'scroll') {
711 this.scroll += (this.step / 10);
712 if (this.scroll >= this.height - this.step) {
715 this.domobj.scrollTop = this.scroll;
717 if (this.countdown == 0) {
720 this.id = setTimeout(function () { instant.sideslide_cb(); }, this.twait);
727 if (this.id != null) {
728 clearInterval(this.id);