[ADD] Revert menu in case do_action fails

bzr revid: fme@openerp.com-20120905134553-k6ryuelp5fhsw6z9
This commit is contained in:
Fabien Meghazi 2012-09-05 15:45:53 +02:00
parent 604bd9fa4d
commit b675eb40de
2 changed files with 15 additions and 12 deletions

View File

@ -731,6 +731,8 @@ instance.web.Menu = instance.web.Widget.extend({
* @param {Number} id database id of the terminal menu to select
*/
open_menu: function (id) {
this.current_menu = id;
this.session.active_id = id;
var $clicked_menu, $sub_menu, $main_menu;
$clicked_menu = this.$el.add(this.$secondary_menus).find('a[data-menu=' + id + ']');
this.trigger('open_menu', id, $clicked_menu);
@ -803,16 +805,15 @@ instance.web.Menu = instance.web.Widget.extend({
}
}
}
this.open_menu(id);
this.current_menu = id;
this.session.active_id = id;
if (action_id) {
this.trigger('menu_click', {
action_id: action_id,
needaction: needaction,
id: id
id: id,
previous_menu_id: this.current_menu // Here we don't know if action will fail (in which case we have to revert menu)
}, $item);
}
this.open_menu(id);
},
/**
* Jquery event handler for menu click
@ -1095,13 +1096,15 @@ instance.web.WebClient = instance.web.Client.extend({
},
on_menu_action: function(options) {
var self = this;
this.rpc("/web/action/load", { action_id: options.action_id })
.then(function (result) {
return this.rpc("/web/action/load", { action_id: options.action_id })
.pipe(function (result) {
var action = result.result;
if (options.needaction) {
action.context.search_default_needaction_pending = true;
}
self.action_manager.do_action(action, null, true);
return $.when(self.action_manager.do_action(action, null, true)).fail(function() {
self.menu.open_menu(options.previous_menu_id);
});
});
},
do_action: function(action) {

View File

@ -215,13 +215,13 @@ instance.web.ActionManager = instance.web.Widget.extend({
return this.do_action(action_client, on_close, clear_breadcrumbs);
} else if (_.isNumber(action) || _.isString(action)) {
var self = this;
return self.rpc("/web/action/load", { action_id: action }, function(result) {
self.do_action(result.result, on_close, clear_breadcrumbs);
return self.rpc("/web/action/load", { action_id: action }).pipe(function(result) {
return self.do_action(result.result, on_close, clear_breadcrumbs);
});
}
if (!action.type) {
console.error("No type for action", action);
return null;
return $.Deferred().reject();
}
var type = action.type.replace(/\./g,'_');
var popup = action.target === 'new';
@ -236,7 +236,7 @@ instance.web.ActionManager = instance.web.Widget.extend({
}, action.flags || {});
if (!(type in this)) {
console.error("Action manager can't handle action of type " + action.type, action);
return null;
return $.Deferred().reject();
}
return this[type](action, on_close, clear_breadcrumbs);
},
@ -250,7 +250,7 @@ instance.web.ActionManager = instance.web.Widget.extend({
var $e = $.Event("about_to_destroy");
this.inner_widget.trigger("about_to_destroy", $e);
if ($e.isDefaultPrevented()) {
return;
return $.Deferred().reject();
} else if (clear_breadcrumbs) {
this.clear_breadcrumbs();
}