[FIX] web: view_manager: restore internal state on switch view failure

When an error occured when switching from a view to another (e.g. switching
to a form view for an id that doesn't exist, by editing the url), active_view
and view_stack were updated even though the switch failed. The view manager
thus lost the reference to the real current active view, which couldn't be
detached anymore. This resulted in two views being displayed at the same time
if the user kept navigating through this view manager.

This is a backport of odoo/enterprise@0b1aafa6b and odoo/enterprise@8e691be.
This commit is contained in:
Aaron Bohy
2016-01-18 14:01:21 +01:00
parent 93075b6b4b
commit 206cc91a63
+10 -1
View File
@@ -156,11 +156,20 @@ var ViewManager = Widget.extend(ControlPanelMixin, {
self.searchview.do_search();
});
}
return $.when(view.created, this.active_search).then(function () {
var switched = $.when(view.created, this.active_search).then(function () {
return self._display_view(view_options, old_view).then(function () {
self.trigger('switch_mode', view_type, no_store, view_options);
});
});
switched.fail(function(e) {
if (!(e && e.code === 200 && e.data.exception_type)) {
self.do_warn(_t("Error"), view.controller.display_name + _t(" view couldn't be loaded"));
}
// Restore internal state
self.active_view = old_view;
self.view_stack.pop();
});
return switched;
},
_display_view: function (view_options, old_view) {
var self = this;