details: https://code.tryton.org/tryton/commit/9a736ac443a2
branch: default
user: Cédric Krier <[email protected]>
date: Fri Jan 23 12:04:00 2026 +0100
description:
Save synchronously the tree state of the menu when the page is unloaded
The callback of window.onbeforeunload can only be synchronous in order
to be
sure that it is fully executed.
Closes #14543
diffstat:
sao/src/sao.js | 6 +++++-
sao/src/screen.js | 26 ++++++++++++++++----------
2 files changed, 21 insertions(+), 11 deletions(-)
diffs (74 lines):
diff -r 4e3fe3bde37a -r 9a736ac443a2 sao/src/sao.js
--- a/sao/src/sao.js Fri Jan 23 12:02:52 2026 +0100
+++ b/sao/src/sao.js Fri Jan 23 12:04:00 2026 +0100
@@ -104,7 +104,11 @@
window.onbeforeunload = function(e) {
if (Sao.main_menu_screen) {
- Sao.main_menu_screen.save_tree_state(true);
+ try {
+ Sao.main_menu_screen.save_tree_state(true, false);
+ } catch (e) {
+ console.error("save tree failed", e);
+ }
}
if (Sao.Tab.tabs.length) {
var dialog = Sao.i18n.gettext("Are your sure to leave?");
diff -r 4e3fe3bde37a -r 9a736ac443a2 sao/src/screen.js
--- a/sao/src/screen.js Fri Jan 23 12:02:52 2026 +0100
+++ b/sao/src/screen.js Fri Jan 23 12:04:00 2026 +0100
@@ -2207,9 +2207,8 @@
}
return path;
},
- save_tree_state: function(store=true) {
+ save_tree_state: function(store=true, async=true) {
var prms = [];
- var prm;
var i, len, view, widgets, wi, wlen;
var parent_ = this.group.parent ? this.group.parent.id : null;
var clear_cache = function() {
@@ -2228,8 +2227,11 @@
widgets = view.widgets[wid_key];
for (wi = 0, wlen = widgets.length; wi < wlen; wi++) {
if (widgets[wi].screen) {
- prm =
widgets[wi].screen.save_tree_state(store);
- prms.push(prm);
+ let result =
widgets[wi].screen.save_tree_state(
+ store, async);
+ if (async) {
+ prms.push(result);
+ }
}
}
}
@@ -2262,19 +2264,23 @@
if (store && parseInt(view.attributes.tree_state, 10)) {
var tree_state_model = new Sao.Model(
'ir.ui.view_tree_state');
- prm = tree_state_model.execute('set', [
+ let result = tree_state_model.execute('set', [
this.model_name,
this.get_tree_domain(parent_),
view.children_field,
JSON.stringify(paths),
- JSON.stringify(selected_paths)], {})
- .then(clear_cache)
- .fail(set_session_fail);
- prms.push(prm);
+ JSON.stringify(selected_paths)], {}, async)
+ if (async) {
+ result.then(clear_cache)
+ .fail(set_session_fail);
+ prms.push(result);
+ }
}
}
}
- return jQuery.when.apply(jQuery, prms);
+ if (async) {
+ return jQuery.when.apply(jQuery, prms);
+ }
},
get_tree_domain: function(parent_) {
var domain;