mirror of https://github.com/OCA/web.git
Make notify options variadic
It opens for extensions. The implemented options now allow to configure the name and the icon of the link for the action. Addons could easily add new features as the arguments are no longer predefined, they'll all be available in the 'options' dictionary.pull/1029/head
parent
bf7fda1980
commit
4fd13e22da
|
@ -50,7 +50,12 @@ The action can be used using the ``action`` keyword:
|
|||
'res_id': self.id,
|
||||
'views': [(False, 'form')],
|
||||
})
|
||||
self.env.user.notify_info('My information message', action=action)
|
||||
self.env.user.notify_info(
|
||||
'My information message',
|
||||
action=action,
|
||||
# optional
|
||||
action_link_name=_('Open Sale'),
|
||||
)
|
||||
|
||||
|
||||
Installation
|
||||
|
|
|
@ -26,32 +26,35 @@ class ResUsers(models.Model):
|
|||
|
||||
@api.multi
|
||||
def notify_info(self, message, title=None, sticky=False,
|
||||
show_reload=False, action=None):
|
||||
show_reload=False, action=None,
|
||||
action_link_name=None, **options):
|
||||
title = title or _('Information')
|
||||
self._notify_channel(
|
||||
'notify_info_channel_name', message, title,
|
||||
sticky, show_reload, action)
|
||||
sticky=sticky, show_reload=show_reload, action=action,
|
||||
action_link_name=action_link_name, **options
|
||||
)
|
||||
|
||||
@api.multi
|
||||
def notify_warning(self, message, title=None, sticky=False,
|
||||
show_reload=False, action=None):
|
||||
show_reload=False, action=None,
|
||||
action_link_name=None, **options):
|
||||
title = title or _('Warning')
|
||||
self._notify_channel(
|
||||
'notify_warning_channel_name', message, title,
|
||||
sticky, show_reload, action)
|
||||
sticky=sticky, show_reload=show_reload, action=action,
|
||||
action_link_name=action_link_name, **options
|
||||
)
|
||||
|
||||
@api.multi
|
||||
def _notify_channel(self, channel_name_field, message, title, sticky,
|
||||
show_reload, action):
|
||||
if action:
|
||||
action = clean_action(action)
|
||||
def _notify_channel(self, channel_name_field, message, title, **options):
|
||||
if options.get('action'):
|
||||
options['action'] = clean_action(options['action'])
|
||||
bus_message = {
|
||||
'message': message,
|
||||
'title': title,
|
||||
'sticky': sticky,
|
||||
'show_reload': show_reload,
|
||||
'action': action,
|
||||
}
|
||||
bus_message.update(options)
|
||||
notifications = [(getattr(record, channel_name_field), bus_message)
|
||||
for record in self]
|
||||
self.env['bus.bus'].sendmany(notifications)
|
||||
|
|
|
@ -5,8 +5,7 @@ odoo.define('web_notify.notification', function (require) {
|
|||
|
||||
var base_notification = require('web.notification'),
|
||||
WebClient = require('web.WebClient'),
|
||||
Notification = base_notification.Notification,
|
||||
Warning = base_notification.Warning;
|
||||
Notification = base_notification.Notification;
|
||||
|
||||
var InteractiveNotification = Notification.extend({
|
||||
template: 'InteractiveNotification',
|
||||
|
@ -23,15 +22,15 @@ odoo.define('web_notify.notification', function (require) {
|
|||
}
|
||||
}
|
||||
),
|
||||
init: function(parent, title, text, sticky, options) {
|
||||
this._super.apply(this, [parent, title, text, sticky]);
|
||||
init: function(parent, title, text, options) {
|
||||
this.options = options || {};
|
||||
var sticky = this.options.sticky;
|
||||
this._super.apply(this, [parent, title, text, sticky]);
|
||||
},
|
||||
reload_active_view: function() {
|
||||
this.trigger_up('reload_active_view');
|
||||
},
|
||||
button_do_action: function() {
|
||||
console.log(this.options.action);
|
||||
this.getParent().do_action(this.options.action);
|
||||
}
|
||||
});
|
||||
|
@ -41,11 +40,11 @@ odoo.define('web_notify.notification', function (require) {
|
|||
});
|
||||
|
||||
base_notification.NotificationManager.include({
|
||||
interactive_notify(title, text, sticky, options) {
|
||||
return this.display(new InteractiveNotification(this, title, text, sticky, options));
|
||||
interactive_notify(title, text, options) {
|
||||
return this.display(new InteractiveNotification(this, title, text, options));
|
||||
},
|
||||
interactive_warn(title, text, sticky, options) {
|
||||
return this.display(new InteractiveWarning(this, title, text, sticky, options));
|
||||
interactive_warn(title, text, options) {
|
||||
return this.display(new InteractiveWarning(this, title, text, options));
|
||||
}
|
||||
|
||||
});
|
||||
|
|
|
@ -8,17 +8,15 @@ var core = require('web.core'),
|
|||
|
||||
|
||||
Widget.include({
|
||||
do_interactive_notify: function(title, message, sticky, options) {
|
||||
do_interactive_notify: function(title, message, options) {
|
||||
this.trigger_up(
|
||||
'interactive_notification',
|
||||
{title: title, message: message,
|
||||
sticky: sticky, options: options});
|
||||
{title: title, message: message, options: options});
|
||||
},
|
||||
do_interactive_warn: function(title, message, sticky, options) {
|
||||
do_interactive_warn: function(title, message, options) {
|
||||
this.trigger_up(
|
||||
'interactive_warning',
|
||||
{title: title, message: message,
|
||||
sticky: sticky, options: options});
|
||||
{title: title, message: message, options: options});
|
||||
},
|
||||
});
|
||||
|
||||
|
@ -31,16 +29,14 @@ WebClient.include({
|
|||
interactive_notification: function (e) {
|
||||
if(this.notification_manager) {
|
||||
this.notification_manager.interactive_notify(
|
||||
e.data.title, e.data.message,
|
||||
e.data.sticky, e.data.options
|
||||
e.data.title, e.data.message, e.data.options
|
||||
);
|
||||
}
|
||||
},
|
||||
interactive_warning: function (e) {
|
||||
if(this.notification_manager) {
|
||||
this.notification_manager.interactive_warn(
|
||||
e.data.title, e.data.message,
|
||||
e.data.sticky, e.data.options
|
||||
e.data.title, e.data.message, e.data.options
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -92,14 +88,14 @@ WebClient.include({
|
|||
on_message_warning: function(message){
|
||||
if(this.notification_manager) {
|
||||
this.notification_manager.do_interactive_warn(
|
||||
message.title, message.message, message.sticky, message
|
||||
message.title, message.message, message
|
||||
);
|
||||
}
|
||||
},
|
||||
on_message_info: function(message){
|
||||
if(this.notification_manager) {
|
||||
this.notification_manager.do_interactive_notify(
|
||||
message.title, message.message, message.sticky, message
|
||||
message.title, message.message, message
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,7 +12,11 @@
|
|||
<t t-name="Notification.do_action">
|
||||
<div class="o_notification_action" t-if="widget.options.action">
|
||||
<a href="#" class="o_notification_do_action">
|
||||
<span class="fa fa-arrow-circle-left"/> Open
|
||||
<span t-att-class="'fa ' + (widget.options.action_fa_icon ? widget.options.action_fa_icon : 'fa-arrow-circle-left')"/>
|
||||
<t t-if="widget.options.action_link_name">
|
||||
<t t-esc="widget.options.action_link_name"/>
|
||||
</t>
|
||||
<t t-else="">Open</t>
|
||||
</a>
|
||||
</div>
|
||||
</t>
|
||||
|
|
Loading…
Reference in New Issue