new listen preferences reload and init managed
authorMatteo Nastasi (mop) <nastasi@alternativeoutput.it>
Sun, 3 Feb 2013 08:59:09 +0000 (09:59 +0100)
committerMatteo Nastasi (mop) <nastasi@alternativeoutput.it>
Sun, 3 Feb 2013 08:59:09 +0000 (09:59 +0100)
TODO.txt
web/Obj/brisk.phh
web/commons.js
web/index.php
web/room.js

index ef083d3..189bcb3 100644 (file)
--- a/TODO.txt
+++ b/TODO.txt
@@ -4,9 +4,11 @@
   FEATURES |
  ----------+
    - prefs API:
+     . prefs_assign(content): assign json content as output var
+     . prefs_apply(prefs_new): apply new content to g_prefs and system
+     . prefs_load(content): load json content and apply to g_prefs and system
+
      . prefs_save (save to the server the new prefs)
-     . prefs_load (load prefs structure with a json)
-     . prefs_apply (from server, and after prefs_save if success)
 
    - preferences (listen into preferences)
      . update values
index db99007..09ea77f 100644 (file)
@@ -926,17 +926,20 @@ class Room
     
     $ret = sprintf('gst.st = %d; ',  $user_step);
 
+    // for test: $prefs = new Client_prefs(USER_FLAG_LISTAUTH >> 2);
     $prefs = new Client_prefs(($user->flags & USER_FLAG_MAP_AUTH) >> 2);
-    $ret .= sprintf('var prefs_new = prefs_load(\'%s\'); console.log(prefs_new);', json_encode($prefs));
+    $ret .= sprintf('prefs_load(\'%s\');', json_encode($prefs));
 
-    if ($user->flags & USER_FLAG_ISOLAUTH) {
-      $ret .= 'list_set(\'isolation\', false, \''.$mlang_brisk['tit_onisol'][$G_lang].'\' ); ';
-    }
-    else if ($user->flags & USER_FLAG_LISTAUTH) {
-      $ret .= 'list_set(\'auth\', false, \''.$mlang_brisk['tit_onauth'][$G_lang].'\' ); ';
-    }
-    else {
-      $ret .= 'list_set(\'all\', false, \'\' ); ';
+    if(false) {
+        if ($user->flags & USER_FLAG_ISOLAUTH) {
+            $ret .= 'list_set(\'isolation\', false, \''.$mlang_brisk['tit_onisol'][$G_lang].'\' ); ';
+        }
+        else if ($user->flags & USER_FLAG_LISTAUTH) {
+            $ret .= 'list_set(\'auth\', false, \''.$mlang_brisk['tit_onauth'][$G_lang].'\' ); ';
+        }
+        else {
+            $ret .= 'list_set(\'all\', false, \'\' ); ';
+        }
     }
 
     if ($user->subst == 'standup')
index 75cabf4..158dc54 100644 (file)
@@ -38,9 +38,14 @@ var mlang_commons = { 'imgload_a' : { 'it' : 'Immagine caricate ',
                       'btn_sit'   : { 'it' : 'Mi siedo.',
                                       'en' : 'Sit down.' },
                       'btn_exit'  : { 'it' : 'Esco.',
-                                      'en' : 'Exit.' }
-                      
-                      };
+                                      'en' : 'Exit.' },
+                      'tit_list'  : { '0'  : { 'it' : '',
+                                               'en' : '' },
+                                      '1'  : { 'it' : '(solo aut.)',
+                                               'en' : '(only aut.)' },
+                                      '2'  : { 'it' : '(isolam.to)',
+                                               'en' : '(isolation)' } }
+                    };
 
 function $(id) { return document.getElementById(id); }
 
index da98a0a..92670c9 100644 (file)
@@ -866,6 +866,7 @@ supported by:<br>
    var g_lng = "<? echo $G_lng; ?>";
    var g_tables_n = <? echo TABLES_N; ?>;
    var g_tables_auth_n = <? echo TABLES_AUTH_N; ?>;
+   var g_prefs, g_prefs_new = null;
    var g_listen;
    var g_withflash = false;
    var g_is_spawn = 0;
@@ -879,6 +880,9 @@ supported by:<br>
    window.onload = function() {
      // alert(window.onbeforeunload);
      g_brow = get_browser_agent();
+
+     g_prefs = new client_prefs();
+
      spo_slide  = new sideslide($('spon_caro'), 80, 20);
      sup_slide  = new sideslide($('supp_caro'), 80, 20);
 
@@ -1001,6 +1005,7 @@ echo "$body"; ?>
    var g_lng = "<? echo $G_lng; ?>";
    var g_tables_n = <? echo TABLES_N; ?>;
    var g_tables_auth_n = <? echo TABLES_AUTH_N; ?>;
+   var g_prefs, g_prefs_new = null;
    var g_listen;
    var tra = null;
    var stat = "";
@@ -1010,13 +1015,16 @@ echo "$body"; ?>
    var topbanner_sfx, topbanner_dx;
    // var nonunload = false;
    var g_withflash = false;
-   var g_imgct= 0;
+   var g_imgct = 0;
    var g_imgtot = g_preload_img_arr.length;
    var g_brow = null;
    var spo_slide, sup_slide;
 
    window.onload = function() {
      g_brow = get_browser_agent();
+
+     g_prefs = new client_prefs();
+
      spo_slide  = new sideslide($('spon_caro'), 80, 20);
      sup_slide  = new sideslide($('supp_caro'), 80, 20);
 
@@ -1197,17 +1205,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="all" onclick="act_chatt(\'/listen all\');" title="'
+<tr><td><input style="vertical-align: bottom;" id="ra_listen_all" type="radio" name="listen" value="0" onclick="act_chatt(\'/listen all\');" 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="auth" onclick="act_chatt(\'/listen auth\');" title="'
+<tr><td><input style="vertical-align: bottom;" id="ra_listen_auth" type="radio" name="listen" value="1" onclick="act_chatt(\'/listen auth\');" 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="isolation" onclick="act_chatt(\'/listen isolation\');" title="'
+<tr><td><input style="vertical-align: bottom;" id="ra_listen_isol" type="radio" name="listen" value="2" onclick="act_chatt(\'/listen isolation\');" title="'
 <?php echo $mlang_room['listisol_desc'][$G_lang];?>
 '"><span id="list_isol">
 <?php echo $mlang_room['tit_listisol'][$G_lang];?>
index 31e97b8..476429a 100644 (file)
 
 
 /* 
+
    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)
 {
     var content = "", supercont = "";
@@ -694,7 +704,7 @@ function j_pollbox(form)
     return (false);
 }
 
-function prefs_load(content)
+function prefs_assign(content)
 {
     var prefs_new;
     var s;
@@ -705,10 +715,44 @@ function prefs_load(content)
     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)
+{
+    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]) {
+                $('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';
+            }
+        }
+
+        g_prefs.listen = prefs_new.listen;
+        relo = true;
+    }
+}
+
+function prefs_load(content)
+{
+    var prefs_new;
+
+    if ((prefs_new = prefs_assign(content)) == null)
+        return false;
+
+    return prefs_apply(prefs_new);
+}
 
 function list_set(what, is_update, info)
 {
-    // console.log(what);
     var i;
     var relo = false;
     var old_st = readCookie("CO_list");