Use existing context for get_preferences and keep it in sessionStorage

So we present to the user his current contextual values.
But we clear the context after modification.

issue9327
review299651002
This commit is contained in:
Cédric Krier
2020-06-06 14:01:51 +02:00
parent 9feccfba49
commit e898419e8f
3 changed files with 27 additions and 7 deletions
+2
View File
@@ -1,3 +1,5 @@
* Keep context in sessionStorage
* Use existing context for get_preferences
* Escape external strings (issue9351)
* Add context to export URL
* Allow changes to editable tree checkboxes without first selecting the line
+1
View File
@@ -586,6 +586,7 @@ var Sao = {};
jQuery('#user-logout').empty();
jQuery('#menu').empty();
new Sao.Window.Preferences(function() {
Sao.Session.current_session.reset_context();
Sao.get_preferences().then(function(preferences) {
Sao.menu(preferences);
Sao.user_menu(preferences);
+24 -7
View File
@@ -17,9 +17,8 @@
this.database = database;
this.login = login;
this.restore();
this.context = {
client: Sao.Bus.id,
};
this.context = {};
this.restore_context();
if (!Sao.Session.current_session) {
Sao.Session.current_session = this;
}
@@ -82,16 +81,34 @@
reload_context: function() {
var args = {
'method': 'model.res.user.get_preferences',
'params': [true, {}]
};
this.context = {
client: Sao.Bus.id,
'params': [true, this.context]
};
this.reset_context();
var prm = Sao.rpc(args, this);
return prm.then(function(context) {
jQuery.extend(this.context, context);
this.store_context();
}.bind(this));
},
reset_context: function() {
this.context = {
client: Sao.Bus.id,
};
},
restore_context: function() {
this.reset_context();
var context = sessionStorage.getItem('sao_context_' + this.database);
if (context !== null) {
jQuery.extend(
this.context, Sao.rpc.convertJSONObject(JSON.parse(context)));
}
},
store_context: function() {
var context = jQuery.extend({}, this.context);
delete context.client;
context = JSON.stringify(Sao.rpc.prepareObject(context));
sessionStorage.setItem('sao_context_' + this.database, context);
},
restore: function() {
if (this.database && !this.session) {
var session_data = localStorage.getItem(