enhanced prefs management
authorMatteo Nastasi (mop) <nastasi@alternativeoutput.it>
Tue, 5 Feb 2013 17:35:19 +0000 (18:35 +0100)
committerMatteo Nastasi (mop) <nastasi@alternativeoutput.it>
Tue, 5 Feb 2013 17:35:19 +0000 (18:35 +0100)
web/Obj/brisk.phh
web/commons.js
web/index.php
web/index_wr.php
web/room.js

index bd1edb8..36060d8 100644 (file)
@@ -928,7 +928,7 @@ class Room
 
     // for test: $prefs = new Client_prefs(USER_FLAG_LISTAUTH >> 2);
     $prefs = new Client_prefs(($user->flags & USER_FLAG_MAP_AUTH) >> 2);
-    $ret .= sprintf('prefs_load(\'%s\');', json_encode($prefs));
+    $ret .= sprintf('prefs_load(\'%s\', false, false);', json_encode($prefs));
 
     if(false) {
         if ($user->flags & USER_FLAG_ISOLAUTH) {
index 158dc54..f522ad5 100644 (file)
@@ -273,17 +273,28 @@ function send_mesg(mesg)
 }
 
 /*
-  request to server
+  sync request to server
   server_request([arg0=arg1[, arg2=arg3[, ...]]])
+  if var name == '__POST__' than all other vars will be managed as POST content
+                                 and the call will be a POST
  */
 function server_request()
 {
     var xhr_wr = createXMLHttpRequest();
-    var i, collect = "";
+    var i, collect = "", post_collect = null, is_post = false;
 
     if (arguments.length > 0) {
         for (i = 0 ; i < arguments.length ; i+= 2) {
-            collect += (i == 0 ? "" : "&") + arguments[i] + "=" + encodeURIComponent(arguments[i+1]);
+            if (arguments[i] == "__POST__") {
+                is_post = true;
+                post_collect = "";
+                i -= 1;
+                continue;
+            }
+            if (is_post)
+                post_collect += (post_collect == "" ? "" : "&") + arguments[i] + "=" + encodeURIComponent(arguments[i+1]);
+            else
+                collect += (i == 0 ? "" : "&") + arguments[i] + "=" + encodeURIComponent(arguments[i+1]);
         }
     }
     // alert("Args: "+arguments.length);
@@ -292,9 +303,15 @@ function server_request()
     
     // console.log("server_request:preresp: "+xhr_wr.responseText);
 
-    xhr_wr.open('GET', 'index_wr.php?'+(is_conn ? 'sess='+sess+'&' : '')+collect, false);
+    if (is_post) {
+        xhr_wr.open('POST', 'index_wr.php?'+(is_conn ? 'sess='+sess+'&' : '')+collect, false);
+        xhr_wr.setRequestHeader("Content-type","application/x-www-form-urlencoded");
+    }
+    else {
+        xhr_wr.open('GET', 'index_wr.php?'+(is_conn ? 'sess='+sess+'&' : '')+collect, false);
+    }
     xhr_wr.onreadystatechange = function() { return; };
-    xhr_wr.send(null);
+    xhr_wr.send(post_collect);
     
     if (xhr_wr.responseText != null) {
         // console.log("server_request:resp: "+xhr_wr.responseText);
index 7e4ec9d..118c8d8 100644 (file)
@@ -52,7 +52,7 @@ $mlang_room = array( 'userpasserr'  => array('it' => 'Utente e/o password errati
                                              'en' => 'back to tables'),
                      'btn_exit'     => array('it' => 'Esco.',
                                              'en' => 'Exit.'),
-                     'btn_prefs_update' => array('it' => 'Salva.',
+                     'btn_prefs_save' => array('it' => 'Salva.',
                                              'en' => 'Save.'),
                      'btn_prefs_close' => array('it' => 'Chiudi.',
                                              'en' => 'Close.'),
@@ -1207,17 +1207,17 @@ type="submit" class="button" onclick="this.form.elements['realsub'].value = 'chi
 <table style="border: 1px solid gray;"><tr><th style="background-color: #cccccc;">
 <?php echo $mlang_room['itm_list'][$G_lang];?>
 </th></tr>
-<tr><td><input style="vertical-align: bottom;" id="ra_listen_all" type="radio" name="listen" value="0" onclick="act_chatt(\'/listen all\');" title="'
+<tr><td><input style="vertical-align: bottom;" id="ra_listen_all" type="radio" name="listen" value="0" onclick="prefs_update();" title="'
 <?php echo $mlang_room['listall_desc'][$G_lang];?>
 '"><span id="list_all">
 <?php echo $mlang_room['tit_listall'][$G_lang];?>
 </span></td></tr>
-<tr><td><input style="vertical-align: bottom;" id="ra_listen_auth" type="radio" name="listen" value="1" onclick="act_chatt(\'/listen auth\');" title="'
+<tr><td><input style="vertical-align: bottom;" id="ra_listen_auth" type="radio" name="listen" value="1" onclick="prefs_update();" title="'
 <?php echo $mlang_room['listaut_desc'][$G_lang];?>
 '"><span id="list_auth">
 <?php echo $mlang_room['tit_listaut'][$G_lang];?>
 </span></td></tr>
-<tr><td><input style="vertical-align: bottom;" id="ra_listen_isol" type="radio" name="listen" value="2" onclick="act_chatt(\'/listen isolation\');" title="'
+<tr><td><input style="vertical-align: bottom;" id="ra_listen_isol" type="radio" name="listen" value="2" onclick="prefs_update();" title="'
 <?php echo $mlang_room['listisol_desc'][$G_lang];?>
 '"><span id="list_isol">
 <?php echo $mlang_room['tit_listisol'][$G_lang];?>
@@ -1236,7 +1236,7 @@ type="submit" class="button" onclick="this.form.elements['realsub'].value = 'chi
 
 
 </div>
-<div class="notify_clo"><input type="submit" class="input_sub" style="bottom: 4px;" onclick="$('preferences').style.visibility = 'hidden';" value="<?php echo $mlang_room['btn_prefs_close'][$G_lang]; ?>"/> <input type="submit" class="input_sub" style="bottom: 4px;" onclick="act_preferences_update();" value="<?php echo $mlang_room['btn_prefs_update'][$G_lang]; ?>"/></div>
+<div class="notify_clo"><input type="submit" class="input_sub" style="bottom: 4px;" onclick="$('preferences').style.visibility = 'hidden';" value="<?php echo $mlang_room['btn_prefs_close'][$G_lang]; ?>"/> <input type="submit" class="input_sub" style="bottom: 4px;" onclick="prefs_save();" value="<?php echo $mlang_room['btn_prefs_save'][$G_lang]; ?>"/></div>
 </div>
 </body>
 </html>
index 9db78fc..a079438 100644 (file)
@@ -184,7 +184,9 @@ function index_wr_main(&$room, $remote_addr_full, $get, $post, $cookie)
         else if ($argz[0] == 'whysupport') {
             echo show_notify(str_replace("\n", " ", $G_room_whysupport[$G_lang]), 0, $mlang_indwr['btn_close'][$G_lng], 400, 200);
         }
-        
+        else if ($argz[0] == 'prefs') {
+            fprintf(STDERR, "\n\n PREFS \n\n");
+        }
         else { 
             log_wr("Get User Error");
             echo "Get User Error:" + $argz[0];
index 476429a..8456ecf 100644 (file)
@@ -718,8 +718,11 @@ function prefs_assign(content)
 var prefs_list_idx  = new Array( 0x00, 0x01, 0x02 );
 var prefs_list_id   = new Array( "all", "auth", "isol" );
 
-function prefs_apply(prefs_new)
+function prefs_apply(prefs_new, is_update, is_volat)
 {
+    var i;
+    var relo = false;
+
     if (typeof(g_prefs) == 'undefined')
         return false;
 
@@ -728,27 +731,96 @@ function prefs_apply(prefs_new)
         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]) {
-                $('list_'+prefs_list_id[i]).style.color = 'red';
+                if (!is_volat)
+                    $('list_'+prefs_list_id[i]).style.color = 'red';
                 $('list_info').innerHTML = mlang_commons['tit_list'][i][g_lang];
             }
             else {
-                $('list_'+prefs_list_id[i]).style.color = 'black';
+                if (!is_volat)
+                    $('list_'+prefs_list_id[i]).style.color = 'black';
             }
         }
 
-        g_prefs.listen = prefs_new.listen;
         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)
+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);
+    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)