4 * Copyright (C) 2006-2014 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.
27 data = [ [ flags, name ], ... ]
32 function state_add(flags, comp)
34 var content = "", supercont = "";
35 var st, superst, name = "", supername = "", supersfx = "";
36 var tit = "", supertit = "";
39 if ((flags & 0xf00) != 0) {
41 // MLANG 4,12,16,20,24,28
45 tit = (g_lang == 'en' ? "I'm doing a break" : "sono in pausa");
49 tit = (g_lang == 'en' ? "I'm away" : "sono fuori");
53 tit = (g_lang == 'en' ? "Dog time" : "sono a spasso col cane");
57 tit = (g_lang == 'en' ? "I'm eating" : "sto mangiando");
61 tit = (g_lang == 'en' ? "I'm working" : "sono a lavoro");
65 tit = (g_lang == 'en' ? "I'm smoking a sigarett (and keeping a cancer)" : "sto fumando una sigaretta (e facendomi venire il cancro)");
69 tit = (g_lang == 'en' ? "I'm here!" : "sono presente!");
72 name = "st_rabbit.png";
73 tit = (g_lang == 'en' ? "Rabbit time" : "sono a spasso col coniglio");
76 name = "st_soccer.png";
77 tit = (g_lang == 'en' ? "Soccer time" : "c'è la partita!!");
81 tit = (g_lang == 'en' ? "Children time" : "ho il pupo da accudire");
85 tit = (g_lang == 'en' ? "Mop time" : "sto rassettando");
88 name = "st_babbo.png";
89 tit = (g_lang == 'en' ? "Sto dando i regali" : "sto dando i regali");
92 name = "st_renna.png";
93 tit = (g_lang == 'en' ? "in giro per regali" : "in giro per regali");
96 name = "st_pupaz.png";
97 tit = (g_lang == 'en' ? "Neve a gogò" : "neve a gogò");
100 name = "st_visch.png";
101 tit = (g_lang == 'en' ? "aspettando sotto al vischio" : "aspettando sotto al vischio");
108 if ((flags & 0xf0000) != 0) {
109 superst = flags & 0x20000;
117 supername = "suprend.php?comp="+comp+"&sfx="+supersfx;
120 supername = "img/superuser"+supersfx+".png";
122 supertit = (g_lang == 'en' ? "Brisk Supporter" : "Brisk Supporter");
127 if (supername != "") {
128 content += ' <img title="'+supertit+'" class="inline" src="'+supername+'">';
132 content += ' <img title="'+tit+'" class="inline" src="img/'+name+'">';
138 var standup_data_old = null;
141 // appendChild , removeChild
143 function table_add(curtag, td)
145 var tbody = null, tr, ct;
148 // console.log("wt: "+curtag.tagName);
150 if (curtag.tagName.toLowerCase() == "div" ||
151 curtag.tagName.toLowerCase() == "table") {
152 curtag = curtag.firstChild;
154 else if (curtag.tagName.toLowerCase() == "tbody") {
160 } while (curtag != null);
162 curtag = tbody.firstChild;
165 if (curtag.tagName.toLowerCase() == "tr") {
166 if (curtag.firstChild != null) {
167 curtag = curtag.firstChild;
171 curtag.appendChild(td);
175 else if (curtag.tagName.toLowerCase() == "td") {
176 if (curtag.nextSibling != null) {
177 curtag = curtag.nextSibling;
182 curtag.parentNode.appendChild(td);
187 curtag = curtag.parentNode.nextSibling;
192 curtag = curtag.parentNode;
195 } while (curtag != null);
197 tr = document.createElement("tr");
199 tbody.appendChild(tr);
204 function spcs(c1, c2, n)
209 for (i = 0 ; i < n ; i++) {
220 function table_walk(curtag)
223 // console.log("wt: "+curtag.tagName);
224 if (curtag.tagName.toLowerCase() == "div" ||
225 curtag.tagName.toLowerCase() == "table" ||
226 curtag.tagName.toLowerCase() == "tbody") {
227 curtag = curtag.firstChild;
229 else if (curtag.tagName.toLowerCase() == "tr") {
230 if (curtag.firstChild != null)
231 curtag = curtag.firstChild;
232 else if (curtag.tagName != '')
233 curtag = curtag.nextSibling;
237 else if (curtag.tagName.toLowerCase() == "td") {
238 if (curtag.nextSibling != null)
239 curtag = curtag.nextSibling;
241 if (curtag.parentNode.nextSibling != null && curtag.parentNode.nextSibling.tagName != '')
242 curtag = curtag.parentNode.nextSibling;
250 } while (curtag != null && curtag.tagName.toLowerCase() != "td");
254 alert("outtag == null");
256 alert("outtag: "+curtag.tagName);
261 function j_stand_tdcont(el)
263 return (user_dec_and_state(el));
267 ddata = [ [ <flags-int>, <nick-str>, <color-str> ], ... ]
269 function j_stand_cont(ddata)
273 var st = 0, name = "";
278 if (g_listen & l_list_isol) {
281 for (i = 0, ii = 0 ; ii < ddata.length ; ii++) {
282 if ((ddata[ii][0] & 0x02) == 0) {
285 data[i++] = ddata[ii];
293 // managing update needs this branch (for few users and the else!!)
295 if (standup_data_old == null || data.length < 4) {
296 content = '<table cols="'+(data.length < 4 ? data.length : 4)+'" class="table_standup">';
297 for (i = 0 ; i < data.length ; i++) {
300 content += '<td id="'+i+'" class="room_standup">';
301 content += j_stand_tdcont(data[i]);
309 content += '</table>';
311 $("standup").innerHTML = content;
313 standup_data_old = data;
316 var idx_del, arr_add, idx_mod, arr_mod;
317 var idx_del_n = 0, idx_add_n = 0, idx_mod_n = 0;
319 var i_del, i_mod, i_add;
322 idx_del = new Array();
323 arr_add = new Array();
324 map_add = new Array();
325 idx_mod = new Array();
326 arr_mod = new Array();
327 map_cur = new Array();
329 // find removed entries
330 for (i = 0 ; i < standup_data_old.length ; i++) {
331 for (e = 0 ; e < data.length ; e++) {
332 if (standup_data_old[i][1] == data[e][1]) {
336 if (e == data.length) {
337 idx_del[idx_del_n++] = i;
341 /* modified entries */
342 if (standup_data_old[i][0] != data[e][0] ||
343 standup_data_old[i].length != data[e].length ||
344 (data[e].length == 3 && standup_data_old[i][2] != data[e][2])) {
345 arr_mod[idx_mod_n] = data[e];
346 idx_mod[idx_mod_n++] = i;
353 for (e = 0 ; e < data.length ; e++) {
354 for (i = 0 ; i < standup_data_old.length ; i++) {
355 if (data[e][1] == standup_data_old[i][1] ) {
359 if (i == standup_data_old.length) {
360 // console.log("ADD: "+data[e][1]);
361 arr_add[idx_add_n] = data[e];
362 map_add[idx_add_n++] = e;
366 // TODO: qui travaso add in del
369 // alert("del: ["+j_stand_tdcont(standup_data_old[idx_del[i_del]])+"]");
370 for (i = 0 , i_del = 0, i_mod = 0, i_add = 0, curtag = table_walk($("standup")) ; curtag != null ; curtag = table_walk(curtag), i++ ) {
371 // console.log("cur.id: "+curtag.id);
373 // alert("i: "+i+" tagname: "+curtag.tagName+" innerHTML: ["+curtag.innerHTML+"]");
374 // console.log("inloop["+i+"]: "+curtag.tagName+" ID: "+curtag.id);
375 if (curtag.innerHTML == "") {
376 // console.log("innerHTML == none");
377 if (i_add < idx_add_n) {
378 // console.log(" to be new");
379 // console.log(" add: CONT:"+j_stand_tdcont(arr_add[i_add]));
380 curtag.innerHTML = j_stand_tdcont(arr_add[i_add]);
381 curtag.id = map_add[i_add];
386 // else if (i_del < idx_del_n && curtag.innerHTML == j_stand_tdcont(standup_data_old[idx_del[i_del]])) {
387 else if (i_del < idx_del_n && curtag.id == idx_del[i_del]) {
388 // console.log("to be cancel["+i+"]: ID: "+curtag.id);
389 if (i_add < idx_add_n) {
390 // console.log(" to be new");
391 // console.log(" add: CONT:"+j_stand_tdcont(arr_add[i_add]));
392 curtag.innerHTML = j_stand_tdcont(arr_add[i_add]);
393 curtag.id = map_add[i_add];
397 // console.log(" to be del");
398 curtag.innerHTML = "";
403 // else if (i_mod < idx_mod_n && curtag.innerHTML == j_stand_tdcont(standup_data_old[idx_mod[i_mod]])) {
404 else if (i_mod < idx_mod_n && curtag.id == idx_mod[i_mod]) {
405 // console.log(" to be mod");
406 // console.log("mod: "+idx_mod[i_mod]+ " CONT:"+j_stand_tdcont(arr_mod[i_mod]));
407 curtag.innerHTML = j_stand_tdcont(arr_mod[i_mod]);
408 curtag.id = map_cur[curtag.id];
412 curtag.id = map_cur[curtag.id];
414 // console.log("fineloop");
416 for (i ; i_add < idx_add_n ; i_add++, i++) {
417 // console.log("ADD: "+i+" arr_add: "+ arr_add[i_add][1]);
418 td = document.createElement("td");
419 td.className = "room_standup";
420 td.id = map_add[i_add];
421 td.innerHTML = j_stand_tdcont(arr_add[i_add]);
423 table_add($("standup"), td);
426 standup_data_old = data;
429 // $("esco").innerHTML = '<input class="button" name="logout" value="Esco." onclick="esco_cb();" type="button">';
433 window.onbeforeunload = null;
434 window.onunload = null;
441 function j_tab_cont(table_idx, data)
446 for (i = 0 ; i < data.length ; i++) {
447 // content += user_decorator(data[i]);
448 // content += state_add(data[i][0]);
449 content += j_stand_tdcont(data[i]);
453 $("table"+table_idx).innerHTML = content;
456 function j_tab_act_cont(idx, act)
460 $("table_act"+idx).innerHTML = '<input type="button" class="button" name="xhenter'+idx+'" value="'+(g_lang == 'en' ? "Sit down." : "Mi siedo.")+'" onclick="act_sitdown('+idx+');">';
462 else if (act == 'sitreser') {
464 $("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+');" title="'+(g_lang == 'en' ? "reserved table for authenticated users only" : "tavolo riservato agli utenti registrati")+'" alt="'+(g_lang == 'en' ? "reserved table for authenticated users only" : "tavolo riservato agli utenti registrati")+'">';
466 else if (act == 'sitcert') {
468 $("table_act"+idx).innerHTML = '<input type="button" style="background-repeat: no-repeat; background-position: center; background-image: url(\'img/okcert.png\');" class="button" name="xhenter'+idx+'" value="'+(g_lang == 'en' ? "Sit down." : "Mi siedo.")+'" onclick="act_sitdown('+idx+');" title="'+(g_lang == 'en' ? "reserved table for authenticated users only" : "tavolo riservato agli utenti registrati e certificati")+'" alt="'+(g_lang == 'en' ? "reserved table for authenticated and certificated users only" : "tavolo riservato agli utenti registrati e certificati")+'">';
470 else if (act == 'wake') {
472 $("table_act"+idx).innerHTML = '<input type="button" class="button" name="xwakeup" value="'+(g_lang == 'en' ? "Wake up." : "Mi alzo.")+'" onclick="act_wakeup();">';
474 else if (act == 'resercert') {
476 $("table_act"+idx).innerHTML = '<img class="nobo" title="'+(g_lang == 'en' ? "reserved table for authenticated and certified users only" : "tavolo riservato agli utenti registrati e certificati")+'" style="margin-right: 20px;" src="img/onlycert.png">';
478 else if (act == 'reserved') {
480 $("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">';
483 $("table_act"+idx).innerHTML = '';
487 function j_login_manager(form)
491 if (form.elements['passid'].value == '')
495 // console.log("richiesta token");
497 token = server_request('mesg', 'getchallenge', 'cli_name', encodeURIComponent(form.elements['nameid'].value));
498 tokens = token.split('|');
500 // console.log('XX token: '+token);
501 // console.log(tokens);
505 token = calcMD5(tokens[1]+calcMD5(form.elements['passid'].value));
507 form.elements['passid_private'].value = token;
508 form.elements['passid'].value = ""; // FIXME da sost con la stessa len di A
516 function login_formtext_hilite()
518 formtext_hilite($("nameid"));
519 formtext_hilite($("passid"));
520 formsub_hilite($("sub"));
523 function login_init()
526 login_formtext_hilite();
529 function warrant_formtext_hilite(form)
532 formtext_hilite($("nameid"));
533 formtext_hilite($("emailid"));
534 formsub_hilite($("subid"));
535 formsub_hilite($("cloid"));
537 formtext_hilite(form.elements['name']);
538 formtext_hilite(form.elements['email']);
539 formsub_hilite(form.elements['sub']);
540 formsub_hilite(form.elements['clo']);
543 function mesgtoadm_formtext_hilite(form)
546 formtext_hilite($("subjid"));
547 formtext_hilite($("mesgid"));
548 formsub_hilite($("subid"));
549 formsub_hilite($("cloid"));
551 formtext_hilite(form.elements['subj']);
552 formtext_hilite(form.elements['mesg']);
553 formsub_hilite(form.elements['sub']);
554 formsub_hilite(form.elements['clo']);
558 function j_check_email(email)
560 if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email))
565 function j_authbox(form)
570 if (form.elements['realsub'].value == "chiudi") {
571 $('authbox').style.visibility = "hidden";
575 if (form.elements['name'].value == '' || j_check_email(form.elements['email'].value) == false) {
578 (g_lang == 'en' ? "<br><b>nickname</b> and/or <b>e-mail</b> fields are invalid;<br>please, fix them." :
579 "<br>I campi <b>nickname</b> e/o <b>e-mail</b> non sono validi;<br> correggeteli per favore."),
580 1, (g_lang == 'en' ? "close" : "chiudi"), 280, 100);
584 // submit the request
585 token = server_request('mesg', 'warranty',
586 'cli_name', encodeURIComponent(form.elements['name'].value),
587 'cli_email', encodeURIComponent(form.elements['email'].value) );
589 $('authbox').style.visibility = "hidden";
590 form.elements['name'].value = "";
591 form.elements['email'].value = "";
599 function authbox(w, h)
605 box.style.zIndex = 200;
606 box.style.width = w+"px";
607 box.style.marginLeft = -parseInt(w/2)+"px";
608 box.style.height = h+"px";
609 box.style.top = parseInt((document.body.clientHeight - h) / 2) + document.body.scrollTop;
611 warrant_formtext_hilite($('auth_form'));
613 box.style.visibility = "visible";
617 function j_mesgtoadmbox(form)
622 if (form.elements['realsub'].value == "chiudi") {
623 $('mesgtoadmbox').style.visibility = "hidden";
627 if (form.elements['mesg'].value == '' || form.elements['subj'].value == '') {
629 no = new notify(gst, (g_lang == 'en' ? "<br><b>subject</b> and the <b>message</b> cannot be void;<br>please, fix them." :
630 "<br>Il <b>soggetto</b> e il <b>messaggo</b> non possono essere vuoti;<br>correggeteli per favore."), 1,
631 (g_lang == 'en' ? "close" : "chiudi"), 280, 100);
635 // submit the request
636 token = server_request('mesg', 'mesgtoadm',
637 'cli_subj', encodeURIComponent(form.elements['subj'].value),
638 'cli_mesg', encodeURIComponent(form.elements['mesg'].value) );
640 $('mesgtoadmbox').style.visibility = "hidden";
641 form.elements['subj'].value = "";
642 form.elements['mesg'].value = "";
650 function mesgtoadmbox(w, h)
654 box = $('mesgtoadmbox');
656 box.style.zIndex = 200;
657 box.style.width = w+"px";
658 box.style.marginLeft = -parseInt(w/2)+"px";
659 box.style.height = h+"px";
660 box.style.top = parseInt((document.body.clientHeight - h) / 2) + document.body.scrollTop;
662 mesgtoadm_formtext_hilite($('mesgtoadm_form'));
664 box.style.visibility = "visible";
665 $('mesgtoadm_form').elements['subj'].focus();
668 function j_pollbox(form)
673 // submit the request
675 for (i = 0 ; i < form.elements.length ; i++) {
676 if (form.elements[i].checked == true)
679 if (i == form.elements.length) {
681 no = new notify(gst, (g_lang == 'en' ? "<br>You must choose ah item;<br> please, fix it." :
682 "<br>Non hai espresso nessuna preferenza;<br> correggi per favore."), 1,
683 (g_lang == 'en' ? "close" : "chiudi"), 280, 100);
687 choose = form.elements[i].value;
689 token = server_request('mesg', 'poll',
690 'cli_choose', encodeURIComponent(choose) );
693 // TODO: mesg to user
694 // $('mesgtoadmbox').style.visibility = "hidden";
703 function sideslide(domobj, height, step)
708 this.domobj = domobj;
709 this.height = height;
715 sideslide.prototype = {
730 this.id = setTimeout(function () { instant.sideslide_cb(); }, this.twait);
733 sideslide_cb: function() {
736 if (this.st == 'wait') {
739 this.id = setInterval(function () { instant.sideslide_cb(); }, 100);
741 else if (this.st == 'scroll') {
742 this.scroll += (this.step / 10);
743 if (this.scroll >= this.height - this.step) {
746 this.domobj.scrollTop = this.scroll;
748 if (this.countdown == 0) {
751 this.id = setTimeout(function () { instant.sideslide_cb(); }, this.twait);
758 if (this.id != null) {
759 clearInterval(this.id);