forked from Techsystech/web
Add possibility to return an action in a notification
parent
8d3f2749e4
commit
b333cdc7b1
|
@ -30,16 +30,29 @@ or
|
|||
:scale: 80 %
|
||||
:alt: Sample notifications
|
||||
|
||||
The notifications can optionally have some action buttons.
|
||||
The notifications can bring interactivity with some buttons.
|
||||
|
||||
* One allowing to refresh the active view
|
||||
* Another allowing to send a window / client action
|
||||
|
||||
It is activated when sending the notification with:
|
||||
The reload button is activated when sending the notification with:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
self.env.user.notify_info('My information message', show_reload=True)
|
||||
|
||||
The action can be used using the ``action`` keyword:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
action = self.env.ref('sale.action_orders').read()[0]
|
||||
action.update({
|
||||
'res_id': self.id,
|
||||
'views': [(False, 'form')],
|
||||
})
|
||||
self.env.user.notify_info('My information message', action=action)
|
||||
|
||||
|
||||
Installation
|
||||
============
|
||||
|
||||
|
@ -74,6 +87,7 @@ Contributors
|
|||
|
||||
* Laurent Mignon <laurent.mignon@acsone.eu>
|
||||
* Serpent Consulting Services Pvt. Ltd.<jay.vora@serpentcs.com>
|
||||
* Guewen Baconnier <guewen.baconnier@camptocamp.com>
|
||||
|
||||
Maintainer
|
||||
----------
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import api, fields, models, _
|
||||
from odoo.addons.web.controllers.main import clean_action
|
||||
|
||||
|
||||
class ResUsers(models.Model):
|
||||
|
@ -25,26 +26,31 @@ class ResUsers(models.Model):
|
|||
|
||||
@api.multi
|
||||
def notify_info(self, message, title=None, sticky=False,
|
||||
show_reload=False):
|
||||
show_reload=False, action=None):
|
||||
title = title or _('Information')
|
||||
self._notify_channel(
|
||||
'notify_info_channel_name', message, title, sticky, show_reload)
|
||||
'notify_info_channel_name', message, title,
|
||||
sticky, show_reload, action)
|
||||
|
||||
@api.multi
|
||||
def notify_warning(self, message, title=None, sticky=False,
|
||||
show_reload=False):
|
||||
show_reload=False, action=None):
|
||||
title = title or _('Warning')
|
||||
self._notify_channel(
|
||||
'notify_warning_channel_name', message, title, sticky, show_reload)
|
||||
'notify_warning_channel_name', message, title,
|
||||
sticky, show_reload, action)
|
||||
|
||||
@api.multi
|
||||
def _notify_channel(self, channel_name_field, message, title, sticky,
|
||||
show_reload):
|
||||
show_reload, action):
|
||||
if action:
|
||||
action = clean_action(action)
|
||||
bus_message = {
|
||||
'message': message,
|
||||
'title': title,
|
||||
'sticky': sticky,
|
||||
'show_reload': show_reload,
|
||||
'action': action,
|
||||
}
|
||||
notifications = [(getattr(record, channel_name_field), bus_message)
|
||||
for record in self]
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
.o_notification {
|
||||
.o_notification_reload {
|
||||
.o_notification_action {
|
||||
padding: 10px;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,10 +12,14 @@ odoo.define('web_notify.notification', function (require) {
|
|||
events: _.extend(
|
||||
{},
|
||||
Notification.prototype.events,
|
||||
{'click .o_view_reload': function(e){
|
||||
{'click .o_notification_reload_view': function(e){
|
||||
e.preventDefault();
|
||||
this.reload_active_view();
|
||||
}
|
||||
},
|
||||
'click .o_notification_do_action': function(e){
|
||||
e.preventDefault();
|
||||
this.button_do_action();
|
||||
}
|
||||
}
|
||||
),
|
||||
init: function(parent, title, text, sticky, options) {
|
||||
|
@ -25,6 +29,10 @@ odoo.define('web_notify.notification', function (require) {
|
|||
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);
|
||||
}
|
||||
});
|
||||
|
||||
base_notification.NotificationManager.include({
|
||||
|
|
|
@ -2,22 +2,32 @@
|
|||
<templates id="template" xml:space="preserve">
|
||||
|
||||
<t t-name="Notification.reload">
|
||||
<div class="o_notification_reload" t-if="widget.options.show_reload">
|
||||
<a href="#" class="o_view_reload">
|
||||
<div class="o_notification_action" t-if="widget.options.show_reload">
|
||||
<a href="#" class="o_notification_reload_view">
|
||||
<span class="fa fa-refresh"/> Reload current view
|
||||
</a>
|
||||
</div>
|
||||
</t>
|
||||
|
||||
<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
|
||||
</a>
|
||||
</div>
|
||||
</t>
|
||||
|
||||
<t t-extend="Notification">
|
||||
<t t-jquery=".o_notification_content" t-operation="after">
|
||||
<t t-call="Notification.reload"/>
|
||||
<t t-call="Notification.do_action"/>
|
||||
</t>
|
||||
</t>
|
||||
|
||||
<t t-extend="Warning">
|
||||
<t t-jquery=".o_notification_content" t-operation="after">
|
||||
<t t-call="Notification.reload"/>
|
||||
<t t-call="Notification.do_action"/>
|
||||
</t>
|
||||
</t>
|
||||
|
||||
|
|
Loading…
Reference in New Issue