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 ], ... ]
31 function state_add(flags, comp)
33 var content = "", supercont = "";
34 var st, superst, name = "", supername = "", supersfx = "";
35 var tit = "", supertit = "";
38 if ((flags & 0xf00) != 0) {
40 // MLANG 4,12,16,20,24,28
44 tit = (g_lang == 'en' ? "I'm doing a break" : "sono in pausa");
48 tit = (g_lang == 'en' ? "I'm away" : "sono fuori");
52 tit = (g_lang == 'en' ? "Dog time" : "sono a spasso col cane");
56 tit = (g_lang == 'en' ? "I'm eating" : "sto mangiando");
60 tit = (g_lang == 'en' ? "I'm working" : "sono a lavoro");
64 tit = (g_lang == 'en' ? "I'm smoking a sigarett (and keeping a cancer)" : "sto fumando una sigaretta (e facendomi venire il cancro)");
68 tit = (g_lang == 'en' ? "I'm here!" : "sono presente!");
71 name = "st_rabbit.png";
72 tit = (g_lang == 'en' ? "Rabbit time" : "sono a spasso col coniglio");
75 name = "st_soccer.png";
76 tit = (g_lang == 'en' ? "Soccer time" : "c'è la partita!!");
80 tit = (g_lang == 'en' ? "Children time" : "ho il pupo da accudire");
84 tit = (g_lang == 'en' ? "Mop time" : "sto rassettando");
87 name = "st_babbo.png";
88 tit = (g_lang == 'en' ? "Sto dando i regali" : "sto dando i regali");
91 name = "st_renna.png";
92 tit = (g_lang == 'en' ? "in giro per regali" : "in giro per regali");
95 name = "st_pupaz.png";
96 tit = (g_lang == 'en' ? "Neve a gogò" : "neve a gogò");
99 name = "st_visch.png";
100 tit = (g_lang == 'en' ? "aspettando sotto al vischio" : "aspettando sotto al vischio");
107 if ((flags & 0xf0000) != 0) {
108 superst = flags & 0x20000;
116 supername = "suprend.php?comp="+comp+"&sfx="+supersfx;
119 supername = "img/superuser"+supersfx+".png";
121 supertit = (g_lang == 'en' ? "Brisk Supporter" : "Brisk Supporter");
126 if (supername != "") {
127 content += ' <img title="'+supertit+'" class="inline" src="'+supername+'">';
131 content += ' <img title="'+tit+'" class="inline" src="img/'+name+'">';
137 var standup_data_old = null;
140 // appendChild , removeChild
142 function table_add(curtag, td)
144 var tbody = null, tr, ct;
147 // console.log("wt: "+curtag.tagName);
149 if (curtag.tagName.toLowerCase() == "div" ||
150 curtag.tagName.toLowerCase() == "table") {
151 curtag = curtag.firstChild;
153 else if (curtag.tagName.toLowerCase() == "tbody") {
159 } while (curtag != null);
161 curtag = tbody.firstChild;
164 if (curtag.tagName.toLowerCase() == "tr") {
165 if (curtag.firstChild != null) {
166 curtag = curtag.firstChild;
170 curtag.appendChild(td);
174 else if (curtag.tagName.toLowerCase() == "td") {
175 if (curtag.nextSibling != null) {
176 curtag = curtag.nextSibling;
181 curtag.parentNode.appendChild(td);
186 curtag = curtag.parentNode.nextSibling;
191 curtag = curtag.parentNode;
194 } while (curtag != null);
196 tr = document.createElement("tr");
198 tbody.appendChild(tr);
203 function spcs(c1, c2, n)
208 for (i = 0 ; i < n ; i++) {
219 function table_walk(curtag)
222 // console.log("wt: "+curtag.tagName);
223 if (curtag.tagName.toLowerCase() == "div" ||
224 curtag.tagName.toLowerCase() == "table" ||
225 curtag.tagName.toLowerCase() == "tbody") {
226 curtag = curtag.firstChild;
228 else if (curtag.tagName.toLowerCase() == "tr") {
229 if (curtag.firstChild != null)
230 curtag = curtag.firstChild;
231 else if (curtag.tagName != '')
232 curtag = curtag.nextSibling;
236 else if (curtag.tagName.toLowerCase() == "td") {
237 if (curtag.nextSibling != null)
238 curtag = curtag.nextSibling;
240 if (curtag.parentNode.nextSibling != null && curtag.parentNode.nextSibling.tagName != '')
241 curtag = curtag.parentNode.nextSibling;
249 } while (curtag != null && curtag.tagName.toLowerCase() != "td");
253 alert("outtag == null");
255 alert("outtag: "+curtag.tagName);
260 function j_stand_tdcont(el)
262 return (user_dec_and_state(el));
266 ddata = [ [ <flags-int>, <nick-str>, <color-str> ], ... ]
268 function j_stand_cont(ddata)
272 var st = 0, name = "";
277 if (g_listen & l_list_isol) {
280 for (i = 0, ii = 0 ; ii < ddata.length ; ii++) {
281 if ((ddata[ii][0] & 0x02) == 0) {
284 data[i++] = ddata[ii];
292 // managing update needs this branch (for few users and the else!!)
294 if (standup_data_old == null || data.length < 4) {
295 content = '<table cols="'+(data.length < 4 ? data.length : 4)+'" class="table_standup">';
296 for (i = 0 ; i < data.length ; i++) {
299 content += '<td id="'+i+'" class="room_standup">';
300 content += j_stand_tdcont(data[i]);
308 content += '</table>';
310 $("standup").innerHTML = content;
312 standup_data_old = data;
315 var idx_del, arr_add, idx_mod, arr_mod;
316 var idx_del_n = 0, idx_add_n = 0, idx_mod_n = 0;
318 var i_del, i_mod, i_add;
321 idx_del = new Array();
322 arr_add = new Array();
323 map_add = new Array();
324 idx_mod = new Array();
325 arr_mod = new Array();
326 map_cur = new Array();
328 // find removed entries
329 for (i = 0 ; i < standup_data_old.length ; i++) {
330 for (e = 0 ; e < data.length ; e++) {
331 if (standup_data_old[i][1] == data[e][1]) {
335 if (e == data.length) {
336 idx_del[idx_del_n++] = i;
340 /* modified entries */
341 if (standup_data_old[i][0] != data[e][0] ||
342 standup_data_old[i].length != data[e].length ||
343 (data[e].length == 3 && standup_data_old[i][2] != data[e][2])) {
344 arr_mod[idx_mod_n] = data[e];
345 idx_mod[idx_mod_n++] = i;
352 for (e = 0 ; e < data.length ; e++) {
353 for (i = 0 ; i < standup_data_old.length ; i++) {
354 if (data[e][1] == standup_data_old[i][1] ) {
358 if (i == standup_data_old.length) {
359 // console.log("ADD: "+data[e][1]);
360 arr_add[idx_add_n] = data[e];
361 map_add[idx_add_n++] = e;
365 // TODO: qui travaso add in del
368 // alert("del: ["+j_stand_tdcont(standup_data_old[idx_del[i_del]])+"]");
369 for (i = 0 , i_del = 0, i_mod = 0, i_add = 0, curtag = table_walk($("standup")) ; curtag != null ; curtag = table_walk(curtag), i++ ) {
370 // console.log("cur.id: "+curtag.id);
372 // alert("i: "+i+" tagname: "+curtag.tagName+" innerHTML: ["+curtag.innerHTML+"]");
373 // console.log("inloop["+i+"]: "+curtag.tagName+" ID: "+curtag.id);
374 if (curtag.innerHTML == "") {
375 // console.log("innerHTML == none");
376 if (i_add < idx_add_n) {
377 // console.log(" to be new");
378 // console.log(" add: CONT:"+j_stand_tdcont(arr_add[i_add]));
379 curtag.innerHTML = j_stand_tdcont(arr_add[i_add]);
380 curtag.id = map_add[i_add];
385 // else if (i_del < idx_del_n && curtag.innerHTML == j_stand_tdcont(standup_data_old[idx_del[i_del]])) {
386 else if (i_del < idx_del_n && curtag.id == idx_del[i_del]) {
387 // console.log("to be cancel["+i+"]: ID: "+curtag.id);
388 if (i_add < idx_add_n) {
389 // console.log(" to be new");
390 // console.log(" add: CONT:"+j_stand_tdcont(arr_add[i_add]));
391 curtag.innerHTML = j_stand_tdcont(arr_add[i_add]);
392 curtag.id = map_add[i_add];
396 // console.log(" to be del");
397 curtag.innerHTML = "";
402 // else if (i_mod < idx_mod_n && curtag.innerHTML == j_stand_tdcont(standup_data_old[idx_mod[i_mod]])) {
403 else if (i_mod < idx_mod_n && curtag.id == idx_mod[i_mod]) {
404 // console.log(" to be mod");
405 // console.log("mod: "+idx_mod[i_mod]+ " CONT:"+j_stand_tdcont(arr_mod[i_mod]));
406 curtag.innerHTML = j_stand_tdcont(arr_mod[i_mod]);
407 curtag.id = map_cur[curtag.id];
411 curtag.id = map_cur[curtag.id];
413 // console.log("fineloop");
415 for (i ; i_add < idx_add_n ; i_add++, i++) {
416 // console.log("ADD: "+i+" arr_add: "+ arr_add[i_add][1]);
417 td = document.createElement("td");
418 td.className = "room_standup";
419 td.id = map_add[i_add];
420 td.innerHTML = j_stand_tdcont(arr_add[i_add]);
422 table_add($("standup"), td);
424 standup_data_old = data;
427 var usr = $("standup").getElementsByClassName("id_usr");
428 for (i = 0 ; i < usr.length ; i++) {
429 addEvent(usr[i], "click", click_update_cb);
434 window.onbeforeunload = null;
435 window.onunload = null;
440 var g_user_info_target = "";
442 function info_show(username)
444 // ret = server_request('mesg', 'prefs|save','__POST__', 'prefs', JSON.stringify(g_prefs));
445 var info_in = JSON.parse(server_request('mesg', 'chatt|/info ' + username));
448 if (info_in.ret == 0) {
449 var fields = { login: { type: 'value' },
450 state: { type: 'value' },
451 guar: { type: 'value' },
452 match: { type: 'value' },
453 game: { type: 'value' },
454 friend: { type: 'radio' } };
456 info = new Fieldify($('info'), fields);
457 info.populate(info_in);
461 console.log("some error: open a dialog");
463 // FIXME: just to be finished
467 function click_update_cb(e)
469 if (g_user_info_target == e.target.innerHTML) {
470 g_user_info_target = "";
471 info_show(e.target.innerHTML);
474 g_user_info_target = e.target.innerHTML;
478 function j_tab_cont(table_idx, data)
483 for (i = 0 ; i < data.length ; i++) {
484 content += j_stand_tdcont(data[i]);
488 $("table"+table_idx).innerHTML = content;
489 var usr = $("table"+table_idx).getElementsByClassName("id_usr");
490 for (i = 0 ; i < usr.length ; i++) {
491 addEvent(usr[i], "click", click_update_cb);
495 function j_tab_act_cont(idx, act)
499 $("table_act"+idx).innerHTML = '<input type="button" class="button" name="xhenter'+idx+'" value="'+(g_lang == 'en' ? "Sit down." : "Mi siedo.")+'" onclick="act_sitdown('+idx+');">';
501 else if (act == 'sitreser') {
503 $("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")+'">';
505 else if (act == 'sitcert') {
507 $("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")+'">';
509 else if (act == 'wake') {
511 $("table_act"+idx).innerHTML = '<input type="button" class="button" name="xwakeup" value="'+(g_lang == 'en' ? "Wake up." : "Mi alzo.")+'" onclick="act_wakeup();">';
513 else if (act == 'resercert') {
515 $("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">';
517 else if (act == 'reserved') {
519 $("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">';
522 $("table_act"+idx).innerHTML = '';
526 function j_check_login(login, ret)
528 if (login.length > 12) {
530 ret.ret += (g_lang == 'en' ? "Nickname too long." : "Nickname troppo lungo.");
533 var old_c = '', old_ct = 0;
535 for (i = 0 ; i < login.length ; i++) {
536 if ((login[i] >= '0' && login[i] <= '9') ||
537 (login[i] >= 'a' && login[i] <= 'z') ||
538 (login[i] >= 'A' && login[i] <= 'Z')) {
539 if (old_c != login[i]) {
546 ret.ret = (g_lang == 'en' ? "More than three contiguous '" + old_c + "' not allowed." :
547 "Il nickname contiene più di tre caratteri '" + old_c + "' consecutivi.");
556 ret.ret = (g_lang == 'en' ? "Nickname includes not allowed '" + login[i] + "' character." :
557 "Il nickname contiene un carattere '" + login[i] + "' non consentito.");
566 function j_new_apprentice(form)
568 var ret = { ret: '' };
572 if (form.elements['realsub'].value == "close") {
573 $('apprentice_div').style.display = 'none';
577 if (j_check_login(form.elements['nameid'].value, ret) == false ||
578 j_check_email(form.elements['emailid'].value, ret) == false) {
580 no = new notify(gst, "<br><b>" + ret.ret + "</b><br>", 1, (g_lang == 'en' ? "Close." : "Chiudi."), 280, 100);
584 // submit the request
585 token = server_request('mesg', 'apprentice',
586 'cli_name', encodeURIComponent(form.elements['nameid'].value),
587 'cli_email', encodeURIComponent(form.elements['emailid'].value),
591 $('apprentice_div').style.display = "none";
592 no = new notify(gst, "<br>Richiesta inviata con successo.<br>Riceverai a breve un' e-mail per verificare la correttezza dell'indirizzo.<br>", 1, (g_lang == 'en' ? "Close." : "Chiudi."), 280, 100);
595 no = new notify(gst, "<br>" + token + "<br>", 1, (g_lang == 'en' ? "Close." : "Chiudi."), 280, 100);
603 function j_login_manager(form)
607 if (form.elements['passid'].value == '')
611 // console.log("richiesta token");
613 token = server_request('mesg', 'getchallenge', 'cli_name', encodeURIComponent(form.elements['nameid'].value));
614 tokens = token.split('|');
616 // console.log('XX token: '+token);
617 // console.log(tokens);
621 token = calcMD5(tokens[1]+calcMD5(form.elements['passid'].value));
623 form.elements['passid_private'].value = token;
624 form.elements['passid'].value = ""; // FIXME da sost con la stessa len di A
632 function login_formtext_hilite()
634 formtext_hilite($("nameid"));
635 formtext_hilite($("passid"));
636 formsub_hilite($("sub"));
639 function login_init()
642 login_formtext_hilite();
645 function warrant_formtext_hilite(form)
648 formtext_hilite($("nameid"));
649 formtext_hilite($("emailid"));
650 formsub_hilite($("subid"));
651 formsub_hilite($("cloid"));
653 formtext_hilite(form.elements['name']);
654 formtext_hilite(form.elements['email']);
655 formsub_hilite(form.elements['sub']);
656 formsub_hilite(form.elements['clo']);
659 function mesgtoadm_formtext_hilite(form)
662 formtext_hilite($("subjid"));
663 formtext_hilite($("mesgid"));
664 formsub_hilite($("subid"));
665 formsub_hilite($("cloid"));
667 formtext_hilite(form.elements['subj']);
668 formtext_hilite(form.elements['mesg']);
669 formsub_hilite(form.elements['sub']);
670 formsub_hilite(form.elements['clo']);
674 function j_check_email(email, ret)
676 if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,10})+$/.test(email))
678 ret.ret += (g_lang == 'en' ? "Invalid email address. " :
679 "Indirizzo e-mail non valido.");
684 function j_authbox(form)
686 var no, ret = { "ret": "" };
689 if (form.elements['realsub'].value == "chiudi") {
690 $('authbox').style.visibility = "hidden";
694 if (form.elements['name'].value == '' || j_check_email(form.elements['email'].value, ret) == false) {
697 (g_lang == 'en' ? "<br><b>" + ret.ret + "</b><br>please, fix." :
698 "<br><b>" + ret.ret + "</b><br>correggere, per favore."),
699 1, (g_lang == 'en' ? "close" : "chiudi"), 280, 100);
703 // submit the request
704 token = server_request('mesg', 'warranty',
705 'cli_name', encodeURIComponent(form.elements['name'].value),
706 'cli_email', encodeURIComponent(form.elements['email'].value) );
708 $('authbox').style.visibility = "hidden";
709 form.elements['name'].value = "";
710 form.elements['email'].value = "";
718 function authbox(w, h)
724 box.style.zIndex = 200;
725 box.style.width = w+"px";
726 box.style.marginLeft = -parseInt(w/2)+"px";
727 box.style.height = h+"px";
728 box.style.top = parseInt((document.body.clientHeight - h) / 2) + document.body.scrollTop;
730 warrant_formtext_hilite($('auth_form'));
732 box.style.visibility = "visible";
736 function j_mesgtoadmbox(form)
741 if (form.elements['realsub'].value == "cloid") {
742 $('mesgtoadmbox').style.visibility = "hidden";
746 if (form.elements['mesg'].value == '' || form.elements['subj'].value == '') {
748 no = new notify(gst, (g_lang == 'en' ? "<br><b>subject</b> and the <b>message</b> cannot be void;<br>please, fix them." :
749 "<br>Il <b>soggetto</b> e il <b>messaggo</b> non possono essere vuoti;<br>correggeteli per favore."), 1,
750 (g_lang == 'en' ? "close" : "chiudi"), 280, 100);
754 // submit the request
755 token = server_request('mesg', 'mesgtoadm',
756 'cli_subj', encodeURIComponent(form.elements['subj'].value),
757 'cli_mesg', encodeURIComponent(form.elements['mesg'].value) );
759 $('mesgtoadmbox').style.visibility = "hidden";
760 form.elements['subj'].value = "";
761 form.elements['mesg'].value = "";
769 function mesgtoadmbox(w, h)
773 box = $('mesgtoadmbox');
775 box.style.zIndex = 200;
776 box.style.width = w+"px";
777 box.style.marginLeft = -parseInt(w/2)+"px";
778 box.style.height = h+"px";
779 box.style.top = parseInt((document.body.clientHeight - h) / 2) + document.body.scrollTop;
781 mesgtoadm_formtext_hilite($('mesgtoadm_form'));
783 box.style.visibility = "visible";
784 $('mesgtoadm_form').elements['subj'].focus();
787 function j_pollbox(form)
792 // submit the request
794 for (i = 0 ; i < form.elements.length ; i++) {
795 if (form.elements[i].checked == true)
798 if (i == form.elements.length) {
800 no = new notify(gst, (g_lang == 'en' ? "<br>You must choose ah item;<br> please, fix it." :
801 "<br>Non hai espresso nessuna preferenza;<br> correggi per favore."), 1,
802 (g_lang == 'en' ? "close" : "chiudi"), 280, 100);
806 choose = form.elements[i].value;
808 token = server_request('mesg', 'poll',
809 'cli_choose', encodeURIComponent(choose) );
812 // TODO: mesg to user
813 // $('mesgtoadmbox').style.visibility = "hidden";
822 function sideslide(domobj, height, step)
827 this.domobj = domobj;
828 this.height = height;
834 sideslide.prototype = {
849 this.id = setTimeout(function () { instant.sideslide_cb(); }, this.twait);
852 sideslide_cb: function() {
855 if (this.st == 'wait') {
858 this.id = setInterval(function () { instant.sideslide_cb(); }, 100);
860 else if (this.st == 'scroll') {
861 this.scroll += (this.step / 10);
862 if (this.scroll >= this.height - this.step) {
865 this.domobj.scrollTop = this.scroll;
867 if (this.countdown == 0) {
870 this.id = setTimeout(function () { instant.sideslide_cb(); }, this.twait);
877 if (this.id != null) {
878 clearInterval(this.id);