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_prefsf = { '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 mlang_prefsn = { 'btn_close' : { 'it' : 'Chiudi.',
36 'tit_list' : { '0' : { 'it' : '',
38 '1' : { 'it' : '(solo aut.)',
39 'en' : '(only aut.)' },
40 '2' : { 'it' : '(isolam.to)',
41 'en' : '(isolation)' } }
44 var l_list_all = 0x00;
45 var l_list_auth = 0x01;
46 var l_list_isol = 0x02;
47 var l_prefs_list_idx = new Array( 0x00, 0x01, 0x02 );
48 var l_prefs_list_id = new Array( "all", "auth", "isol" );
49 var l_comps_name = new Array('s_fg_r', 's_fg_g', 's_fg_b', 's_bg_r', 's_bg_g', 's_bg_b');
51 /* FIXME: move to html page with dynamic valorization */
52 var is_supp_custom = true;
56 var fields = { listen: { type: 'radio', cb: Prefsn.listen_change_cb } };
59 type: 'fields', fields: { r: { type: 'value', cb: Prefsn.supp_change_cb },
60 g: { type: 'value', cb: Prefsn.supp_change_cb },
61 b: { type: 'value', cb: Prefsn.supp_change_cb }
65 type: 'fields', fields: { r: { type: 'value', cb: Prefsn.supp_change_cb },
66 g: { type: 'value', cb: Prefsn.supp_change_cb },
67 b: { type: 'value', cb: Prefsn.supp_change_cb }
72 this.fieldify = new Fieldify([obj], fields);
77 Prefsn.listen_change_cb = function(field)
83 console.log("listen_change_cb:" + field.value);
84 console.log("xx" + g_prefsn.data);
86 /* listen management */
87 if (g_prefsn.data == null || g_prefsn.data.listen != field.value) {
88 $('list_info').innerHTML = mlang_prefsn['tit_list'][field.value][g_lang];
89 console.log('update listen');
90 for (i = g_tables_cert_n + g_tables_auth_n ; i < g_tables_n ; i++) {
92 $('tr_noauth'+i).style.display = (field.value == l_list_isol ? 'none' : '');
95 $('td_noauth'+i).style.display = (field.value == l_list_isol ? 'none' : '');
97 if (field.value == l_list_isol) {
106 function obj_clone(obj) // begin = {} or [] is optional
110 if (arguments.length > 1)
111 begin = arguments[1];
118 if (ty == 'object') {
119 if (obj[i].constructor == Array) {
120 ret[i] = obj_clone(obj[i], []);
123 ret[i] = obj_clone(obj[i], {});
133 function obj_update(cur, delta)
138 if (ty == 'object') {
139 obj_update(cur[i], delta[i]);
148 Prefsn.supp_change_cb = function(field)
154 if (g_prefsn == null)
157 supp_new = Fieldify.item2tree([g_prefsn.obj], field);
159 console.log(g_prefsn.data.fg);
160 supp_cur['fg'] = obj_clone(g_prefsn.data.fg);
161 supp_cur['bg'] = obj_clone(g_prefsn.data.bg);
163 for (i in ['fg', 'bg']) {
164 if (! i in supp_new) {
167 obj_update(supp_cur[i], supp_new[i]);
170 var col, ct = 0, s = "";
171 for (col in [ 'fg', 'bg' ]) {
172 for (cmp in [ 'r', 'g', 'b' ]) {
173 var val_s = supp_cur[col][cmp];
174 if (parseInt(val_s) < 0 || parseInt(val_s) > 255 || isNaN(parseInt(val_s)))
177 s += dec2hex(parseInt(val_s), 2);
179 $('s_img').src = 'suprend.php?comp=' + s;
189 load: function(data) {
190 var in_data = JSON.parse(data);
191 this.fieldify.json2dom(in_data);
197 Fieldify.reset(this.obj);
201 this.fieldify.visible(true);
205 function prefsn_show(username)
207 var prefsn_in_in = server_request('index_wr.php', sess, 'mesg', 'chatt|/prefsn');
208 var prefsn_in = JSON.parse(prefsn_in_in);
211 if (prefsn_in.ret == 0) {
212 prefsn = prefsn_fld($('prefsn'));
213 prefsn.json2dom(prefsn_in);
214 prefsn.visible(true);
217 var noti = new notify(gst, prefsn_in.mesg, 0, mlang_prefsn['btn_close'][g_lang], 400, 150);
221 function prefsn_reset()
223 Fieldify.reset($('prefsn'));
232 function client_prefs(old)
235 this.listen = old.listen;
236 this.supp_comp = old.supp_comp;
240 client_prefs.prototype = {
242 supp_comp: 'ff00ffff00'
245 function prefs_assign(content)
250 s = "prefs_new = " + content;
256 function prefs_apply(prefs_new, is_update, is_volat)
261 if (typeof(g_prefs) == 'undefined')
263 /* listen management */
264 if (g_prefs.listen != prefs_new.listen || is_update) {
265 for (i = 0 ; i < l_prefs_list_idx.length ; i++) {
266 set_checked_value($('ra_listen_'+l_prefs_list_id[i]), prefs_new.listen);
267 if (prefs_new.listen == l_prefs_list_idx[i]) {
269 $('list_'+l_prefs_list_id[i]).style.color = 'red';
270 $('list_info').innerHTML = mlang_prefsn['tit_list'][i][g_lang];
274 $('list_'+l_prefs_list_id[i]).style.color = 'black';
281 // supporter component management
282 if (g_prefs.supp_comp != prefs_new.supp_comp || is_update) {
284 for (i = 0 ; i < 6 ; i++) {
285 $(l_comps_name[i]).value = parseInt(prefs_new.supp_comp.substr(i*2,2), 16);
287 $('s_img').src = 'suprend.php?comp='+prefs_new.supp_comp;
290 if (relo || !is_update) {
291 for (i = g_tables_auth_n ; i < g_tables_n ; i++) {
293 $('tr_noauth'+i).style.display = (prefs_new.listen == l_list_isol ? 'none' : '');
296 $('td_noauth'+i).style.display = (prefs_new.listen == l_list_isol ? 'none' : '');
298 if (prefs_new.listen == l_list_isol) {
306 // ricalculation of standup area
307 if (standup_data_old != null) {
308 standup_data = standup_data_old;
309 standup_data_old = null;
310 j_stand_cont(standup_data);
315 g_prefs.listen = prefs_new.listen;
316 g_prefs.supp_comp = prefs_new.supp_comp;
319 function prefs_load(content, is_update, is_volat)
323 // console.log('prefs_load('+content+')');
325 if ((prefs_new = prefs_assign(content)) == null)
328 return prefs_apply(prefs_new, is_update, is_volat);
331 function prefs_save()
335 if (typeof(g_prefs) == 'undefined')
338 ret = server_request('index_wr.php', sess, 'mesg', 'prefs|save','__POST__', 'prefs', JSON.stringify(g_prefs));
341 $('preferences').style.visibility = 'hidden';
348 function prefs_reset()
352 ret = server_request('index_wr.php', sess, 'mesg', 'prefs|reset');
355 function prefs_update(field)
360 // console.log("prefs_update("+field+")");
362 if (typeof(g_prefs) == 'undefined')
365 prefs_new = new client_prefs(g_prefs);
367 if (field == 'listen') {
368 /* listen management */
369 for (i = 0 ; i < l_prefs_list_idx.length ; i++) {
370 prefs_new.listen = get_checked_value($('ra_listen_'+l_prefs_list_id[i]));
371 if (prefs_new.listen != '')
375 else if (field == 'supp') {
376 for (i = 0 ; i < 6 ; i++) {
377 if (parseInt($(l_comps_name[i]).value) < 0 || parseInt($(l_comps_name[i]).value) > 255 ||
378 isNaN(parseInt($(l_comps_name[i]).value))) {
384 prefs_new.supp_comp = "";
385 for (i = 0 ; i < 6 ; i++) {
386 prefs_new.supp_comp += dec2hex(parseInt($(l_comps_name[i]).value), 2);
390 // console.log("prefs_update:: i break "+i+" ["+prefs_new.supp_comp+"]");
392 for (i = 0 ; i < 6 ; i++) {
393 $(l_comps_name[i]).value = parseInt(prefs_new.supp_comp.substr(i*2, 2), 16);
397 /* from form to struct */
398 prefs_apply(prefs_new, true, true);
401 function list_set(what, is_update, info)
405 var old_st = readCookie("CO_list");
407 if (what == 'auth') {
408 $('list_auth').style.color = 'red';
409 $('list_isol').style.color = 'black';
410 $('list_all').style.color = 'black';
411 if (old_st == 'isolation')
413 g_listen = l_list_auth;
415 else if (what == 'isolation') {
416 $('list_auth').style.color = 'black';
417 $('list_isol').style.color = 'red';
418 $('list_all').style.color = 'black';
419 if (old_st != 'isolation')
421 g_listen = l_list_isol;
424 $('list_auth').style.color = 'black';
425 $('list_isol').style.color = 'black';
426 $('list_all').style.color = 'red';
427 if (old_st == 'isolation')
429 g_listen = l_list_all;
432 set_checked_value($('ra_listen_auth'), what);
433 set_checked_value($('ra_listen_isol'), what);
434 set_checked_value($('ra_listen_all'), what);
436 $('list_info').innerHTML = info;
438 createCookie("CO_list", what, 24*365, cookiepath);
442 if (relo || !is_update) {
443 for (i = g_tables_auth_n ; i < g_tables_n ; i++) {
446 $('tr_noauth'+i).style.display = (what == 'isolation' ? 'none' : '');
449 $('td_noauth'+i).style.display = (what == 'isolation' ? 'none' : '');
451 if (what == 'isolation') {
459 // ricalculation of standup area
460 if (standup_data_old != null) {
461 standup_data = standup_data_old;
462 standup_data_old = null;
463 j_stand_cont(standup_data);
470 function g_prefsf_listen_cb(item)
472 var whats = [ 'all', 'auth', 'isolation' ];
473 var what = whats[item.value];
475 console.log("change listen", item.value);
477 $('list_info').innerHTML = mlang_prefsf.tit_list[item.value][g_lang];
479 for (i = g_tables_cert_n + g_tables_auth_n ; i < g_tables_n ; i++) {
481 $('tr_noauth'+i).style.display = (what == 'isolation' ? 'none' : '');
483 $('td_noauth'+i).style.display = (what == 'isolation' ? 'none' : '');
485 if (what == 'isolation') {
493 function g_prefsf_comps_cb(item)
496 console.log(g_prefsf);
498 var col, ct = 0, s = "";
499 var col_arr = [ 'fg', 'bg' ];
500 var cmp_arr = [ 'r', 'g', 'b' ];
501 for (col in col_arr) {
502 for (cmp in cmp_arr) {
503 console.log(g_prefsf.bsk_comps[col_arr[col]][cmp_arr[cmp]].value);
504 var val_s = g_prefsf.bsk_comps[col_arr[col]][cmp_arr[cmp]].value;
505 if (parseInt(val_s) < 0 || parseInt(val_s) > 255 || isNaN(parseInt(val_s)))
507 s += dec2hex(parseInt(val_s), 2);
509 console.log("sub: [" + s + "]");
511 $('s_img').src = 'suprend.php?comp=' + s;
514 function prefsf_status_cb(st)
516 // console.log('status_show HERE ' + st);
518 case Fieldify.STATUS_OK:
519 $('prefsf-status-flag').src = 'img/light-green.png';
521 case Fieldify.STATUS_PROC:
522 $('prefsf-status-flag').src = 'img/light-orange.png';
524 default: // Fieldify.STATUS_ERR
525 $('prefsf-status-flag').src = 'img/light-red.png';
530 function prefsf_initialize()
532 clie_cb = { 'listen': { cb: g_prefsf_listen_cb, type: "fast" },
533 'fg': { 'r': { cb: g_prefsf_comps_cb, type: "fast"},
534 'g': { cb: g_prefsf_comps_cb, type: "fast"},
535 'b': { cb: g_prefsf_comps_cb, type: "fast"}},
536 'bg': { 'r': { cb: g_prefsf_comps_cb, type: "fast"},
537 'g': { cb: g_prefsf_comps_cb, type: "fast"},
538 'b': { cb: g_prefsf_comps_cb, type: "fast"}}};
539 g_prefsf = new Fieldify(null, null, null, clie_cb, "prefsf", [$("prefsf")], prefsf_status_cb);
540 g_prefsf.bsk_comps = { 'bg': { 'r': $C('bg_r') != undefined ? $C('bg_r')[0] : null,
541 'g': $C('bg_g') != undefined ? $C('bg_g')[0] : null,
542 'b': $C('bg_b') != undefined ? $C('bg_b')[0] : null },
543 'fg': { 'r': $C('fg_r') != undefined ? $C('fg_r')[0] : null,
544 'g': $C('fg_g') != undefined ? $C('fg_g')[0] : null,
545 'b': $C('fg_b') != undefined ? $C('fg_b')[0] : null} };