From 115568212c0b62540471708937e8ec3f70049b5c Mon Sep 17 00:00:00 2001 From: Holger Brunn Date: Thu, 3 Mar 2016 17:27:19 +0100 Subject: [PATCH] allow to pass a list of buttons --- web_ir_actions_act_window_message/README.rst | 25 ++++++++- .../js/web_ir_actions_act_window_message.js | 55 ++++++++++++++++++- 2 files changed, 77 insertions(+), 3 deletions(-) diff --git a/web_ir_actions_act_window_message/README.rst b/web_ir_actions_act_window_message/README.rst index f330f0bf..8341746d 100644 --- a/web_ir_actions_act_window_message/README.rst +++ b/web_ir_actions_act_window_message/README.rst @@ -14,6 +14,30 @@ Depend on this module and return 'type': 'ir.actions.act_window.message', 'title': _('My title'), 'message': _('My message'), + # this is an optional list of buttons to show + 'buttons': [ + # a button can be any action (also ir.actions.report.xml et al) + { + 'type': 'ir.actions.act_window', + 'name': 'All customers', + 'res_model': 'res.partner', + 'view_mode': 'form', + 'views': [[False, 'list'], [False, 'form']], + 'domain': [('customer', '=', True)], + }, + # or if type == method, you need to pass a model, a method name and + # parameters + { + 'type': 'method', + 'name': _('Yes, do it'), + 'model': self._name, + 'method': 'myfunction', + # list of arguments to pass positionally + 'args': [self.ids], + # dictionary of keyword arguments + 'kwargs': {'force': True}, + } + ] } You are responsible for translating the messages. @@ -24,7 +48,6 @@ Known issues / Roadmap * add `message_type` to differenciate between warnings, errors, etc. * have one `message_type` to show a nonmodal warning on top right * have `button_title` to set the button title -* have `buttons` containing button names and action definitions for triggering actions from the message box Bug Tracker diff --git a/web_ir_actions_act_window_message/static/src/js/web_ir_actions_act_window_message.js b/web_ir_actions_act_window_message/static/src/js/web_ir_actions_act_window_message.js index bfc6f55d..95f3b26d 100644 --- a/web_ir_actions_act_window_message/static/src/js/web_ir_actions_act_window_message.js +++ b/web_ir_actions_act_window_message/static/src/js/web_ir_actions_act_window_message.js @@ -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(); + }, + } + }); + }, }); }