class notify enhanced, server_request enhanced
[brisk.git] / web / commons.js
index c950435..d016faf 100644 (file)
@@ -228,6 +228,7 @@ function send_mesg(mesg)
     var xhr_wr = createXMLHttpRequest();
     var is_conn = (sess == "not_connected" ? false : true);
     
+    // alert("xhr_wr: "+xhr_wr+"  is_conn: "+is_conn);
     xhr_wr.open('GET', 'index_wr.php?'+(is_conn ? 'sess='+sess+'&' : '')+'mesg='+mesg, (is_conn ? true : false));
     xhr_wr.onreadystatechange = function() { return; };
     xhr_wr.send(null);
@@ -239,20 +240,28 @@ function send_mesg(mesg)
     }
 }
 
-function server_request(mesg)
+function server_request()
 {
     var xhr_wr = createXMLHttpRequest();
-    
+    var i, collect = "";
+
+    if (arguments.length > 0) {
+        for (i = 0 ; i < arguments.length ; i+= 2) {
+            collect += (i == 0 ? "" : "&") + arguments[i] + "=" + encodeURIComponent(arguments[i+1]);
+        }
+    }
+    // alert("Args: "+arguments.length);
+
     var is_conn = (sess == "not_connected" ? false : true);
     
-    console.log("server_request:preresp: "+xhr_wr.responseText);
+    // console.log("server_request:preresp: "+xhr_wr.responseText);
 
-    xhr_wr.open('GET', 'index_wr.php?'+(is_conn ? 'sess='+sess+'&' : '')+'mesg='+mesg, false);
+    xhr_wr.open('GET', 'index_wr.php?'+(is_conn ? 'sess='+sess+'&' : '')+collect, false);
     xhr_wr.onreadystatechange = function() { return; };
     xhr_wr.send(null);
     
     if (xhr_wr.responseText != null) {
-        console.log("server_request:resp: "+xhr_wr.responseText);
+        // console.log("server_request:resp: "+xhr_wr.responseText);
         return (xhr_wr.responseText);
     } 
     else
@@ -386,11 +395,13 @@ function safelascio()
 function act_logout(exitlock)
 {
     send_mesg("logout|"+exitlock);
+    // alert("IZZO");
 }
 
 function act_reload()
 {
     window.onunload = null;
+    window.onbeforeunload = null;
     document.location.reload();
 }
 
@@ -399,8 +410,8 @@ function act_shutdown()
     var c = 0;
 
     send_mesg("shutdown");
-    while (xhr_wr.readyState != 4)
-       c++;
+    // while (xhr_wr.readyState != 4)
+    // c++;
 }
 
 function postact_logout()
@@ -687,13 +698,23 @@ function notify(st, text, tout, butt, w, h)
     clodiv.className = "notify_clo";
     clodiv.appendChild(clo);
 
-    box = document.createElement("div");
+    cont = document.createElement("div");
+
+    cont.style.borderBottomStyle = "solid";
+    cont.style.borderBottomWidth = "1px";
+    cont.style.borderBottomColor = "gray";
+    cont.style.height = (h - 30)+"px";
+    cont.style.overflow = "auto";
+    cont.innerHTML = text;
+
+    box =  document.createElement("div");
     box.className = "notify";
-    box.innerHTML = text;
     box.style.zIndex = 200;
     box.style.width  = w+"px";
     box.style.marginLeft  = -parseInt(w/2)+"px";
     box.style.height = h+"px";
+    box.style.top = parseInt((document.body.clientHeight - h) / 2) + document.body.scrollTop;
+    box.appendChild(cont);
     box.appendChild(clodiv);
     box.style.visibility = "visible";
 
@@ -783,6 +804,8 @@ function choose_seed(card)
 {
     var i;
 
+    $("asta").style.visibility = "hidden"; 
+    $("astalascio").style.visibility = "hidden"; 
     $("chooseed").style.visibility = "visible";
     for (i = 0 ; i < 4 ; i++) {
        $("seed"+i).src = "img/"+i+""+card+".png";
@@ -791,19 +814,28 @@ function choose_seed(card)
     }
 }
 
