[IMP] Improved action buttons for wizards
bzr revid: fme@openerp.com-20110713142502-r9xzs6crfusu5ccl
This commit is contained in:
parent
a2e890635b
commit
595496206c
|
@ -722,10 +722,7 @@ openerp.base.form.WidgetButton = openerp.base.form.Widget.extend({
|
|||
|
||||
this.view.execute_action(
|
||||
this.node.attrs, this.view.dataset, this.session.action_manager,
|
||||
this.view.datarecord.id, function (result) {
|
||||
self.log("Button returned", result);
|
||||
self.view.reload();
|
||||
}, function() {
|
||||
this.view.datarecord.id, function () {
|
||||
self.view.reload();
|
||||
});
|
||||
}
|
||||
|
|
|
@ -453,13 +453,7 @@ openerp.base.ListView = openerp.base.View.extend( /** @lends openerp.base.ListVi
|
|||
return field.name === name;
|
||||
});
|
||||
if (!action) { return; }
|
||||
this.execute_action(
|
||||
action, this.dataset, this.session.action_manager,
|
||||
id, function () {
|
||||
if (callback) {
|
||||
callback();
|
||||
}
|
||||
});
|
||||
this.execute_action(action, this.dataset, this.session.action_manager, id, callback);
|
||||
},
|
||||
/**
|
||||
* Handles the activation of a record (clicking on it)
|
||||
|
|
|
@ -29,17 +29,6 @@ openerp.base.ActionManager = openerp.base.Controller.extend({
|
|||
pager : action.target != 'new'
|
||||
}, action.flags || {});
|
||||
// instantiate the right controllers by understanding the action
|
||||
if (this.current_dialog) {
|
||||
this.current_dialog.stop();
|
||||
this.current_dialog = null;
|
||||
}
|
||||
if (this.current_dialog) {
|
||||
this.current_dialog.stop();
|
||||
this.current_dialog = null;
|
||||
} else if (this.view_manager && this.view_manager.current_dialog) {
|
||||
this.view_manager.current_dialog.stop();
|
||||
this.view_manager.current_dialog = null;
|
||||
}
|
||||
switch (action.type) {
|
||||
case 'ir.actions.act_window':
|
||||
if (!action.target && this.current_dialog) {
|
||||
|
@ -51,14 +40,11 @@ openerp.base.ActionManager = openerp.base.Controller.extend({
|
|||
width: '50%'
|
||||
});
|
||||
if (on_closed) {
|
||||
dialog.on_closed.add_first(on_closed);
|
||||
dialog.close_callback = on_closed;
|
||||
}
|
||||
dialog.start(false);
|
||||
var viewmanager = new openerp.base.ViewManagerAction(this.session, dialog.element_id, action);
|
||||
var viewmanager = dialog.viewmanager = new openerp.base.ViewManagerAction(this.session, dialog.element_id, action);
|
||||
viewmanager.start();
|
||||
// TODO: merge ActionManager & ViewManager in order to get rid of this circular reference
|
||||
viewmanager.current_dialog = dialog;
|
||||
dialog.viewmanager = viewmanager;
|
||||
dialog.open();
|
||||
} else if (action.flags.new_window) {
|
||||
action.flags.new_window = false;
|
||||
|
@ -76,6 +62,7 @@ openerp.base.ActionManager = openerp.base.Controller.extend({
|
|||
}
|
||||
break;
|
||||
case 'ir.actions.act_window_close':
|
||||
this.close_dialog();
|
||||
break;
|
||||
case 'ir.actions.server':
|
||||
this.rpc('/base/action/run', {
|
||||
|
@ -88,6 +75,12 @@ openerp.base.ActionManager = openerp.base.Controller.extend({
|
|||
default:
|
||||
console.log("Action manager can't handle action of type " + action.type, action);
|
||||
}
|
||||
},
|
||||
close_dialog: function() {
|
||||
if (this.current_dialog) {
|
||||
this.current_dialog.stop();
|
||||
this.current_dialog = null;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -344,14 +337,11 @@ openerp.base.ViewManagerAction = openerp.base.ViewManager.extend({
|
|||
|
||||
openerp.base.ActionDialog = openerp.base.Dialog.extend({
|
||||
identifier_prefix: 'action_dialog',
|
||||
close: function() {
|
||||
this._super(this, arguments);
|
||||
this.on_closed();
|
||||
},
|
||||
on_closed: function() {
|
||||
},
|
||||
stop: function() {
|
||||
this._super(this, arguments);
|
||||
if (this.close_callback) {
|
||||
this.close_callback();
|
||||
}
|
||||
if (this.viewmanager) {
|
||||
this.viewmanager.stop();
|
||||
}
|
||||
|
@ -446,11 +436,15 @@ openerp.base.View = openerp.base.Controller.extend({
|
|||
* @param {openerp.base.DataSet} dataset a dataset object used to communicate with the server
|
||||
* @param {openerp.base.ActionManager} action_manager object able to actually execute the action, if any is fetched
|
||||
* @param {Object} [record_id] the identifier of the object on which the action is to be applied
|
||||
* @param {Function} on_no_action callback to execute if the action does not generate any result (no new action)
|
||||
* @param {Function} on_closed callback to execute when dialog is closed or when the action does not generate any result (no new action)
|
||||
*/
|
||||
execute_action: function (action_data, dataset, action_manager, record_id, on_no_action, on_closed) {
|
||||
execute_action: function (action_data, dataset, action_manager, record_id, on_closed) {
|
||||
var self = this;
|
||||
if (action_manager.current_dialog) {
|
||||
on_closed = action_manager.current_dialog.close_callback;
|
||||
}
|
||||
var handler = function (r) {
|
||||
action_manager.close_dialog();
|
||||
var action = r.result;
|
||||
if (action && action.constructor == Object) {
|
||||
action.context = action.context || {};
|
||||
|
@ -463,20 +457,12 @@ openerp.base.View = openerp.base.Controller.extend({
|
|||
new_window: true
|
||||
};
|
||||
action_manager.do_action(action, on_closed);
|
||||
} else {
|
||||
on_no_action(action);
|
||||
} else if (on_closed) {
|
||||
on_closed(action);
|
||||
}
|
||||
};
|
||||
|
||||
if (action_data.special) {
|
||||
if (action_manager.current_dialog) {
|
||||
action_manager.current_dialog.stop();
|
||||
action_manager.current_dialog = null;
|
||||
} else if (this.view_manager.current_dialog) {
|
||||
this.view_manager.current_dialog.stop();
|
||||
this.view_manager.current_dialog = null;
|
||||
}
|
||||
} else {
|
||||
if (!action_data.special) {
|
||||
var context = new openerp.base.CompoundContext(dataset.get_context(), action_data.context || {});
|
||||
switch(action_data.type) {
|
||||
case 'object':
|
||||
|
@ -486,6 +472,8 @@ openerp.base.View = openerp.base.Controller.extend({
|
|||
default:
|
||||
return dataset.exec_workflow(record_id, action_data.name, handler);
|
||||
}
|
||||
} else {
|
||||
action_manager.close_dialog();
|
||||
}
|
||||
},
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue