[FIX] web: Discard from form view to form view

Clicking on the discard button in a form view whose previous view is
another form view wouldn't do anything.

This is fixed by making the view_manager trigger_up a history_back event
and then the history_back callback will handle cases in which there is
only one view and only one action, which used to be rejected
This commit is contained in:
Elkasitu
2017-07-13 13:10:30 +02:00
parent 60ee6bbda5
commit 0c496136a9
3 changed files with 13 additions and 17 deletions
@@ -420,16 +420,20 @@ var ActionManager = Widget.extend({
return this.inner_widget;
},
history_back: function() {
var nb_views = this.inner_action.get_nb_views();
if (nb_views > 1) {
var nbViews = this.inner_action.get_nb_views();
if (nbViews > 1) {
// Stay on this action, but select the previous view
return this.select_action(this.inner_action, nb_views - 2);
return this.select_action(this.inner_action, nbViews - 2);
}
if (this.action_stack.length > 1) {
var nbActions = this.action_stack.length;
if (nbActions > 1) {
// Select the previous action
var action = this.action_stack[this.action_stack.length - 2];
nb_views = action.get_nb_views();
return this.select_action(action, nb_views - 1);
var action = this.action_stack[nbActions - 2];
nbViews = action.get_nb_views();
return this.select_action(action, nbViews - 1);
}
else if (nbActions === 1 && nbViews === 1) {
return this.select_action(this.action_stack[0], 0);
}
return $.Deferred().reject();
},
@@ -636,18 +636,10 @@ var ViewManager = Widget.extend(ControlPanelMixin, {
* will call this very view manager to activate the previous view.
* @todo: directly switch to previous view
*
* A special case is done in the case that there is no previous view. When
* that happens, we simply rerender the current view.
*
* @private
*/
_onSwitchToPreviousView: function () {
if (this.view_stack.length === 1) {
var currentView = this.view_stack[0].controller;
currentView.update({}, {reload: false});
} else {
this.do_action('history_back');
}
this.trigger_up('history_back');
}
});
@@ -250,7 +250,7 @@ var BasicController = AbstractController.extend(FieldManagerMixin, {
on_fail: function (reason) {
reload().always(function() {
def.reject(reason);
})
});
},
on_success: def.resolve.bind(def),
});