allow to pass a list of buttons

This commit is contained in:
Holger Brunn
2016-03-03 17:27:19 +01:00
committed by Jasmin Solanki
parent 2ea4d8bd23
commit 208e8d4475
2 changed files with 77 additions and 3 deletions

View File

@@ -24,7 +24,8 @@ openerp.web_ir_actions_act_window_message = function(instance)
instance.web.ActionManager.include({
ir_actions_act_window_message: function(action, options)
{
var dialog = new instance.web.Dialog(
var self = this,
dialog = new instance.web.Dialog(
this,
{
size: 'medium',
@@ -35,7 +36,10 @@ openerp.web_ir_actions_act_window_message = function(instance)
click: function() { dialog.close() },
oe_link_class: 'oe_highlight',
},
],
].concat(
this.ir_actions_act_window_message_get_buttons(
action, function() { dialog.close() })
),
},
jQuery(instance.web.qweb.render(
'web_ir_actions_act_window_message',
@@ -46,5 +50,52 @@ openerp.web_ir_actions_act_window_message = function(instance)
)
return dialog.open();
},
ir_actions_act_window_message_get_buttons: function(action, close_func)
{
// return an array of button definitions from action
var self = this;
return _.map(action.buttons || [], function(button_definition)
{
return {
text: button_definition.name || 'No name set',
oe_link_class: button_definition.oe_link_class ||
'oe_highlight',
click: function() {
if(button_definition.type == 'method')
{
(new instance.web.Model(button_definition.model))
.call(
button_definition.method,
button_definition.args,
button_definition.kwargs
).then(function(result)
{
if(_.isObject(result))
{
self.do_action(result);
}
else
{
if(
self.inner_widget &&
self.inner_widget.views
)
{
self.inner_widget
.views[self.inner_widget.active_view]
.controller.recursive_reload();
}
}
});
}
else
{
self.do_action(button_definition);
}
close_func();
},
}
});
},
});
}