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 Prefsn.supp_change_cb = function(field)
101 console.log("prefs_update("+field+")");
103 if (typeof(g_prefsn) == 'undefined')
106 for (i = 0 ; i < 6 ; i++) {
107 if (parseInt($(l_comps_name[i]).value) < 0 || parseInt($(l_comps_name[i]).value) > 255 ||
108 isNaN(parseInt($(l_comps_name[i]).value))) {
114 prefs_new.supp_comp = "";
115 for (i = 0 ; i < 6 ; i++) {
116 prefs_new.supp_comp += dec2hex(parseInt($(l_comps_name[i]).value), 2);
120 // console.log("prefs_update:: i break "+i+" ["+prefs_new.supp_comp+"]");
122 for (i = 0 ; i < 6 ; i++) {
123 $(l_comps_name[i]).value = parseInt(prefs_new.supp_comp.substr(i*2, 2), 16);
126 /* from form to struct */
127 // prefs_apply(prefs_new, true, true);
137 load: function(data) {
138 var in_data = JSON.parse(data);
139 this.fieldify.json2dom(in_data);
145 Fieldify.reset(this.obj);
149 this.fieldify.visible(true);
153 function prefsn_show(username)
155 var prefsn_in_in = server_request('index_wr.php', sess, 'mesg', 'chatt|/prefsn');
156 var prefsn_in = JSON.parse(prefsn_in_in);
159 if (prefsn_in.ret == 0) {
160 prefsn = prefsn_fld($('prefsn'));
161 prefsn.json2dom(prefsn_in);
162 prefsn.visible(true);
165 var noti = new notify(gst, prefsn_in.mesg, 0, mlang_prefsn['btn_close'][g_lang], 400, 150);
169 function prefsn_reset()
171 Fieldify.reset($('prefsn'));
180 function client_prefs(old)
183 this.listen = old.listen;
184 this.supp_comp = old.supp_comp;
188 client_prefs.prototype = {
190 supp_comp: 'ff00ffff00'
193 function prefs_assign(content)
198 s = "prefs_new = " + content;
204 function prefs_apply(prefs_new, is_update, is_volat)
209 if (typeof(g_prefs) == 'undefined')
211 /* listen management */
212 if (g_prefs.listen != prefs_new.listen || is_update) {
213 for (i = 0 ; i < l_prefs_list_idx.length ; i++) {
214 set_checked_value($('ra_listen_'+l_prefs_list_id[i]), prefs_new.listen);
215 if (prefs_new.listen == l_prefs_list_idx[i]) {
217 $('list_'+l_prefs_list_id[i]).style.color = 'red';
218 $('list_info').innerHTML = mlang_prefsn['tit_list'][i][g_lang];
222 $('list_'+l_prefs_list_id[i]).style.color = 'black';
229 // supporter component management
230 if (g_prefs.supp_comp != prefs_new.supp_comp || is_update) {
232 for (i = 0 ; i < 6 ; i++) {
233 $(l_comps_name[i]).value = parseInt(prefs_new.supp_comp.substr(i*2,2), 16);
235 $('s_img').src = 'suprend.php?comp='+prefs_new.supp_comp;
238 if (relo || !is_update) {
239 for (i = g_tables_auth_n ; i < g_tables_n ; i++) {
241 $('tr_noauth'+i).style.display = (prefs_new.listen == l_list_isol ? 'none' : '');
244 $('td_noauth'+i).style.display = (prefs_new.listen == l_list_isol ? 'none' : '');
246 if (prefs_new.listen == l_list_isol) {
254 // ricalculation of standup area
255 if (standup_data_old != null) {
256 standup_data = standup_data_old;
257 standup_data_old = null;
258 j_stand_cont(standup_data);
263 g_prefs.listen = prefs_new.listen;
264 g_prefs.supp_comp = prefs_new.supp_comp;
267 function prefs_load(content, is_update, is_volat)
271 // console.log('prefs_load('+content+')');
273 if ((prefs_new = prefs_assign(content)) == null)
276 return prefs_apply(prefs_new, is_update, is_volat);
279 function prefs_save()
283 if (typeof(g_prefs) == 'undefined')
286 ret = server_request('index_wr.php', sess, 'mesg', 'prefs|save','__POST__', 'prefs', JSON.stringify(g_prefs));
289 $('preferences').style.visibility = 'hidden';
296 function prefs_reset()
300 ret = server_request('index_wr.php', sess, 'mesg', 'prefs|reset');
303 function prefs_update(field)
308 // console.log("prefs_update("+field+")");
310 if (typeof(g_prefs) == 'undefined')
313 prefs_new = new client_prefs(g_prefs);
315 if (field == 'listen') {
316 /* listen management */
317 for (i = 0 ; i < l_prefs_list_idx.length ; i++) {
318 prefs_new.listen = get_checked_value($('ra_listen_'+l_prefs_list_id[i]));
319 if (prefs_new.listen != '')
323 else if (field == 'supp') {
324 for (i = 0 ; i < 6 ; i++) {
325 if (parseInt($(l_comps_name[i]).value) < 0 || parseInt($(l_comps_name[i]).value) > 255 ||
326 isNaN(parseInt($(l_comps_name[i]).value))) {
332 prefs_new.supp_comp = "";
333 for (i = 0 ; i < 6 ; i++) {
334 prefs_new.supp_comp += dec2hex(parseInt($(l_comps_name[i]).value), 2);
338 // console.log("prefs_update:: i break "+i+" ["+prefs_new.supp_comp+"]");
340 for (i = 0 ; i < 6 ; i++) {
341 $(l_comps_name[i]).value = parseInt(prefs_new.supp_comp.substr(i*2, 2), 16);
345 /* from form to struct */
346 prefs_apply(prefs_new, true, true);
349 function list_set(what, is_update, info)
353 var old_st = readCookie("CO_list");
355 if (what == 'auth') {
356 $('list_auth').style.color = 'red';
357 $('list_isol').style.color = 'black';
358 $('list_all').style.color = 'black';
359 if (old_st == 'isolation')
361 g_listen = l_list_auth;
363 else if (what == 'isolation') {
364 $('list_auth').style.color = 'black';
365 $('list_isol').style.color = 'red';
366 $('list_all').style.color = 'black';
367 if (old_st != 'isolation')
369 g_listen = l_list_isol;
372 $('list_auth').style.color = 'black';
373 $('list_isol').style.color = 'black';
374 $('list_all').style.color = 'red';
375 if (old_st == 'isolation')
377 g_listen = l_list_all;
380 set_checked_value($('ra_listen_auth'), what);
381 set_checked_value($('ra_listen_isol'), what);
382 set_checked_value($('ra_listen_all'), what);
384 $('list_info').innerHTML = info;
386 createCookie("CO_list", what, 24*365, cookiepath);
390 if (relo || !is_update) {
391 for (i = g_tables_auth_n ; i < g_tables_n ; i++) {
394 $('tr_noauth'+i).style.display = (what == 'isolation' ? 'none' : '');
397 $('td_noauth'+i).style.display = (what == 'isolation' ? 'none' : '');
399 if (what == 'isolation') {
407 // ricalculation of standup area
408 if (standup_data_old != null) {
409 standup_data = standup_data_old;
410 standup_data_old = null;
411 j_stand_cont(standup_data);