summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js
diff options
context:
space:
mode:
authorFabien Meghazi <fme@openerp.com>2012-09-05 15:45:53 +0200
committerFabien Meghazi <fme@openerp.com>2012-09-05 15:45:53 +0200
commitb675eb40de439b126fb4dffa00fde0c883f5f7b0 (patch)
tree5f3a6bf4d207aa56018b571aa763681539271794 /addons/web/static/src/js
parent604bd9fa4da689e3162a295ecd2959a764bd4eef (diff)
[ADD] Revert menu in case do_action fails
bzr revid: fme@openerp.com-20120905134553-k6ryuelp5fhsw6z9
Diffstat (limited to 'addons/web/static/src/js')
-rw-r--r--addons/web/static/src/js/chrome.js17
-rw-r--r--addons/web/static/src/js/views.js10
2 files changed, 15 insertions, 12 deletions
diff --git a/addons/web/static/src/js/chrome.js b/addons/web/static/src/js/chrome.js
index 3dd7672287f..3180c21f88e 100644
--- a/addons/web/static/src/js/chrome.js
+++ b/addons/web/static/src/js/chrome.js
@@ -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) {
diff --git a/addons/web/static/src/js/views.js b/addons/web/static/src/js/views.js
index 20f7b12c0ac..2f015dab7a0 100644
--- a/addons/web/static/src/js/views.js
+++ b/addons/web/static/src/js/views.js
@@ -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();
}