+function italizer(ga)
+{
+    var pre, pos;
+    if (ga[0] & 2) 
+        return "<i>"+ga[1]+"</i>";
+    else
+        return ga[1];
+}
+
 function set_names(so,ea,ne,nw,we)
 {
 //    alert("EA: "+ea);
-    $("name").innerHTML = so; 
-    $("name").title = unescapeHTML(so); 
-    $("name_ea").innerHTML = ea;
-    $("name_ea").title = unescapeHTML(ea);
-    $("name_ne").innerHTML = ne;
-    $("name_ne").title = unescapeHTML(ne);
-    $("name_nw").innerHTML = nw;
-    $("name_nw").title = unescapeHTML(nw);
-    $("name_we").innerHTML = we;
-    $("name_we").title = unescapeHTML(we);
+    $("name").innerHTML = italizer(so);
+    $("name").title = unescapeHTML(so[1]); 
+    $("name_ea").innerHTML = italizer(ea);
+    $("name_ea").title = unescapeHTML(ea[1]);
+    $("name_ne").innerHTML = italizer(ne);
+    $("name_ne").title = unescapeHTML(ne[1]);
+    $("name_nw").innerHTML = italizer(nw);
+    $("name_nw").title = unescapeHTML(nw[1]);
+    $("name_we").innerHTML = italizer(we);
+    $("name_we").title = unescapeHTML(we[1]);
 
     return;
 }
@@ -891,10 +923,18 @@ var chatt_lines_n = 0;
 var CHATT_MAXLINES = 40;
 
 /* PRO CHATT */
-function chatt_sub(name,str)
+function chatt_sub(dt,data,str)
 {
     var must_scroll = false;
+    var name;
+    var flags;
+    var isauth;
 
+    flags = data[0];
+    if (flags & 0x02)
+        name = "<i>"+data[1]+"</i>";
+    else
+        name = data[1];
     // alert ($("txt").scrollTop + parseInt(getStyle($("txt"),"height", "height")) -  $("txt").scrollHeight);
 
   if ($("txt").scrollTop + parseInt(getStyle($("txt"),"height", "height")) -  $("txt").scrollHeight >= 0)
@@ -907,11 +947,11 @@ function chatt_sub(name,str)
       chatt_lines[i] = chatt_lines[i+1];
       $("txt").innerHTML += chatt_lines[i];
     }
-    chatt_lines[i] = "<b>"+name+"</b> "+str+ "<br>";
+    chatt_lines[i] = dt+"<b>"+name+"</b> "+str+ "<br>";
     $("txt").innerHTML += chatt_lines[i];
   }
   else {
-    chatt_lines[chatt_lines_n] = "<b>"+name+"</b> "+str+ "<br>";
+    chatt_lines[chatt_lines_n] = dt+"<b>"+name+"</b> "+str+ "<br>";
     $("txt").innerHTML += chatt_lines[chatt_lines_n];
     chatt_lines_n++;
   }
@@ -955,19 +995,29 @@ function eraseCookie(name) {
 var onunload_times = 0;
 
 
-function onunload_cb () {
+function onbeforeunload_cb () {
+    return("");
+}
+
+function onunload_cb_old () {
     var u = 0;
+    
+    //    if (nonunload == true)
+    //     return true;
+    
     if (onunload_times == 0) {
        var res = window.confirm("    Vuoi veramente abbandonare la briscola ?\n(clicca annulla o cancel se vuoi ricaricare la briscola)");
        if (res == true) {
            the_end = true; 
            act_shutdown();
-           while (1) 
-               u++;
+           // while (1) 
+           //  u++;
        }
        else {
            try {
-               location = self.location;
+               document.location.href = self.location; //  = self.location;
+                // alert ("passiamo di qui"+self.location);
+                return (false);
            } catch (e) {
                alert("Ripristino della briscola fallito, per non perdere la sessione ricaricare la pagina manualmente.");
            }
@@ -978,6 +1028,15 @@ function onunload_cb () {
     return(false);
 }
 
+function onunload_cb () {
+    
+    the_end = true; 
+
+    act_shutdown();
+    
+    return(false);
+}
+
 
 function room_checkspace(emme,tables,inpe)
 {
@@ -1005,7 +1064,8 @@ function room_checkspace(emme,tables,inpe)
     stand += "</tr>";
     $("standup").innerHTML = stand;
 
-    $("esco").innerHTML = "<input class=\"button\" name=\"logout\" type=\"button\" value=\"Esco.\" onclick=\"window.onunload = null; act_logout();\" type=\"button\">";
+    // VERIFY: what is this button ?
+    $("esco").innerHTML = "<input class=\"button\" name=\"logout\" type=\"button\" value=\"Esco.\" onclick=\"act_logout();\" type=\"button\">";
 }
 
 function  unescapeHTML(cont) {
@@ -1052,7 +1112,7 @@ function playsound(tag, sound) {
 
 function topbanner_init()
 {
-//    setInterval(topbanner_cb, 666);
+    setInterval(topbanner_cb, 666);
 ;
 }
 
@@ -1068,3 +1128,5 @@ function topbanner_cb()
 
     // console.log("A: "+a+"  B: "+b);
 }
+
+