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 var l_list_all = 0x00;
33 var l_list_auth = 0x01;
34 var l_list_isol = 0x02;
36 function client_prefs()
40 client_prefs.prototype = {
44 function state_add(flags)
46 var content = "", supercont = "";
47 var st, superst, name = "", supername = "", supersfx = "";
48 var tit = "", supertit = "";
51 if ((flags & 0xf00) != 0) {
53 // MLANG 4,12,16,20,24,28
57 tit = (g_lang == 'en' ? "I'm doing a break" : "sono in pausa");
61 tit = (g_lang == 'en' ? "I'm away" : "sono fuori");
65 tit = (g_lang == 'en' ? "Dog time" : "sono a spasso col cane");
69 tit = (g_lang == 'en' ? "I'm eating" : "sto mangiando");
73 tit = (g_lang == 'en' ? "I'm working" : "sono a lavoro");
77 tit = (g_lang == 'en' ? "I'm smoking a sigarett (and keeping a cancer)" : "sto fumando una sigaretta (e facendomi venire il cancro)");
81 tit = (g_lang == 'en' ? "I'm here!" : "sono presente!");
84 name = "st_rabbit.png";
85 tit = (g_lang == 'en' ? "Rabbit time" : "sono a spasso col coniglio");
88 name = "st_soccer.png";
89 tit = (g_lang == 'en' ? "Soccer time" : "c'è la partita!!");
93 tit = (g_lang == 'en' ? "Children time" : "ho il pupo da accudire");
97 tit = (g_lang == 'en' ? "Mop time" : "sto rassettando");
100 name = "st_babbo.png";
101 tit = (g_lang == 'en' ? "Sto dando i regali" : "sto dando i regali");
104 name = "st_renna.png";
105 tit = (g_lang == 'en' ? "in giro per regali" : "in giro per regali");
108 name = "st_pupaz.png";
109 tit = (g_lang == 'en' ? "Neve a gogò" : "neve a gogò");
112 name = "st_visch.png";
113 tit = (g_lang == 'en' ? "aspettando sotto al vischio" : "aspettando sotto al vischio");
120 if ((flags & 0xf0000) != 0) {
121 superst = flags & 0xf0000;
128 supername = "superuser"+supersfx+".png";
129 supertit = (g_lang == 'en' ? "Brisk Supporter" : "Brisk Supporter");
134 if (supername != "") {
135 content += ' <img title="'+supertit+'" class="inline" src="img/'+supername+'">';
139 content += ' <img title="'+tit+'" class="inline" src="img/'+name+'">';
145 var standup_data_old = null;
148 // appendChild , removeChild
150 function table_add(curtag, td)
152 var tbody = null, tr, ct;
155 // console.log("wt: "+curtag.tagName);
157 if (curtag.tagName.toLowerCase() == "div" ||
158 curtag.tagName.toLowerCase() == "table") {
159 curtag = curtag.firstChild;
161 else if (curtag.tagName.toLowerCase() == "tbody") {
167 } while (curtag != null);
169 curtag = tbody.firstChild;
172 if (curtag.tagName.toLowerCase() == "tr") {
173 if (curtag.firstChild != null) {
174 curtag = curtag.firstChild;
178 curtag.appendChild(td);
182 else if (curtag.tagName.toLowerCase() == "td") {
183 if (curtag.nextSibling != null) {
184 curtag = curtag.nextSibling;
189 curtag.parentNode.appendChild(td);
194 curtag = curtag.parentNode.nextSibling;
199 curtag = curtag.parentNode;
202 } while (curtag != null);
204 tr = document.createElement("tr");
206 tbody.appendChild(tr);
211 function spcs(c1, c2, n)
216 for (i = 0 ; i < n ; i++) {
227 function table_walk(curtag)
230 // console.log("wt: "+curtag.tagName);
231 if (curtag.tagName.toLowerCase() == "div" ||
232 curtag.tagName.toLowerCase() == "table" ||
233 curtag.tagName.toLowerCase() == "tbody") {
234 curtag = curtag.firstChild;
236 else if (curtag.tagName.toLowerCase() == "tr") {
237 if (curtag.firstChild != null)
238 curtag = curtag.firstChild;
239 else if (curtag.tagName != '')
240 curtag = curtag.nextSibling;
244 else if (curtag.tagName.toLowerCase() == "td") {
245 if (curtag.nextSibling != null)
246 curtag = curtag.nextSibling;
248 if (curtag.parentNode.nextSibling != null && curtag.parentNode.nextSibling.tagName != '')
249 curtag = curtag.parentNode.nextSibling;
257 } while (curtag != null && curtag.tagName.toLowerCase() != "td");
261 alert("outtag == null");
263 alert("outtag: "+curtag.tagName);
268 function j_stand_tdcont(el)
270 return (user_dec_and_state(el));
273 function j_stand_cont(ddata)
277 var st = 0, name = "";
282 if (g_listen & l_list_isol) {
285 for (i = 0, ii = 0 ; ii < ddata.length ; ii++) {
286 if ((ddata[ii][0] & 0x02) == 0) {
289 data[i++] = ddata[ii];
295 if (standup_data_old == null || data.length < 4) {
296 // if (standup_data_old == null) {
298 content = '<table cols="'+(data.length < 4 ? data.length : 4)+'" class="table_standup">';
299 for (i = 0 ; i < data.length ; i++) {
302 content += '<td id="'+i+'" class="room_standup">';
303 content += j_stand_tdcont(data[i]);
311 content += '</table>';
313 $("standup").innerHTML = content;
315 // console.log("inizio");
316 // for (i = 0 , curtag = table_walk($("standup")) ; curtag != null ; curtag = table_walk(curtag), i++ ) {
317 // console.log("inloop["+i+"]: "+curtag.tagName+" ID: "+curtag.id);
319 // console.log("fine "+i);
321 // walktable($("standup"), nextag);
322 // console.log($("standup").firstChild);
323 // console.log($("standup").firstChild.firstChild.firstChild.firstChild);
325 // log_walk($("standup"));
327 standup_data_old = data;
330 var idx_del, arr_add, idx_mod, arr_mod;
331 var idx_del_n = 0, idx_add_n = 0, idx_mod_n = 0;
333 var i_del, i_mod, i_add;
336 idx_del = new Array();
337 arr_add = new Array();
338 map_add = new Array();
339 idx_mod = new Array();
340 arr_mod = new Array();
341 map_cur = new Array();
343 // find removed entries
344 for (i = 0 ; i < standup_data_old.length ; i++) {
345 for (e = 0 ; e < data.length ; e++) {
346 if (standup_data_old[i][1] == data[e][1]) {
350 if (e == data.length) {
351 idx_del[idx_del_n++] = i;
355 /* modified entries */
356 if (standup_data_old[i][0] != data[e][0]) {
357 arr_mod[idx_mod_n] = data[e];
358 idx_mod[idx_mod_n++] = i;
365 for (e = 0 ; e < data.length ; e++) {
366 for (i = 0 ; i < standup_data_old.length ; i++) {
367 if (data[e][1] == standup_data_old[i][1] ) {
371 if (i == standup_data_old.length) {
372 // console.log("ADD: "+data[e][1]);
373 arr_add[idx_add_n] = data[e];
374 map_add[idx_add_n++] = e;
378 // TODO: qui travaso add in del
381 // alert("del: ["+j_stand_tdcont(standup_data_old[idx_del[i_del]])+"]");
382 for (i = 0 , i_del = 0, i_mod = 0, i_add = 0, curtag = table_walk($("standup")) ; curtag != null ; curtag = table_walk(curtag), i++ ) {
383 // console.log("cur.id: "+curtag.id);
385 // alert("i: "+i+" tagname: "+curtag.tagName+" innerHTML: ["+curtag.innerHTML+"]");
386 // console.log("inloop["+i+"]: "+curtag.tagName+" ID: "+curtag.id);
387 if (curtag.innerHTML == "") {
388 // console.log("innerHTML == none");
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];
398 // else if (i_del < idx_del_n && curtag.innerHTML == j_stand_tdcont(standup_data_old[idx_del[i_del]])) {
399 else if (i_del < idx_del_n && curtag.id == idx_del[i_del]) {
400 // console.log("to be cancel["+i+"]: ID: "+curtag.id);
401 if (i_add < idx_add_n) {
402 // console.log(" to be new");
403 // console.log(" add: CONT:"+j_stand_tdcont(arr_add[i_add]));
404 curtag.innerHTML = j_stand_tdcont(arr_add[i_add]);
405 curtag.id = map_add[i_add];
409 // console.log(" to be del");
410 curtag.innerHTML = "";
415 // else if (i_mod < idx_mod_n && curtag.innerHTML == j_stand_tdcont(standup_data_old[idx_mod[i_mod]])) {
416 else if (i_mod < idx_mod_n && curtag.id == idx_mod[i_mod]) {
417 // console.log(" to be mod");
418 // console.log("mod: "+idx_mod[i_mod]+ " CONT:"+j_stand_tdcont(arr_mod[i_mod]));
419 curtag.innerHTML = j_stand_tdcont(arr_mod[i_mod]);
420 curtag.id = map_cur[curtag.id];
424 curtag.id = map_cur[curtag.id];
426 // console.log("fineloop");
428 for (i ; i_add < idx_add_n ; i_add++, i++) {
429 // console.log("ADD: "+i+" arr_add: "+ arr_add[i_add][1]);
430 td = document.createElement("td");
431 td.className = "room_standup";
432 td.id = map_add[i_add];
433 td.innerHTML = j_stand_tdcont(arr_add[i_add]);
435 table_add($("standup"), td);
438 standup_data_old = data;
441 // $("esco").innerHTML = '<input class="button" name="logout" value="Esco." onclick="esco_cb();" type="button">';
445 window.onbeforeunload = null;
446 window.onunload = null;
453 function j_tab_cont(table_idx, data)
458 for (i = 0 ; i < data.length ; i++) {
459 // content += user_decorator(data[i]);
460 // content += state_add(data[i][0]);
461 content += j_stand_tdcont(data[i]);
465 $("table"+table_idx).innerHTML = content;
468 function j_tab_act_cont(idx, act)
472 $("table_act"+idx).innerHTML = '<input type="button" class="button" name="xhenter'+idx+'" value="'+(g_lang == 'en' ? "Sit down." : "Mi siedo.")+'" onclick="act_sitdown('+idx+');">';
474 else if (act == 'sitreser') {
475 // <img class="nobo" title="tavolo riservato agli utenti registrati" style="display: inline; margin-right: 80px;" src="img/okauth.png">
477 $("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+');">';
479 else if (act == 'wake') {
481 $("table_act"+idx).innerHTML = '<input type="button" class="button" name="xwakeup" value="'+(g_lang == 'en' ? "Wake up." : "Mi alzo.")+'" onclick="act_wakeup();">';
483 else if (act == 'reserved') {
485 $("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">';
488 $("table_act"+idx).innerHTML = '';
492 function j_login_manager(form)
496 if (form.elements['passid'].value == '')
500 // console.log("richiesta token");
502 token = server_request('mesg', 'getchallenge', 'cli_name', encodeURIComponent(form.elements['nameid'].value));
503 tokens = token.split('|');
505 // console.log('XX token: '+token);
506 // console.log(tokens);
510 token = calcMD5(tokens[1]+calcMD5(form.elements['passid'].value));
512 form.elements['passid_private'].value = token;
513 form.elements['passid'].value = ""; // FIXME da sost con la stessa len di A
521 function login_formtext_hilite()
523 formtext_hilite($("nameid"));
524 formtext_hilite($("passid"));
525 formsub_hilite($("sub"));
528 function login_init()
531 login_formtext_hilite();
534 function warrant_formtext_hilite(form)
537 formtext_hilite($("nameid"));
538 formtext_hilite($("emailid"));
539 formsub_hilite($("subid"));
540 formsub_hilite($("cloid"));
542 formtext_hilite(form.elements['name']);
543 formtext_hilite(form.elements['email']);
544 formsub_hilite(form.elements['sub']);
545 formsub_hilite(form.elements['clo']);
548 function mesgtoadm_formtext_hilite(form)
551 formtext_hilite($("subjid"));
552 formtext_hilite($("mesgid"));
553 formsub_hilite($("subid"));
554 formsub_hilite($("cloid"));
556 formtext_hilite(form.elements['subj']);
557 formtext_hilite(form.elements['mesg']);
558 formsub_hilite(form.elements['sub']);
559 formsub_hilite(form.elements['clo']);
563 function j_check_email(email)
565 if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email))
570 function j_authbox(form)
575 if (form.elements['realsub'].value == "chiudi") {
576 $('authbox').style.visibility = "hidden";
580 if (form.elements['name'].value == '' || j_check_email(form.elements['email'].value) == false) {
583 (g_lang == 'en' ? "<br><b>nickname</b> and/or <b>e-mail</b> fields are invalid;<br>please, fix them." :
584 "<br>I campi <b>nickname</b> e/o <b>e-mail</b> non sono validi;<br> correggeteli per favore."),
585 1, (g_lang == 'en' ? "close" : "chiudi"), 280, 100);
589 // submit the request
590 token = server_request('mesg', 'warranty',
591 'cli_name', encodeURIComponent(form.elements['name'].value),
592 'cli_email', encodeURIComponent(form.elements['email'].value) );
594 $('authbox').style.visibility = "hidden";
595 form.elements['name'].value = "";
596 form.elements['email'].value = "";
604 function authbox(w, h)
610 box.style.zIndex = 200;
611 box.style.width = w+"px";
612 box.style.marginLeft = -parseInt(w/2)+"px";
613 box.style.height = h+"px";
614 box.style.top = parseInt((document.body.clientHeight - h) / 2) + document.body.scrollTop;
616 warrant_formtext_hilite($('auth_form'));
618 box.style.visibility = "visible";
622 function j_mesgtoadmbox(form)
627 if (form.elements['realsub'].value == "chiudi") {
628 $('mesgtoadmbox').style.visibility = "hidden";
632 if (form.elements['mesg'].value == '' || form.elements['subj'].value == '') {
634 no = new notify(gst, (g_lang == 'en' ? "<br><b>subject</b> and the <b>message</b> cannot be void;<br>please, fix them." :
635 "<br>Il <b>soggetto</b> e il <b>messaggo</b> non possono essere vuoti;<br>correggeteli per favore."), 1,
636 (g_lang == 'en' ? "close" : "chiudi"), 280, 100);
640 // submit the request
641 token = server_request('mesg', 'mesgtoadm',
642 'cli_subj', encodeURIComponent(form.elements['subj'].value),
643 'cli_mesg', encodeURIComponent(form.elements['mesg'].value) );
645 $('mesgtoadmbox').style.visibility = "hidden";
646 form.elements['subj'].value = "";
647 form.elements['mesg'].value = "";
655 function mesgtoadmbox(w, h)
659 box = $('mesgtoadmbox');
661 box.style.zIndex = 200;
662 box.style.width = w+"px";
663 box.style.marginLeft = -parseInt(w/2)+"px";
664 box.style.height = h+"px";
665 box.style.top = parseInt((document.body.clientHeight - h) / 2) + document.body.scrollTop;
667 mesgtoadm_formtext_hilite($('mesgtoadm_form'));
669 box.style.visibility = "visible";
670 $('mesgtoadm_form').elements['subj'].focus();
673 function j_pollbox(form)
678 // submit the request
680 for (i = 0 ; i < form.elements.length ; i++) {
681 if (form.elements[i].checked == true)
684 if (i == form.elements.length) {
686 no = new notify(gst, (g_lang == 'en' ? "<br>You must choose ah item;<br> please, fix it." :
687 "<br>Non hai espresso nessuna preferenza;<br> correggi per favore."), 1,
688 (g_lang == 'en' ? "close" : "chiudi"), 280, 100);
692 choose = form.elements[i].value;
694 token = server_request('mesg', 'poll',
695 'cli_choose', encodeURIComponent(choose) );
698 // TODO: mesg to user
699 // $('mesgtoadmbox').style.visibility = "hidden";
707 function prefs_assign(content)
712 s = "prefs_new = " + content;
718 var prefs_list_idx = new Array( 0x00, 0x01, 0x02 );
719 var prefs_list_id = new Array( "all", "auth", "isol" );
721 function prefs_apply(prefs_new, is_update, is_volat)
726 if (typeof(g_prefs) == 'undefined')
729 /* listen management */
730 if (g_prefs.listen != prefs_new.listen) {
731 for (i = 0 ; i < prefs_list_idx.length ; i++) {
732 set_checked_value($('ra_listen_'+prefs_list_id[i]), prefs_new.listen);
733 if (prefs_new.listen == prefs_list_idx[i]) {
735 $('list_'+prefs_list_id[i]).style.color = 'red';
736 $('list_info').innerHTML = mlang_commons['tit_list'][i][g_lang];
740 $('list_'+prefs_list_id[i]).style.color = 'black';
748 // TO BE ANALYZED !!!
750 // createCookie("CO_list", what, 24*365, cookiepath);
754 if (relo || !is_update) {
755 for (i = g_tables_auth_n ; i < g_tables_n ; i++) {
757 $('tr_noauth'+i).style.display = (prefs_new.listen == l_list_isol ? 'none' : '');
760 $('td_noauth'+i).style.display = (prefs_new.listen == l_list_isol ? 'none' : '');
762 if (prefs_new.listen == l_list_isol) {
770 // ricalculation of standup area
771 if (standup_data_old != null) {
772 standup_data = standup_data_old;
773 standup_data_old = null;
774 j_stand_cont(standup_data);
779 g_prefs.listen = prefs_new.listen;
782 function prefs_load(content, is_update, is_volat)
786 if ((prefs_new = prefs_assign(content)) == null)
789 return prefs_apply(prefs_new, is_update, is_volat);
792 function prefs_save()
794 if (typeof(g_prefs) == 'undefined')
797 console.log(server_request('mesg', 'prefs', '__POST__', 'prefs', JSON.stringify(g_prefs)));
799 // $('preferences').style.visibility = 'hidden';
802 function prefs_update()
808 if (typeof(g_prefs) == 'undefined')
811 prefs_new = new client_prefs();
813 /* listen management */
814 for (i = 0 ; i < prefs_list_idx.length ; i++) {
815 prefs_new.listen = get_checked_value($('ra_listen_'+prefs_list_id[i]));
816 if (prefs_new.listen != '')
820 /* TODO SAVE TEMPORARY */
821 /* from form to struct */
822 console.log("Prefs_update");
823 prefs_apply(prefs_new, true, true);
826 function list_set(what, is_update, info)
830 var old_st = readCookie("CO_list");
832 if (what == 'auth') {
833 $('list_auth').style.color = 'red';
834 $('list_isol').style.color = 'black';
835 $('list_all').style.color = 'black';
836 if (old_st == 'isolation')
838 g_listen = l_list_auth;
840 else if (what == 'isolation') {
841 $('list_auth').style.color = 'black';
842 $('list_isol').style.color = 'red';
843 $('list_all').style.color = 'black';
844 if (old_st != 'isolation')
846 g_listen = l_list_isol;
849 $('list_auth').style.color = 'black';
850 $('list_isol').style.color = 'black';
851 $('list_all').style.color = 'red';
852 if (old_st == 'isolation')
854 g_listen = l_list_all;
857 set_checked_value($('ra_listen_auth'), what);
858 set_checked_value($('ra_listen_isol'), what);
859 set_checked_value($('ra_listen_all'), what);
861 $('list_info').innerHTML = info;
863 createCookie("CO_list", what, 24*365, cookiepath);
867 if (relo || !is_update) {
868 for (i = g_tables_auth_n ; i < g_tables_n ; i++) {
871 $('tr_noauth'+i).style.display = (what == 'isolation' ? 'none' : '');
874 $('td_noauth'+i).style.display = (what == 'isolation' ? 'none' : '');
876 if (what == 'isolation') {
884 // ricalculation of standup area
885 if (standup_data_old != null) {
886 standup_data = standup_data_old;
887 standup_data_old = null;
888 j_stand_cont(standup_data);
894 function sideslide(domobj, height, step)
899 this.domobj = domobj;
900 this.height = height;
906 sideslide.prototype = {
921 this.id = setTimeout(function () { instant.sideslide_cb(); }, this.twait);
924 sideslide_cb: function() {
927 if (this.st == 'wait') {
930 this.id = setInterval(function () { instant.sideslide_cb(); }, 100);
932 else if (this.st == 'scroll') {
933 this.scroll += (this.step / 10);
934 if (this.scroll >= this.height - this.step) {
937 this.domobj.scrollTop = this.scroll;
939 if (this.countdown == 0) {
942 this.id = setTimeout(function () { instant.sideslide_cb(); }, this.twait);
949 if (this.id != null) {
950 clearInterval(this.id);