supp_comp partial support (db/prefs management, usage is missing)
[brisk.git] / web / prefs.js
1 var l_list_all = 0x00;
2 var l_list_auth = 0x01;
3 var l_list_isol = 0x02;
4
5 function client_prefs(old)
6 {
7     if (old != null) {
8         this.listen    = old.listen;
9         this.supp_comp = old.supp_comp;
10     }
11 }
12
13 client_prefs.prototype = {
14     listen:    -1,
15     supp_comp: 'ff00ffff00'
16 }
17
18 function prefs_assign(content)
19 {
20     var prefs_new;
21     var s;
22
23     s = "prefs_new = " + content;
24     eval(s);
25
26     return (prefs_new);
27 }
28
29 var prefs_list_idx  = new Array( 0x00, 0x01, 0x02 );
30 var prefs_list_id   = new Array( "all", "auth", "isol" );
31
32 function prefs_apply(prefs_new, is_update, is_volat)
33 {
34     var i;
35     var relo = false;
36
37     if (typeof(g_prefs) == 'undefined')
38         return false;
39     /* listen management */
40     if (g_prefs.listen != prefs_new.listen || is_update) {
41         for (i = 0 ; i < prefs_list_idx.length ; i++) {
42             set_checked_value($('ra_listen_'+prefs_list_id[i]), prefs_new.listen);
43             if (prefs_new.listen == prefs_list_idx[i]) {
44                 if (!is_volat)
45                     $('list_'+prefs_list_id[i]).style.color = 'red';
46                 $('list_info').innerHTML = mlang_commons['tit_list'][i][g_lang];
47             }
48             else {
49                 if (!is_volat)
50                     $('list_'+prefs_list_id[i]).style.color = 'black';
51             }
52         }
53
54         relo = true;
55     }
56
57     // supporter component management
58     if (g_prefs.supp_comp != prefs_new.supp_comp || is_update) {
59         $('s_img').src = 'suprend.php?comp='+prefs_new.supp_comp;
60     }
61
62     if (relo || !is_update) {
63         for (i = g_tables_auth_n ; i < g_tables_n ; i++) {
64             if (i % 4 == 0) {
65                 $('tr_noauth'+i).style.display = (prefs_new.listen == l_list_isol ? 'none' : '');
66             }
67
68             $('td_noauth'+i).style.display = (prefs_new.listen == l_list_isol ? 'none' : '');
69         }
70         if (prefs_new.listen == l_list_isol) {
71             tra.hide_noauth();
72         }
73         else {
74             tra.show_noauth();
75         }
76
77         if (false) {
78             // ricalculation of standup area
79             if (standup_data_old != null) {
80                 standup_data = standup_data_old;
81                 standup_data_old = null;
82                 j_stand_cont(standup_data);
83             }
84         }
85     }
86
87     g_prefs.listen    = prefs_new.listen;
88     g_prefs.supp_comp = prefs_new.supp_comp;
89 }
90
91 function prefs_load(content, is_update, is_volat)
92 {
93     var prefs_new;
94
95     // console.log('prefs_load('+content+')');
96
97     if ((prefs_new = prefs_assign(content)) == null)
98         return false;
99
100     return prefs_apply(prefs_new, is_update, is_volat);
101 }
102
103 function prefs_save()
104 {
105     var ret;
106
107     if (typeof(g_prefs) == 'undefined')
108         return false;
109
110     ret = server_request('mesg', 'prefs','__POST__', 'prefs', JSON.stringify(g_prefs));
111
112     if (ret == 1)
113         $('preferences').style.visibility = 'hidden';
114 }
115
116 function prefs_update(field)
117 {
118     var i;
119     var prefs_new;
120     var relo = false;
121
122     // console.log("prefs_update("+field+")");
123
124     if (typeof(g_prefs) == 'undefined')
125         return false;
126
127     prefs_new = new client_prefs(g_prefs);
128
129     if (field == 'listen') {
130         /* listen management */
131         for (i = 0 ; i < prefs_list_idx.length ; i++) {
132             prefs_new.listen = get_checked_value($('ra_listen_'+prefs_list_id[i]));
133             if (prefs_new.listen != '')
134                 break;
135         }
136     }
137     else if (field == 'supp') {
138         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);
139     }
140
141     /* from form to struct */
142     prefs_apply(prefs_new, true, true);
143 }
144
145 function list_set(what, is_update, info)
146 {
147     var i;
148     var relo = false;
149     var old_st = readCookie("CO_list");
150     
151     if (what == 'auth') {
152         $('list_auth').style.color = 'red';
153         $('list_isol').style.color = 'black';
154         $('list_all').style.color = 'black';
155         if (old_st == 'isolation')
156             relo = true;
157         g_listen = l_list_auth;
158     }
159     else if (what == 'isolation') {
160         $('list_auth').style.color = 'black';
161         $('list_isol').style.color = 'red';
162         $('list_all').style.color = 'black';
163         if (old_st != 'isolation')
164             relo = true;
165         g_listen = l_list_isol;
166     }
167     else {
168         $('list_auth').style.color = 'black';
169         $('list_isol').style.color = 'black';
170         $('list_all').style.color = 'red';
171         if (old_st == 'isolation')
172             relo = true;
173         g_listen = l_list_all;
174     }
175
176     set_checked_value($('ra_listen_auth'), what);
177     set_checked_value($('ra_listen_isol'), what);
178     set_checked_value($('ra_listen_all'),  what);
179
180     $('list_info').innerHTML = info;
181     if (is_update) {
182         createCookie("CO_list", what, 24*365, cookiepath);
183     }
184
185
186     if (relo || !is_update) {
187         for (i = g_tables_auth_n ; i < g_tables_n ; i++) {
188             
189             if (i % 4 == 0) {
190                 $('tr_noauth'+i).style.display = (what == 'isolation' ? 'none' : '');
191             }
192             
193             $('td_noauth'+i).style.display = (what == 'isolation' ? 'none' : '');
194         }
195         if (what == 'isolation') {
196             tra.hide_noauth();
197         }
198         else {
199             tra.show_noauth();
200         }
201             
202         if (false) {
203             // ricalculation of standup area
204             if (standup_data_old != null) {
205                 standup_data = standup_data_old;
206                 standup_data_old = null;
207                 j_stand_cont(standup_data);
208             }
209         }
210     }
211 }