/*
* brisk - room.js
*
- * Copyright (C) 2006-2012 Matteo Nastasi
- * mailto: nastasi@alternativeoutput.it
+ * Copyright (C) 2006-2014 Matteo Nastasi
+ * mailto: nastasi@alternativeoutput.it
* matteo.nastasi@milug.org
* web: http://www.alternativeoutput.it
*
*/
-/*
+/*
data = [ [ flags, name ], ... ]
-
-*/
-
-
-var l_list_all = 0x00;
-var l_list_auth = 0x01;
-var l_list_isol = 0x02;
-
-function client_prefs()
-{
-}
-client_prefs.prototype = {
- listen: -1
-}
+*/
-function state_add(flags)
+function state_add(flags, comp)
{
var content = "", supercont = "";
var st, superst, name = "", supername = "", supersfx = "";
}
if ((flags & 0xf0000) != 0) {
- superst = flags & 0xf0000;
+ superst = flags & 0x20000;
if (name != "") {
- supersfx = "_side";
+ supersfx = "_side";
}
switch (superst) {
case 0x20000:
- supername = "superuser"+supersfx+".png";
+ if (comp != null) {
+ supername = "suprend.php?comp="+comp+"&sfx="+supersfx;
+ }
+ else {
+ supername = "img/superuser"+supersfx+".png";
+ }
supertit = (g_lang == 'en' ? "Brisk Supporter" : "Brisk Supporter");
break;
}
}
if (supername != "") {
- content += ' <img title="'+supertit+'" class="inline" src="img/'+supername+'">';
+ content += ' <img title="'+supertit+'" class="inline" src="'+supername+'">';
}
-
+
if (name != "") {
content += ' <img title="'+tit+'" class="inline" src="img/'+name+'">';
}
do {
// console.log("wt: "+curtag.tagName);
- if (curtag.tagName.toLowerCase() == "div" ||
+ if (curtag.tagName.toLowerCase() == "div" ||
curtag.tagName.toLowerCase() == "table") {
curtag = curtag.firstChild;
}
else
curtag = null;
} while (curtag != null);
-
+
curtag = tbody.firstChild;
ct = 0;
do {
{
do {
// console.log("wt: "+curtag.tagName);
- if (curtag.tagName.toLowerCase() == "div" ||
+ if (curtag.tagName.toLowerCase() == "div" ||
curtag.tagName.toLowerCase() == "table" ||
curtag.tagName.toLowerCase() == "tbody") {
curtag = curtag.firstChild;
if (1 == 0) {
if (curtag == null)
- alert("outtag == null");
+ alert("outtag == null");
else
alert("outtag: "+curtag.tagName);
}
return (user_dec_and_state(el));
}
+/*
+ ddata = [ [ <flags-int>, <nick-str>, <color-str> ], ... ]
+ */
function j_stand_cont(ddata)
{
var i, ii;
else
data = ddata;
+ // WARNING:
+ //
+ // managing update needs this branch (for few users and the else!!)
+ //
if (standup_data_old == null || data.length < 4) {
- // if (standup_data_old == null) {
-
content = '<table cols="'+(data.length < 4 ? data.length : 4)+'" class="table_standup">';
for (i = 0 ; i < data.length ; i++) {
if ((i % 4) == 0)
content += '<td id="'+i+'" class="room_standup">';
content += j_stand_tdcont(data[i]);
content += '</td>';
-
+
if ((i % 4) == 3)
content += '</tr>';
}
if ((i % 4) < 3)
content += '</tr>';
content += '</table>';
-
- $("standup").innerHTML = content;
-
- // console.log("inizio");
- // for (i = 0 , curtag = table_walk($("standup")) ; curtag != null ; curtag = table_walk(curtag), i++ ) {
- // console.log("inloop["+i+"]: "+curtag.tagName+" ID: "+curtag.id);
- // }
- // console.log("fine "+i);
-
- // walktable($("standup"), nextag);
- // console.log($("standup").firstChild);
- // console.log($("standup").firstChild.firstChild.firstChild.firstChild);
- // log_walk($("standup"));
+ $("standup").innerHTML = content;
standup_data_old = data;
}
idx_mod = new Array();
arr_mod = new Array();
map_cur = new Array();
-
+
// find removed entries
for (i = 0 ; i < standup_data_old.length ; i++) {
for (e = 0 ; e < data.length ; e++) {
}
else {
/* modified entries */
- if (standup_data_old[i][0] != data[e][0]) {
+ if (standup_data_old[i][0] != data[e][0] ||
+ standup_data_old[i].length != data[e].length ||
+ (data[e].length == 3 && standup_data_old[i][2] != data[e][2])) {
arr_mod[idx_mod_n] = data[e];
idx_mod[idx_mod_n++] = i;
}
map_add[idx_add_n++] = e;
}
}
-
+
// TODO: qui travaso add in del
i_del = 0;
table_add($("standup"), td);
}
-
standup_data_old = data;
- return;
}
- // $("esco").innerHTML = '<input class="button" name="logout" value="Esco." onclick="esco_cb();" type="button">';
+
+ var usr = $("standup").getElementsByClassName("id_usr");
+ for (i = 0 ; i < usr.length ; i++) {
+ addEvent(usr[i], "click", click_update_cb);
+ }
}
function esco_cb() {
- window.onbeforeunload = null;
- window.onunload = null;
- // nonunload = true;
+ window.onbeforeunload = null;
+ window.onunload = null;
+ // nonunload = true;
act_logout(0);
};
+var g_user_info_target = "";
+function info_show(username)
+{
+ // ret = server_request('mesg', 'prefs|save','__POST__', 'prefs', JSON.stringify(g_prefs));
+ var info_in = JSON.parse(server_request('mesg', 'chatt|/info ' + username));
+ var info = null;
+
+ if (info_in.ret == 0) {
+ var fields = { login: { type: 'value' },
+ state: { type: 'value' },
+ guar: { type: 'value' },
+ match: { type: 'value' },
+ game: { type: 'value' },
+ friend: { type: 'radio' },
+ skill: { type: 'radio' },
+ trust: { type: 'radio' }
+ };
+
+ info = new Fieldify($('info'), fields);
+ info.populate(info_in);
+ info.visible(true);
+ }
+ else {
+ console.log("some error: open a dialog");
+ }
+ // FIXME: just to be finished
+ console.log(info);
+}
+
+function click_update_cb(e)
+{
+ if (g_user_info_target == e.target.innerHTML) {
+ g_user_info_target = "";
+ info_show(e.target.innerHTML);
+ }
+ else {
+ g_user_info_target = e.target.innerHTML;
+ }
+}
function j_tab_cont(table_idx, data)
{
var content = '';
for (i = 0 ; i < data.length ; i++) {
- // content += user_decorator(data[i]);
- // content += state_add(data[i][0]);
content += j_stand_tdcont(data[i]);
content += '<br>';
}
$("table"+table_idx).innerHTML = content;
+ var usr = $("table"+table_idx).getElementsByClassName("id_usr");
+ for (i = 0 ; i < usr.length ; i++) {
+ addEvent(usr[i], "click", click_update_cb);
+ }
}
function j_tab_act_cont(idx, act)
$("table_act"+idx).innerHTML = '<input type="button" class="button" name="xhenter'+idx+'" value="'+(g_lang == 'en' ? "Sit down." : "Mi siedo.")+'" onclick="act_sitdown('+idx+');">';
}
else if (act == 'sitreser') {
- // <img class="nobo" title="tavolo riservato agli utenti registrati" style="display: inline; margin-right: 80px;" src="img/okauth.png">
// MLANG 1
- $("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+');">';
+ $("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")+'">';
+ }
+ else if (act == 'sitcert') {
+ // MLANG 1
+ $("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")+'">';
}
else if (act == 'wake') {
// MLANG 1
$("table_act"+idx).innerHTML = '<input type="button" class="button" name="xwakeup" value="'+(g_lang == 'en' ? "Wake up." : "Mi alzo.")+'" onclick="act_wakeup();">';
}
+ else if (act == 'resercert') {
+ // MLANG 1
+ $("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">';
+ }
else if (act == 'reserved') {
// MLANG 1
$("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">';
}
}
+function j_check_login(login, ret)
+{
+ if (login.length > 12) {
+ // FIXME LANG
+ ret.ret += (g_lang == 'en' ? "Nickname too long." : "Nickname troppo lungo.");
+ return (false);
+ }
+ var old_c = '', old_ct = 0;
+
+ for (i = 0 ; i < login.length ; i++) {
+ if ((login[i] >= '0' && login[i] <= '9') ||
+ (login[i] >= 'a' && login[i] <= 'z') ||
+ (login[i] >= 'A' && login[i] <= 'Z')) {
+ if (old_c != login[i]) {
+ old_c = login[i];
+ old_ct = 0;
+ }
+ else {
+ if (old_ct > 3) {
+ // FIXME LANG
+ ret.ret = (g_lang == 'en' ? "More than three contiguous '" + old_c + "' not allowed." :
+ "Il nickname contiene piĆ¹ di tre caratteri '" + old_c + "' consecutivi.");
+ return (false);
+ }
+ }
+ old_ct++;
+ continue;
+ }
+ else {
+ // FIXME LANG
+ ret.ret = (g_lang == 'en' ? "Nickname includes not allowed '" + login[i] + "' character." :
+ "Il nickname contiene un carattere '" + login[i] + "' non consentito.");
+ return (false);
+ }
+ }
+
+ return (true);
+}
+
+
+function j_new_apprentice(form)
+{
+ var ret = { ret: '' };
+ var token;
+
+ do {
+ if (form.elements['realsub'].value == "close") {
+ $('apprentice_div').style.display = 'none';
+ break;
+ }
+
+ if (j_check_login(form.elements['nameid'].value, ret) == false ||
+ j_check_email(form.elements['emailid'].value, ret) == false) {
+
+ no = new notify(gst, "<br><b>" + ret.ret + "</b><br>", 1, (g_lang == 'en' ? "Close." : "Chiudi."), 280, 100);
+ break;
+ }
+
+ // submit the request
+ token = server_request('mesg', 'apprentice',
+ 'cli_name', encodeURIComponent(form.elements['nameid'].value),
+ 'cli_email', encodeURIComponent(form.elements['emailid'].value),
+ 'cli_lang', g_lang);
+ if (token == "1") {
+ // FIXME LANG
+ $('apprentice_div').style.display = "none";
+ 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);
+ }
+ else {
+ no = new notify(gst, "<br>" + token + "<br>", 1, (g_lang == 'en' ? "Close." : "Chiudi."), 280, 100);
+ }
+ } while (0);
+
+ return (false);
+}
+
+
function j_login_manager(form)
{
var token;
/* richiede token */
token = server_request('mesg', 'getchallenge', 'cli_name', encodeURIComponent(form.elements['nameid'].value));
tokens = token.split('|');
-
+
// console.log('XX token: '+token);
// console.log(tokens);
if (token == null)
return (false);
token = calcMD5(tokens[1]+calcMD5(form.elements['passid'].value));
-
+
form.elements['passid_private'].value = token;
form.elements['passid'].value = ""; // FIXME da sost con la stessa len di A
return (true);
}
-
+
return (false);
}
}
-function j_check_email(email)
+function j_check_email(email, ret)
{
- if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email))
+ if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,10})+$/.test(email))
return (true);
+ ret.ret += (g_lang == 'en' ? "Invalid email address. " :
+ "Indirizzo e-mail non valido.");
+
return (false);
}
function j_authbox(form)
{
- var no;
+ var no, ret = { "ret": "" };
do {
if (form.elements['realsub'].value == "chiudi") {
break;
}
- if (form.elements['name'].value == '' || j_check_email(form.elements['email'].value) == false) {
+ if (form.elements['name'].value == '' || j_check_email(form.elements['email'].value, ret) == false) {
// MLANG 2-4
- no = new notify(gst,
- (g_lang == 'en' ? "<br><b>nickname</b> and/or <b>e-mail</b> fields are invalid;<br>please, fix them." :
- "<br>I campi <b>nickname</b> e/o <b>e-mail</b> non sono validi;<br> correggeteli per favore."),
- 1, (g_lang == 'en' ? "close" : "chiudi"), 280, 100);
+ no = new notify(gst,
+ (g_lang == 'en' ? "<br><b>" + ret.ret + "</b><br>please, fix." :
+ "<br><b>" + ret.ret + "</b><br>correggere, per favore."),
+ 1, (g_lang == 'en' ? "close" : "chiudi"), 280, 100);
break;
}
// submit the request
- token = server_request('mesg', 'warranty',
+ token = server_request('mesg', 'warranty',
'cli_name', encodeURIComponent(form.elements['name'].value),
'cli_email', encodeURIComponent(form.elements['email'].value) );
if (token == "1") {
function j_mesgtoadmbox(form)
{
- var no;
+ var no;
do {
- if (form.elements['realsub'].value == "chiudi") {
+ if (form.elements['realsub'].value == "cloid") {
$('mesgtoadmbox').style.visibility = "hidden";
break;
}
if (form.elements['mesg'].value == '' || form.elements['subj'].value == '') {
// MLANG 1-3
no = new notify(gst, (g_lang == 'en' ? "<br><b>subject</b> and the <b>message</b> cannot be void;<br>please, fix them." :
- "<br>Il <b>soggetto</b> e il <b>messaggo</b> non possono essere vuoti;<br>correggeteli per favore."), 1,
- (g_lang == 'en' ? "close" : "chiudi"), 280, 100);
+ "<br>Il <b>soggetto</b> e il <b>messaggo</b> non possono essere vuoti;<br>correggeteli per favore."), 1,
+ (g_lang == 'en' ? "close" : "chiudi"), 280, 100);
break;
}
-
+
// submit the request
- token = server_request('mesg', 'mesgtoadm',
+ token = server_request('mesg', 'mesgtoadm',
'cli_subj', encodeURIComponent(form.elements['subj'].value),
'cli_mesg', encodeURIComponent(form.elements['mesg'].value) );
if (token == "1") {
function j_pollbox(form)
{
- var no, i, choose;
+ var no, i, choose;
do {
// submit the request
-
+
for (i = 0 ; i < form.elements.length ; i++) {
if (form.elements[i].checked == true)
break;
if (i == form.elements.length) {
// MLANG 1-3
no = new notify(gst, (g_lang == 'en' ? "<br>You must choose ah item;<br> please, fix it." :
- "<br>Non hai espresso nessuna preferenza;<br> correggi per favore."), 1,
- (g_lang == 'en' ? "close" : "chiudi"), 280, 100);
+ "<br>Non hai espresso nessuna preferenza;<br> correggi per favore."), 1,
+ (g_lang == 'en' ? "close" : "chiudi"), 280, 100);
return false;
}
else
choose = form.elements[i].value;
- token = server_request('mesg', 'poll',
+ token = server_request('mesg', 'poll',
'cli_choose', encodeURIComponent(choose) );
if (token == "1") {
return (false);
}
-function prefs_assign(content)
-{
- var prefs_new;
- var s;
-
- s = "prefs_new = " + content;
- eval(s);
-
- return (prefs_new);
-}
-
-var prefs_list_idx = new Array( 0x00, 0x01, 0x02 );
-var prefs_list_id = new Array( "all", "auth", "isol" );
-
-function prefs_apply(prefs_new, is_update, is_volat)
-{
- var i;
- var relo = false;
-
- if (typeof(g_prefs) == 'undefined')
- return false;
-
- /* listen management */
- if (g_prefs.listen != prefs_new.listen) {
- for (i = 0 ; i < prefs_list_idx.length ; i++) {
- set_checked_value($('ra_listen_'+prefs_list_id[i]), prefs_new.listen);
- if (prefs_new.listen == prefs_list_idx[i]) {
- if (!is_volat)
- $('list_'+prefs_list_id[i]).style.color = 'red';
- $('list_info').innerHTML = mlang_commons['tit_list'][i][g_lang];
- }
- else {
- if (!is_volat)
- $('list_'+prefs_list_id[i]).style.color = 'black';
- }
- }
-
- relo = true;
- }
-
-
- // TO BE ANALYZED !!!
- // if (is_update) {
- // createCookie("CO_list", what, 24*365, cookiepath);
- // }
-
-
- if (relo || !is_update) {
- for (i = g_tables_auth_n ; i < g_tables_n ; i++) {
- if (i % 4 == 0) {
- $('tr_noauth'+i).style.display = (prefs_new.listen == l_list_isol ? 'none' : '');
- }
-
- $('td_noauth'+i).style.display = (prefs_new.listen == l_list_isol ? 'none' : '');
- }
- if (prefs_new.listen == l_list_isol) {
- tra.hide_noauth();
- }
- else {
- tra.show_noauth();
- }
-
- if (false) {
- // ricalculation of standup area
- if (standup_data_old != null) {
- standup_data = standup_data_old;
- standup_data_old = null;
- j_stand_cont(standup_data);
- }
- }
- }
-
- g_prefs.listen = prefs_new.listen;
-}
-
-function prefs_load(content, is_update, is_volat)
-{
- var prefs_new;
-
- if ((prefs_new = prefs_assign(content)) == null)
- return false;
-
- return prefs_apply(prefs_new, is_update, is_volat);
-}
-
-function prefs_save()
-{
- if (typeof(g_prefs) == 'undefined')
- return false;
-
- console.log(server_request('mesg', 'prefs', '__POST__', 'prefs', JSON.stringify(g_prefs)));
- // close the win:
- // $('preferences').style.visibility = 'hidden';
-}
-
-function prefs_update()
-{
- var i;
- var prefs_new;
- var relo = false;
-
- if (typeof(g_prefs) == 'undefined')
- return false;
-
- prefs_new = new client_prefs();
-
- /* listen management */
- for (i = 0 ; i < prefs_list_idx.length ; i++) {
- prefs_new.listen = get_checked_value($('ra_listen_'+prefs_list_id[i]));
- if (prefs_new.listen != '')
- break;
- }
-
- /* TODO SAVE TEMPORARY */
- /* from form to struct */
- console.log("Prefs_update");
- prefs_apply(prefs_new, true, true);
-}
-
-function list_set(what, is_update, info)
-{
- var i;
- var relo = false;
- var old_st = readCookie("CO_list");
-
- if (what == 'auth') {
- $('list_auth').style.color = 'red';
- $('list_isol').style.color = 'black';
- $('list_all').style.color = 'black';
- if (old_st == 'isolation')
- relo = true;
- g_listen = l_list_auth;
- }
- else if (what == 'isolation') {
- $('list_auth').style.color = 'black';
- $('list_isol').style.color = 'red';
- $('list_all').style.color = 'black';
- if (old_st != 'isolation')
- relo = true;
- g_listen = l_list_isol;
- }
- else {
- $('list_auth').style.color = 'black';
- $('list_isol').style.color = 'black';
- $('list_all').style.color = 'red';
- if (old_st == 'isolation')
- relo = true;
- g_listen = l_list_all;
- }
-
- set_checked_value($('ra_listen_auth'), what);
- set_checked_value($('ra_listen_isol'), what);
- set_checked_value($('ra_listen_all'), what);
-
- $('list_info').innerHTML = info;
- if (is_update) {
- createCookie("CO_list", what, 24*365, cookiepath);
- }
-
-
- if (relo || !is_update) {
- for (i = g_tables_auth_n ; i < g_tables_n ; i++) {
-
- if (i % 4 == 0) {
- $('tr_noauth'+i).style.display = (what == 'isolation' ? 'none' : '');
- }
-
- $('td_noauth'+i).style.display = (what == 'isolation' ? 'none' : '');
- }
- if (what == 'isolation') {
- tra.hide_noauth();
- }
- else {
- tra.show_noauth();
- }
-
- if (false) {
- // ricalculation of standup area
- if (standup_data_old != null) {
- standup_data = standup_data_old;
- standup_data_old = null;
- j_stand_cont(standup_data);
- }
- }
- }
-}
function sideslide(domobj, height, step)
{
start: function() {
var instant = this;
-
+
this.st = 'wait';
this.id = setTimeout(function () { instant.sideslide_cb(); }, this.twait);
},