From: Matteo Nastasi (mop) Date: Tue, 5 Feb 2013 17:35:19 +0000 (+0100) Subject: enhanced prefs management X-Git-Tag: v4.7.1~20 X-Git-Url: http://mop.ddnsfree.com/gitweb/?p=brisk.git;a=commitdiff_plain;h=2dafd9b1a8edbf64595bee1e669be6c95921bf61 enhanced prefs management --- diff --git a/web/Obj/brisk.phh b/web/Obj/brisk.phh index bd1edb8..36060d8 100644 --- a/web/Obj/brisk.phh +++ b/web/Obj/brisk.phh @@ -928,7 +928,7 @@ class Room // for test: $prefs = new Client_prefs(USER_FLAG_LISTAUTH >> 2); $prefs = new Client_prefs(($user->flags & USER_FLAG_MAP_AUTH) >> 2); - $ret .= sprintf('prefs_load(\'%s\');', json_encode($prefs)); + $ret .= sprintf('prefs_load(\'%s\', false, false);', json_encode($prefs)); if(false) { if ($user->flags & USER_FLAG_ISOLAUTH) { diff --git a/web/commons.js b/web/commons.js index 158dc54..f522ad5 100644 --- a/web/commons.js +++ b/web/commons.js @@ -273,17 +273,28 @@ function send_mesg(mesg) } /* - request to server + sync request to server server_request([arg0=arg1[, arg2=arg3[, ...]]]) + if var name == '__POST__' than all other vars will be managed as POST content + and the call will be a POST */ function server_request() { var xhr_wr = createXMLHttpRequest(); - var i, collect = ""; + var i, collect = "", post_collect = null, is_post = false; if (arguments.length > 0) { for (i = 0 ; i < arguments.length ; i+= 2) { - collect += (i == 0 ? "" : "&") + arguments[i] + "=" + encodeURIComponent(arguments[i+1]); + if (arguments[i] == "__POST__") { + is_post = true; + post_collect = ""; + i -= 1; + continue; + } + if (is_post) + post_collect += (post_collect == "" ? "" : "&") + arguments[i] + "=" + encodeURIComponent(arguments[i+1]); + else + collect += (i == 0 ? "" : "&") + arguments[i] + "=" + encodeURIComponent(arguments[i+1]); } } // alert("Args: "+arguments.length); @@ -292,9 +303,15 @@ function server_request() // console.log("server_request:preresp: "+xhr_wr.responseText); - xhr_wr.open('GET', 'index_wr.php?'+(is_conn ? 'sess='+sess+'&' : '')+collect, false); + if (is_post) { + xhr_wr.open('POST', 'index_wr.php?'+(is_conn ? 'sess='+sess+'&' : '')+collect, false); + xhr_wr.setRequestHeader("Content-type","application/x-www-form-urlencoded"); + } + else { + xhr_wr.open('GET', 'index_wr.php?'+(is_conn ? 'sess='+sess+'&' : '')+collect, false); + } xhr_wr.onreadystatechange = function() { return; }; - xhr_wr.send(null); + xhr_wr.send(post_collect); if (xhr_wr.responseText != null) { // console.log("server_request:resp: "+xhr_wr.responseText); diff --git a/web/index.php b/web/index.php index 7e4ec9d..118c8d8 100644 --- a/web/index.php +++ b/web/index.php @@ -52,7 +52,7 @@ $mlang_room = array( 'userpasserr' => array('it' => 'Utente e/o password errati 'en' => 'back to tables'), 'btn_exit' => array('it' => 'Esco.', 'en' => 'Exit.'), - 'btn_prefs_update' => array('it' => 'Salva.', + 'btn_prefs_save' => array('it' => 'Salva.', 'en' => 'Save.'), 'btn_prefs_close' => array('it' => 'Chiudi.', 'en' => 'Close.'), @@ -1207,17 +1207,17 @@ type="submit" class="button" onclick="this.form.elements['realsub'].value = 'chi - - -
@@ -1236,7 +1236,7 @@ type="submit" class="button" onclick="this.form.elements['realsub'].value = 'chi -
+
diff --git a/web/index_wr.php b/web/index_wr.php index 9db78fc..a079438 100644 --- a/web/index_wr.php +++ b/web/index_wr.php @@ -184,7 +184,9 @@ function index_wr_main(&$room, $remote_addr_full, $get, $post, $cookie) else if ($argz[0] == 'whysupport') { echo show_notify(str_replace("\n", " ", $G_room_whysupport[$G_lang]), 0, $mlang_indwr['btn_close'][$G_lng], 400, 200); } - + else if ($argz[0] == 'prefs') { + fprintf(STDERR, "\n\n PREFS \n\n"); + } else { log_wr("Get User Error"); echo "Get User Error:" + $argz[0]; diff --git a/web/room.js b/web/room.js index 476429a..8456ecf 100644 --- a/web/room.js +++ b/web/room.js @@ -718,8 +718,11 @@ function prefs_assign(content) var prefs_list_idx = new Array( 0x00, 0x01, 0x02 ); var prefs_list_id = new Array( "all", "auth", "isol" ); -function prefs_apply(prefs_new) +function prefs_apply(prefs_new, is_update, is_volat) { + var i; + var relo = false; + if (typeof(g_prefs) == 'undefined') return false; @@ -728,27 +731,96 @@ function prefs_apply(prefs_new) 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]) { - $('list_'+prefs_list_id[i]).style.color = 'red'; + if (!is_volat) + $('list_'+prefs_list_id[i]).style.color = 'red'; $('list_info').innerHTML = mlang_commons['tit_list'][i][g_lang]; } else { - $('list_'+prefs_list_id[i]).style.color = 'black'; + if (!is_volat) + $('list_'+prefs_list_id[i]).style.color = 'black'; } } - g_prefs.listen = prefs_new.listen; relo = true; } + + + // TO BE ANALYZED !!! + // 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 = (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; } -function prefs_load(content) +function prefs_load(content, is_update, is_volat) { var prefs_new; if ((prefs_new = prefs_assign(content)) == null) return false; - return prefs_apply(prefs_new); + return prefs_apply(prefs_new, is_update, is_volat); +} + +function prefs_save() +{ + if (typeof(g_prefs) == 'undefined') + return false; + + console.log(server_request('mesg', 'prefs', '__POST__', 'prefs', JSON.stringify(g_prefs))); + // close the win: + // $('preferences').style.visibility = 'hidden'; +} + +function prefs_update() +{ + var i; + var prefs_new; + var relo = false; + + if (typeof(g_prefs) == 'undefined') + return false; + + prefs_new = new client_prefs(); + + /* 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; + } + + /* TODO SAVE TEMPORARY */ + /* from form to struct */ + console.log("Prefs_update"); + prefs_apply(prefs_new, true, true); } function list_set(what, is_update, info)