4 * Copyright (C) 2015 Matteo Nastasi
5 * mailto: nastasi@alternativeoutput.it
6 * matteo.nastasi@milug.org
7 * web: http://www.alternativeoutput.it
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABLILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details. You should have received a
18 * copy of the GNU General Public License along with this program; if
19 * not, write to the Free Software Foundation, Inc, 59 Temple Place -
20 * Suite 330, Boston, MA 02111-1307, USA.
24 var mlang_prefsn = { 'btn_close' : { 'it' : 'Chiudi.',
26 'tit_list' : { '0' : { 'it' : '',
28 '1' : { 'it' : '(solo aut.)',
29 'en' : '(only aut.)' },
30 '2' : { 'it' : '(isolam.to)',
31 'en' : '(isolation)' } }
34 var l_list_all = 0x00;
35 var l_list_auth = 0x01;
36 var l_list_isol = 0x02;
37 var l_prefs_list_idx = new Array( 0x00, 0x01, 0x02 );
38 var l_prefs_list_id = new Array( "all", "auth", "isol" );
39 var l_comps_name = new Array('s_fg_r', 's_fg_g', 's_fg_b', 's_bg_r', 's_bg_g', 's_bg_b');
41 /* FIXME: move to html page with dynamic valorization */
42 var is_supp_custom = true;
46 var fields = { listen: { type: 'radio', cb: Prefsn.listen_change_cb } };
49 type: 'fields', fields: { r: { type: 'value', cb: Prefsn.supp_change_cb },
50 g: { type: 'value', cb: Prefsn.supp_change_cb },
51 b: { type: 'value', cb: Prefsn.supp_change_cb }
55 type: 'fields', fields: { r: { type: 'value', cb: Prefsn.supp_change_cb },
56 g: { type: 'value', cb: Prefsn.supp_change_cb },
57 b: { type: 'value', cb: Prefsn.supp_change_cb }
62 this.fieldify = new Fieldify([obj], fields);
67 Prefsn.listen_change_cb = function(field)
73 console.log("listen_change_cb:" + field.value);
74 console.log("xx" + g_prefsn.data);
76 /* listen management */
77 if (g_prefsn.data == null || g_prefsn.data.listen != field.value) {
78 $('list_info').innerHTML = mlang_prefsn['tit_list'][field.value][g_lang];
79 console.log('update listen');
80 for (i = g_tables_auth_n ; i < g_tables_n ; i++) {
82 $('tr_noauth'+i).style.display = (field.value == l_list_isol ? 'none' : '');
85 $('td_noauth'+i).style.display = (field.value == l_list_isol ? 'none' : '');
87 if (field.value == l_list_isol) {
96 function obj_clone(obj) // begin = {} or [] is optional
100 if (arguments.length > 1)
101 begin = arguments[1];
108 if (ty == 'object') {
109 if (obj[i].constructor == Array) {
110 ret[i] = obj_clone(obj[i], []);
113 ret[i] = obj_clone(obj[i], {});
123 function obj_update(cur, delta)
128 if (ty == 'object') {
129 obj_update(cur[i], delta[i]);
138 Prefsn.supp_change_cb = function(field)
144 if (g_prefsn == null)
147 supp_new = Fieldify.item2tree([g_prefsn.obj], field);
149 console.log(g_prefsn.data.fg);
150 supp_cur['fg'] = obj_clone(g_prefsn.data.fg);
151 supp_cur['bg'] = obj_clone(g_prefsn.data.bg);
153 for (i in ['fg', 'bg']) {
154 if (! i in supp_new) {
157 obj_update(supp_cur[i], supp_new[i]);
160 var col, ct = 0, s = "";
161 for (col in [ 'fg', 'bg' ]) {
162 for (cmp in [ 'r', 'g', 'b' ]) {
163 var val_s = supp_cur[col][cmp];
164 if (parseInt(val_s) < 0 || parseInt(val_s) > 255 || isNaN(parseInt(val_s)))
167 s += dec2hex(parseInt(val_s), 2);
169 $('s_img').src = 'suprend.php?comp=' + s;
179 load: function(data) {
180 var in_data = JSON.parse(data);
181 this.fieldify.json2dom(in_data);
187 Fieldify.reset(this.obj);
191 this.fieldify.visible(true);
195 function prefsn_show(username)
197 var prefsn_in_in = server_request('index_wr.php', sess, 'mesg', 'chatt|/prefsn');
198 var prefsn_in = JSON.parse(prefsn_in_in);
201 if (prefsn_in.ret == 0) {
202 prefsn = prefsn_fld($('prefsn'));
203 prefsn.json2dom(prefsn_in);
204 prefsn.visible(true);
207 var noti = new notify(gst, prefsn_in.mesg, 0, mlang_prefsn['btn_close'][g_lang], 400, 150);
211 function prefsn_reset()
213 Fieldify.reset($('prefsn'));
222 function client_prefs(old)
225 this.listen = old.listen;
226 this.supp_comp = old.supp_comp;
230 client_prefs.prototype = {
232 supp_comp: 'ff00ffff00'
235 function prefs_assign(content)
240 s = "prefs_new = " + content;
246 function prefs_apply(prefs_new, is_update, is_volat)
251 if (typeof(g_prefs) == 'undefined')
253 /* listen management */
254 if (g_prefs.listen != prefs_new.listen || is_update) {
255 for (i = 0 ; i < l_prefs_list_idx.length ; i++) {
256 set_checked_value($('ra_listen_'+l_prefs_list_id[i]), prefs_new.listen);
257 if (prefs_new.listen == l_prefs_list_idx[i]) {
259 $('list_'+l_prefs_list_id[i]).style.color = 'red';
260 $('list_info').innerHTML = mlang_prefsn['tit_list'][i][g_lang];
264 $('list_'+l_prefs_list_id[i]).style.color = 'black';
271 // supporter component management
272 if (g_prefs.supp_comp != prefs_new.supp_comp || is_update) {
274 for (i = 0 ; i < 6 ; i++) {
275 $(l_comps_name[i]).value = parseInt(prefs_new.supp_comp.substr(i*2,2), 16);
277 $('s_img').src = 'suprend.php?comp='+prefs_new.supp_comp;
280 if (relo || !is_update) {
281 for (i = g_tables_auth_n ; i < g_tables_n ; i++) {
283 $('tr_noauth'+i).style.display = (prefs_new.listen == l_list_isol ? 'none' : '');
286 $('td_noauth'+i).style.display = (prefs_new.listen == l_list_isol ? 'none' : '');
288 if (prefs_new.listen == l_list_isol) {
296 // ricalculation of standup area
297 if (standup_data_old != null) {
298 standup_data = standup_data_old;
299 standup_data_old = null;
300 j_stand_cont(standup_data);
305 g_prefs.listen = prefs_new.listen;
306 g_prefs.supp_comp = prefs_new.supp_comp;
309 function prefs_load(content, is_update, is_volat)
313 // console.log('prefs_load('+content+')');
315 if ((prefs_new = prefs_assign(content)) == null)
318 return prefs_apply(prefs_new, is_update, is_volat);
321 function prefs_save()
325 if (typeof(g_prefs) == 'undefined')
328 ret = server_request('index_wr.php', sess, 'mesg', 'prefs|save','__POST__', 'prefs', JSON.stringify(g_prefs));
331 $('preferences').style.visibility = 'hidden';
338 function prefs_reset()
342 ret = server_request('index_wr.php', sess, 'mesg', 'prefs|reset');
345 function prefs_update(field)
350 // console.log("prefs_update("+field+")");
352 if (typeof(g_prefs) == 'undefined')
355 prefs_new = new client_prefs(g_prefs);
357 if (field == 'listen') {
358 /* listen management */
359 for (i = 0 ; i < l_prefs_list_idx.length ; i++) {
360 prefs_new.listen = get_checked_value($('ra_listen_'+l_prefs_list_id[i]));
361 if (prefs_new.listen != '')
365 else if (field == 'supp') {
366 for (i = 0 ; i < 6 ; i++) {
367 if (parseInt($(l_comps_name[i]).value) < 0 || parseInt($(l_comps_name[i]).value) > 255 ||
368 isNaN(parseInt($(l_comps_name[i]).value))) {
374 prefs_new.supp_comp = "";
375 for (i = 0 ; i < 6 ; i++) {
376 prefs_new.supp_comp += dec2hex(parseInt($(l_comps_name[i]).value), 2);
380 // console.log("prefs_update:: i break "+i+" ["+prefs_new.supp_comp+"]");
382 for (i = 0 ; i < 6 ; i++) {
383 $(l_comps_name[i]).value = parseInt(prefs_new.supp_comp.substr(i*2, 2), 16);
387 /* from form to struct */
388 prefs_apply(prefs_new, true, true);
391 function list_set(what, is_update, info)
395 var old_st = readCookie("CO_list");
397 if (what == 'auth') {
398 $('list_auth').style.color = 'red';
399 $('list_isol').style.color = 'black';
400 $('list_all').style.color = 'black';
401 if (old_st == 'isolation')
403 g_listen = l_list_auth;
405 else if (what == 'isolation') {
406 $('list_auth').style.color = 'black';
407 $('list_isol').style.color = 'red';
408 $('list_all').style.color = 'black';
409 if (old_st != 'isolation')
411 g_listen = l_list_isol;
414 $('list_auth').style.color = 'black';
415 $('list_isol').style.color = 'black';
416 $('list_all').style.color = 'red';
417 if (old_st == 'isolation')
419 g_listen = l_list_all;
422 set_checked_value($('ra_listen_auth'), what);
423 set_checked_value($('ra_listen_isol'), what);
424 set_checked_value($('ra_listen_all'), what);
426 $('list_info').innerHTML = info;
428 createCookie("CO_list", what, 24*365, cookiepath);
432 if (relo || !is_update) {
433 for (i = g_tables_auth_n ; i < g_tables_n ; i++) {
436 $('tr_noauth'+i).style.display = (what == 'isolation' ? 'none' : '');
439 $('td_noauth'+i).style.display = (what == 'isolation' ? 'none' : '');
441 if (what == 'isolation') {
449 // ricalculation of standup area
450 if (standup_data_old != null) {
451 standup_data = standup_data_old;
452 standup_data_old = null;
453 j_stand_cont(standup_data);