dev commit
[brisk.git] / web / prefs.js
index 5e658b4..314c90e 100644 (file)
@@ -1,10 +1,11 @@
 var l_list_all  = 0x00;
 var l_list_auth = 0x01;
 var l_list_isol = 0x02;
-var prefs_list_idx  = new Array( 0x00, 0x01, 0x02 );
-var prefs_list_id   = new Array( "all", "auth", "isol" );
-var comps_name = new Array('s_fg_r', 's_fg_g', 's_fg_b', 's_bg_r',  's_bg_g',  's_bg_b');
+var l_prefs_list_idx = new Array( 0x00, 0x01, 0x02 );
+var l_prefs_list_id  = new Array( "all", "auth", "isol" );
+var l_comps_name     = new Array('s_fg_r', 's_fg_g', 's_fg_b', 's_bg_r',  's_bg_g',  's_bg_b');
 
+var standup_data_notisol = null;
 
 function client_prefs(old)
 {
@@ -35,20 +36,22 @@ function prefs_apply(prefs_new, is_update, is_volat)
     var i;
     var relo = false;
 
+    console.log('prefs_apply: begin');
+
     if (typeof(g_prefs) == 'undefined')
         return false;
     /* listen management */
     if (g_prefs.listen != prefs_new.listen || is_update) {
-        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]) {
+        for (i = 0 ; i < l_prefs_list_idx.length ; i++) {
+            set_checked_value($('ra_listen_'+l_prefs_list_id[i]), prefs_new.listen);
+            if (prefs_new.listen == l_prefs_list_idx[i]) {
                 if (!is_volat)
-                    $('list_'+prefs_list_id[i]).style.color = 'red';
+                    $('list_'+l_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';
+                    $('list_'+l_prefs_list_id[i]).style.color = 'black';
             }
         }
 
@@ -59,13 +62,13 @@ function prefs_apply(prefs_new, is_update, is_volat)
     if (g_prefs.supp_comp != prefs_new.supp_comp || is_update) {
 
         for (i = 0 ; i < 6 ; i++) {
-            $(comps_name[i]).value = parseInt(prefs_new.supp_comp.substr(i*2,2), 16);
+            $(l_comps_name[i]).value = parseInt(prefs_new.supp_comp.substr(i*2,2), 16);
         }
         $('s_img').src = 'suprend.php?comp='+prefs_new.supp_comp;
     }
 
     if (relo || !is_update) {
-        for (i = g_tables_auth_n ; i < g_tables_n ; i++) {
+        for (i = g_tables_appr_n ; i < g_tables_n ; i++) {
             if (i % 4 == 0) {
                 $('tr_noauth'+i).style.display = (prefs_new.listen == l_list_isol ? 'none' : '');
             }
@@ -79,9 +82,27 @@ function prefs_apply(prefs_new, is_update, is_volat)
             tra.show_noauth();
         }
 
-        if (false) {
+        if (typeof(prefs) != "undefined") {
+            if (prefs.listen != l_list_isol && prefs_new.listen == l_list_isol) {
+                if (standup_data_old != null) {
+                    standup_data_notisol = standup_data_old.slice();
+                }
+            }
+            else if (prefs.listen == l_list_isol && prefs_new.listen != l_list_isol) {
+                if (standup_data_notisol != null) {
+                    standup_data_old = standup_data_notisol;
+                    standup_data_notisol = null;
+                }
+            }
+        }
+        
+        if (g_prefs.listen != prefs_new.listen) {
             // ricalculation of standup area
+            g_prefs.listen = prefs_new.listen;
+
+            console.log('here we are');
             if (standup_data_old != null) {
+                console.log('here we are2');
                 standup_data = standup_data_old;
                 standup_data_old = null;
                 j_stand_cont(standup_data);
@@ -112,10 +133,21 @@ function prefs_save()
     if (typeof(g_prefs) == 'undefined')
         return false;
 
-    ret = server_request('mesg', 'prefs','__POST__', 'prefs', JSON.stringify(g_prefs));
+    ret = server_request('mesg', 'prefs|save','__POST__', 'prefs', JSON.stringify(g_prefs));
 
-    if (ret == 1)
+    if (ret == 1) {
         $('preferences').style.visibility = 'hidden';
+    }
+    else {
+        alert(ret);
+    }
+}
+
+function prefs_reset()
+{
+    var ret;
+
+    ret = server_request('mesg', 'prefs|reset');
 }
 
 function prefs_update(field)
@@ -132,16 +164,16 @@ function prefs_update(field)
 
     if (field == 'listen') {
         /* listen management */
-        for (i = 0 ; i < prefs_list_idx.length ; i++) {
-            prefs_new.listen = get_checked_value($('ra_listen_'+prefs_list_id[i]));
+        for (i = 0 ; i < l_prefs_list_idx.length ; i++) {
+            prefs_new.listen = get_checked_value($('ra_listen_'+l_prefs_list_id[i]));
             if (prefs_new.listen != '')
                 break;
         }
     }
     else if (field == 'supp') {
         for (i = 0 ; i < 6 ; i++) {
-            if (parseInt($(comps_name[i]).value) < 0 || parseInt($(comps_name[i]).value) > 255 ||
-                isNaN(parseInt($(comps_name[i]).value))) {
+            if (parseInt($(l_comps_name[i]).value) < 0 || parseInt($(l_comps_name[i]).value) > 255 ||
+                isNaN(parseInt($(l_comps_name[i]).value))) {
                 break;
             }
         }
@@ -149,14 +181,14 @@ function prefs_update(field)
         if (i == 6) {
             prefs_new.supp_comp = "";
             for (i = 0 ; i < 6 ; i++) {
-                prefs_new.supp_comp += dec2hex(parseInt($(comps_name[i]).value), 2);
+                prefs_new.supp_comp += dec2hex(parseInt($(l_comps_name[i]).value), 2);
             }
         }
 
         // console.log("prefs_update:: i break "+i+" ["+prefs_new.supp_comp+"]");
 
         for (i = 0 ; i < 6 ; i++) {
-            $(comps_name[i]).value = parseInt(prefs_new.supp_comp.substr(i*2, 2), 16);
+            $(l_comps_name[i]).value = parseInt(prefs_new.supp_comp.substr(i*2, 2), 16);
         }
     }
 
@@ -206,7 +238,7 @@ function list_set(what, is_update, info)
 
 
     if (relo || !is_update) {
-        for (i = g_tables_auth_n ; i < g_tables_n ; i++) {
+        for (i = g_tables_appr_n ; i < g_tables_n ; i++) {
             
             if (i % 4 == 0) {
                 $('tr_noauth'+i).style.display = (what == 'isolation' ? 'none' : '');