[IMP] Use an 'options' dict as second arg for ActionManager#do_action()

bzr revid: fme@openerp.com-20121017145548-oc9s6oadhwzbr78m
This commit is contained in:
Fabien Meghazi 2012-10-17 16:55:48 +02:00
parent b85b32fb2b
commit 31b316577c
2 changed files with 31 additions and 26 deletions

View File

@ -1122,7 +1122,9 @@ instance.web.WebClient = instance.web.Client.extend({
if (options.needaction) {
action.context.search_default_message_unread = true;
}
return $.when(self.action_manager.do_action(action, null, true)).fail(function() {
return $.when(self.action_manager.do_action(action, {
clear_breadcrumbs: true,
})).fail(function() {
self.menu.open_menu(options.previous_menu_id);
});
});

View File

@ -239,14 +239,19 @@ instance.web.ActionManager = instance.web.Widget.extend({
}
});
},
do_action: function(action, on_close, clear_breadcrumbs, on_reverse_breadcrumb) {
do_action: function(action, options) {
options = _.defaults(options || {}, {
clear_breadcrumbs: false,
on_reverse_breadcrumb: function() {},
on_close: function() {},
});
if (_.isString(action) && instance.web.client_actions.contains(action)) {
var action_client = { type: "ir.actions.client", tag: action };
return this.do_action(action_client, on_close, clear_breadcrumbs, on_reverse_breadcrumb);
return this.do_action(action_client, options);
} else if (_.isNumber(action) || _.isString(action)) {
var self = this;
return self.rpc("/web/action/load", { action_id: action }).pipe(function(result) {
return self.do_action(result, on_close, clear_breadcrumbs, on_reverse_breadcrumb);
return self.do_action(result, options);
});
}
if (!action.type) {
@ -268,7 +273,7 @@ instance.web.ActionManager = instance.web.Widget.extend({
console.error("Action manager can't handle action of type " + action.type, action);
return $.Deferred().reject();
}
return this[type](action, on_close, clear_breadcrumbs, on_reverse_breadcrumb);
return this[type](action, options);
},
null_action: function() {
this.dialog_stop();
@ -281,15 +286,14 @@ instance.web.ActionManager = instance.web.Widget.extend({
* @param {Function<instance.web.Widget>} executor.widget function used to fetch the widget instance
* @param {String} executor.klass CSS class to add on the dialog root, if action.target=new
* @param {Function<instance.web.Widget, undefined>} executor.post_process cleanup called after a widget has been added as inner_widget
* @param on_close
* @param clear_breadcrumbs
* @param {Object} options
* @return {*}
*/
ir_actions_common: function(executor, on_close, clear_breadcrumbs) {
ir_actions_common: function(executor, options) {
if (this.inner_widget && executor.action.target !== 'new') {
if (this.getParent().has_uncommitted_changes()) {
return $.Deferred().reject();
} else if (clear_breadcrumbs) {
} else if (options.clear_breadcrumbs) {
this.clear_breadcrumbs();
}
}
@ -300,8 +304,7 @@ instance.web.ActionManager = instance.web.Widget.extend({
buttons: {"Close": function() {$(this).dialog("close")}},
dialogClass: executor.klass,
});
if (on_close)
this.dialog.on("closing", null, on_close);
this.dialog.on("closing", null, options.on_close);
this.dialog.init_dialog();
} else {
this.dialog_widget.destroy();
@ -325,24 +328,24 @@ instance.web.ActionManager = instance.web.Widget.extend({
return this.inner_widget.appendTo(this.$el);
}
},
ir_actions_act_window: function (action, on_close, clear_breadcrumbs, on_reverse_breadcrumb) {
ir_actions_act_window: function (action, options) {
var self = this;
return this.ir_actions_common({
widget: function () { return new instance.web.ViewManagerAction(self, action); },
action: action,
klass: 'oe_act_window',
post_process: function (widget) { widget.add_breadcrumb(on_reverse_breadcrumb); }
}, on_close, clear_breadcrumbs, on_reverse_breadcrumb);
post_process: function (widget) { widget.add_breadcrumb(options.on_reverse_breadcrumb); }
}, options);
},
ir_actions_client: function (action, on_close, clear_breadcrumbs, on_reverse_breadcrumb) {
ir_actions_client: function (action, options) {
var self = this;
var ClientWidget = instance.web.client_actions.get_object(action.tag);
if (!(ClientWidget.prototype instanceof instance.web.Widget)) {
var next;
if (next = ClientWidget(this, action.params)) {
return this.do_action(next, on_close, clear_breadcrumbs, on_reverse_breadcrumb);
return this.do_action(next, options);
}
return $.when();
}
@ -355,30 +358,30 @@ instance.web.ActionManager = instance.web.Widget.extend({
self.push_breadcrumb({
widget: widget,
title: action.name,
on_reverse_breadcrumb: on_reverse_breadcrumb,
on_reverse_breadcrumb: options.on_reverse_breadcrumb,
});
if (action.tag !== 'reload') {
self.do_push_state({});
}
}
}, on_close, clear_breadcrumbs, on_reverse_breadcrumb);
}, options);
},
ir_actions_act_window_close: function (action, on_closed) {
if (!this.dialog && on_closed) {
on_closed();
ir_actions_act_window_close: function (action, options) {
if (!this.dialog) {
options.on_close();
}
this.dialog_stop();
},
ir_actions_server: function (action, on_closed, clear_breadcrumbs, on_reverse_breadcrumb) {
ir_actions_server: function (action, options) {
var self = this;
this.rpc('/web/action/run', {
action_id: action.id,
context: action.context || {}
}).then(function (action) {
self.do_action(action, on_closed, clear_breadcrumbs, on_reverse_breadcrumb)
self.do_action(action, options)
});
},
ir_actions_report_xml: function(action, on_closed) {
ir_actions_report_xml: function(action, options) {
var self = this;
instance.web.blockUI();
self.rpc("/web/session/eval_domain_and_context", {
@ -392,8 +395,8 @@ instance.web.ActionManager = instance.web.Widget.extend({
data: {action: JSON.stringify(action)},
complete: instance.web.unblockUI,
success: function(){
if (!self.dialog && on_closed) {
on_closed();
if (!self.dialog) {
options.on_close();
}
self.dialog_stop();
},