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.
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 & 0xf0000;
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') {
463 // <img class="nobo" title="tavolo riservato agli utenti registrati" style="display: inline; margin-right: 80px;" src="img/okauth.png">
465 $("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+');">';
467 else if (act == 'wake') {
469 $("table_act"+idx).innerHTML = '<input type="button" class="button" name="xwakeup" value="'+(g_lang == 'en' ? "Wake up." : "Mi alzo.")+'" onclick="act_wakeup();">';
471 else if (act == 'reserved') {
473 $("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">';
476 $("table_act"+idx).innerHTML = '';
480 function j_login_manager(form)
484 if (form.elements['passid'].value == '')
488 // console.log("richiesta token");
490 token = server_request('mesg', 'getchallenge', 'cli_name', encodeURIComponent(form.elements['nameid'].value));
491 tokens = token.split('|');
493 // console.log('XX token: '+token);
494 // console.log(tokens);
498 token = calcMD5(tokens[1]+calcMD5(form.elements['passid'].value));
500 form.elements['passid_private'].value = token;
501 form.elements['passid'].value = ""; // FIXME da sost con la stessa len di A
509 function login_formtext_hilite()
511 formtext_hilite($("nameid"));
512 formtext_hilite($("passid"));
513 formsub_hilite($("sub"));
516 function login_init()
519 login_formtext_hilite();
522 function warrant_formtext_hilite(form)
525 formtext_hilite($("nameid"));
526 formtext_hilite($("emailid"));
527 formsub_hilite($("subid"));
528 formsub_hilite($("cloid"));
530 formtext_hilite(form.elements['name']);
531 formtext_hilite(form.elements['email']);
532 formsub_hilite(form.elements['sub']);
533 formsub_hilite(form.elements['clo']);
536 function mesgtoadm_formtext_hilite(form)
539 formtext_hilite($("subjid"));
540 formtext_hilite($("mesgid"));
541 formsub_hilite($("subid"));
542 formsub_hilite($("cloid"));
544 formtext_hilite(form.elements['subj']);
545 formtext_hilite(form.elements['mesg']);
546 formsub_hilite(form.elements['sub']);
547 formsub_hilite(form.elements['clo']);
551 function j_check_email(email)
553 if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email))
558 function j_authbox(form)
563 if (form.elements['realsub'].value == "chiudi") {
564 $('authbox').style.visibility = "hidden";
568 if (form.elements['name'].value == '' || j_check_email(form.elements['email'].value) == false) {
571 (g_lang == 'en' ? "<br><b>nickname</b> and/or <b>e-mail</b> fields are invalid;<br>please, fix them." :
572 "<br>I campi <b>nickname</b> e/o <b>e-mail</b> non sono validi;<br> correggeteli per favore."),
573 1, (g_lang == 'en' ? "close" : "chiudi"), 280, 100);
577 // submit the request
578 token = server_request('mesg', 'warranty',
579 'cli_name', encodeURIComponent(form.elements['name'].value),
580 'cli_email', encodeURIComponent(form.elements['email'].value) );
582 $('authbox').style.visibility = "hidden";
583 form.elements['name'].value = "";
584 form.elements['email'].value = "";
592 function authbox(w, h)
598 box.style.zIndex = 200;
599 box.style.width = w+"px";
600 box.style.marginLeft = -parseInt(w/2)+"px";
601 box.style.height = h+"px";
602 box.style.top = parseInt((document.body.clientHeight - h) / 2) + document.body.scrollTop;
604 warrant_formtext_hilite($('auth_form'));
606 box.style.visibility = "visible";
610 function j_mesgtoadmbox(form)
615 if (form.elements['realsub'].value == "chiudi") {
616 $('mesgtoadmbox').style.visibility = "hidden";
620 if (form.elements['mesg'].value == '' || form.elements['subj'].value == '') {
622 no = new notify(gst, (g_lang == 'en' ? "<br><b>subject</b> and the <b>message</b> cannot be void;<br>please, fix them." :
623 "<br>Il <b>soggetto</b> e il <b>messaggo</b> non possono essere vuoti;<br>correggeteli per favore."), 1,
624 (g_lang == 'en' ? "close" : "chiudi"), 280, 100);
628 // submit the request
629 token = server_request('mesg', 'mesgtoadm',
630 'cli_subj', encodeURIComponent(form.elements['subj'].value),
631 'cli_mesg', encodeURIComponent(form.elements['mesg'].value) );
633 $('mesgtoadmbox').style.visibility = "hidden";
634 form.elements['subj'].value = "";
635 form.elements['mesg'].value = "";
643 function mesgtoadmbox(w, h)
647 box = $('mesgtoadmbox');
649 box.style.zIndex = 200;
650 box.style.width = w+"px";
651 box.style.marginLeft = -parseInt(w/2)+"px";
652 box.style.height = h+"px";
653 box.style.top = parseInt((document.body.clientHeight - h) / 2) + document.body.scrollTop;
655 mesgtoadm_formtext_hilite($('mesgtoadm_form'));
657 box.style.visibility = "visible";
658 $('mesgtoadm_form').elements['subj'].focus();
661 function j_pollbox(form)
666 // submit the request
668 for (i = 0 ; i < form.elements.length ; i++) {
669 if (form.elements[i].checked == true)
672 if (i == form.elements.length) {
674 no = new notify(gst, (g_lang == 'en' ? "<br>You must choose ah item;<br> please, fix it." :
675 "<br>Non hai espresso nessuna preferenza;<br> correggi per favore."), 1,
676 (g_lang == 'en' ? "close" : "chiudi"), 280, 100);
680 choose = form.elements[i].value;
682 token = server_request('mesg', 'poll',
683 'cli_choose', encodeURIComponent(choose) );
686 // TODO: mesg to user
687 // $('mesgtoadmbox').style.visibility = "hidden";
696 function sideslide(domobj, height, step)
701 this.domobj = domobj;
702 this.height = height;
708 sideslide.prototype = {
723 this.id = setTimeout(function () { instant.sideslide_cb(); }, this.twait);
726 sideslide_cb: function() {
729 if (this.st == 'wait') {
732 this.id = setInterval(function () { instant.sideslide_cb(); }, 100);
734 else if (this.st == 'scroll') {
735 this.scroll += (this.step / 10);
736 if (this.scroll >= this.height - this.step) {
739 this.domobj.scrollTop = this.scroll;
741 if (this.countdown == 0) {
744 this.id = setTimeout(function () { instant.sideslide_cb(); }, this.twait);
751 if (this.id != null) {
752 clearInterval(this.id);