supp_comp partial support (db/prefs management, usage is missing)
[brisk.git] / web / prefs.js
diff --git a/web/prefs.js b/web/prefs.js
new file mode 100644 (file)
index 0000000..4fe20b8
--- /dev/null
@@ -0,0 +1,211 @@
+var l_list_all = 0x00;
+var l_list_auth = 0x01;
+var l_list_isol = 0x02;
+
+function client_prefs(old)
+{
+    if (old != null) {
+        this.listen    = old.listen;
+        this.supp_comp = old.supp_comp;
+    }
+}
+
+client_prefs.prototype = {
+    listen:    -1,
+    supp_comp: 'ff00ffff00'
+}
+
+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 || 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]) {
+                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;
+    }
+
+    // supporter component management
+    if (g_prefs.supp_comp != prefs_new.supp_comp || is_update) {
+        $('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++) {
+            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;
+    g_prefs.supp_comp = prefs_new.supp_comp;
+}
+
+function prefs_load(content, is_update, is_volat)
+{
+    var prefs_new;
+
+    // console.log('prefs_load('+content+')');
+
+    if ((prefs_new = prefs_assign(content)) == null)
+        return false;
+
+    return prefs_apply(prefs_new, is_update, is_volat);
+}
+
+function prefs_save()
+{
+    var ret;
+
+    if (typeof(g_prefs) == 'undefined')
+        return false;
+
+    ret = server_request('mesg', 'prefs','__POST__', 'prefs', JSON.stringify(g_prefs));
+
+    if (ret == 1)
+        $('preferences').style.visibility = 'hidden';
+}
+
+function prefs_update(field)
+{
+    var i;
+    var prefs_new;
+    var relo = false;
+
+    // console.log("prefs_update("+field+")");
+
+    if (typeof(g_prefs) == 'undefined')
+        return false;
+
+    prefs_new = new client_prefs(g_prefs);
+
+    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]));
+            if (prefs_new.listen != '')
+                break;
+        }
+    }
+    else if (field == 'supp') {
+        prefs_new.supp_comp = "" + dec2hex($('s_fg_r').value, 2) + dec2hex($('s_fg_g').value, 2) + dec2hex($('s_fg_b').value, 2) + dec2hex($('s_bg_r').value, 2) + dec2hex($('s_bg_g').value, 2) + dec2hex($('s_bg_b').value, 2);
+    }
+
+    /* from form to struct */
+    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);
+            }
+        }
+    }
+}