diff --git a/web_notify/README.rst b/web_notify/README.rst
index 2fa24871b..0d95e255a 100644
--- a/web_notify/README.rst
+++ b/web_notify/README.rst
@@ -30,6 +30,16 @@ or
:scale: 80 %
:alt: Sample notifications
+The notifications can optionally have some action buttons.
+
+* One allowing to refresh the active view
+
+It is activated when sending the notification with:
+
+.. code-block:: python
+
+ self.env.user.notify_info('My information message', show_reload=True)
+
Installation
============
diff --git a/web_notify/__manifest__.py b/web_notify/__manifest__.py
index 858c3be99..c84ae279b 100644
--- a/web_notify/__manifest__.py
+++ b/web_notify/__manifest__.py
@@ -6,7 +6,7 @@
'name': 'Web Notify',
'summary': """
Send notification messages to user""",
- 'version': '10.0.1.0.0',
+ 'version': '10.0.1.1.0',
'description': 'Web Notify',
'license': 'AGPL-3',
'author': 'ACSONE SA/NV,Odoo Community Association (OCA)',
@@ -18,7 +18,8 @@
'data': [
'views/web_notify.xml'
],
- 'demo': [
+ 'qweb': [
+ 'static/src/xml/*.xml',
],
'installable': True,
}
diff --git a/web_notify/models/res_users.py b/web_notify/models/res_users.py
index 29f0eca17..30165f17d 100644
--- a/web_notify/models/res_users.py
+++ b/web_notify/models/res_users.py
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
# Copyright 2016 ACSONE SA/NV
+# Copyright 2018 Camptocamp
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import api, fields, models, _
@@ -23,23 +24,27 @@ class ResUsers(models.Model):
compute='_compute_channel_names')
@api.multi
- def notify_info(self, message, title=None, sticky=False):
+ def notify_info(self, message, title=None, sticky=False,
+ show_reload=False):
title = title or _('Information')
self._notify_channel(
- 'notify_info_channel_name', message, title, sticky)
+ 'notify_info_channel_name', message, title, sticky, show_reload)
@api.multi
- def notify_warning(self, message, title=None, sticky=False):
+ def notify_warning(self, message, title=None, sticky=False,
+ show_reload=False):
title = title or _('Warning')
self._notify_channel(
- 'notify_warning_channel_name', message, title, sticky)
+ 'notify_warning_channel_name', message, title, sticky, show_reload)
@api.multi
- def _notify_channel(self, channel_name_field, message, title, sticky):
+ def _notify_channel(self, channel_name_field, message, title, sticky,
+ show_reload):
bus_message = {
'message': message,
'title': title,
- 'sticky': sticky
+ 'sticky': sticky,
+ 'show_reload': show_reload,
}
notifications = [(getattr(record, channel_name_field), bus_message)
for record in self]
diff --git a/web_notify/static/src/css/notification.less b/web_notify/static/src/css/notification.less
new file mode 100644
index 000000000..1f1ee9a6e
--- /dev/null
+++ b/web_notify/static/src/css/notification.less
@@ -0,0 +1,5 @@
+.o_notification {
+ .o_notification_reload {
+ padding: 10px;
+ }
+}
diff --git a/web_notify/static/src/js/notification.js b/web_notify/static/src/js/notification.js
new file mode 100644
index 000000000..383b1d3e6
--- /dev/null
+++ b/web_notify/static/src/js/notification.js
@@ -0,0 +1,40 @@
+/* Copyright 2018 Camptocamp
+ * License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). */
+odoo.define('web_notify.notification', function (require) {
+ "use strict";
+
+ var base_notification = require('web.notification'),
+ WebClient = require('web.WebClient'),
+ Notification = base_notification.Notification,
+ Warning = base_notification.Warning;
+
+ Notification.include({
+ events: _.extend(
+ {},
+ Notification.prototype.events,
+ {'click .o_view_reload': function(e){
+ e.preventDefault();
+ this.reload_active_view();
+ }
+ }
+ ),
+ init: function(parent, title, text, sticky, options) {
+ this._super.apply(this, arguments);
+ this.options = options || {};
+ },
+ reload_active_view: function() {
+ this.trigger_up('reload_active_view');
+ },
+ });
+
+ base_notification.NotificationManager.include({
+ notify: function(title, text, sticky, options) {
+ return this.display(new Notification(this, title, text, sticky, options));
+ },
+ warn: function(title, text, sticky, options) {
+ return this.display(new Warning(this, title, text, sticky, options));
+ },
+
+ });
+
+});
diff --git a/web_notify/static/src/js/web_client.js b/web_notify/static/src/js/web_client.js
index 1ee99224c..6fceb35ba 100644
--- a/web_notify/static/src/js/web_client.js
+++ b/web_notify/static/src/js/web_client.js
@@ -1,13 +1,52 @@
odoo.define('web_notify.WebClient', function (require) {
"use strict";
-var WebClient = require('web.WebClient');
-var base_bus = require('bus.bus');
+var core = require('web.core'),
+ WebClient = require('web.WebClient'),
+ base_bus = require('bus.bus'),
+ Widget = require('web.Widget');
+
+
+Widget.include({
+ do_notify: function(title, message, sticky, options) {
+ this.trigger_up('notification', {title: title, message: message, sticky: sticky, options: options});
+ },
+ do_warn: function(title, message, sticky, options) {
+ this.trigger_up('warning', {title: title, message: message, sticky: sticky, options: options});
+ },
+});
+
WebClient.include({
+ custom_events: _.extend(
+ {},
+ WebClient.prototype.custom_events,
+ {reload_active_view: 'reload_active_view',
+ notification: function (e) {
+ if(this.notification_manager) {
+ this.notification_manager.notify(e.data.title, e.data.message, e.data.sticky, e.data.options);
+ }
+ },
+ warning: function (e) {
+ if(this.notification_manager) {
+ this.notification_manager.warn(e.data.title, e.data.message, e.data.sticky, e.data.options);
+ }
+ }
+ }
+ ),
init: function(parent, client_options){
this._super(parent, client_options);
},
+ reload_active_view: function(){
+ var action_manager = this.action_manager;
+ if(!action_manager){
+ return;
+ }
+ var active_view = action_manager.inner_widget.active_view;
+ if(active_view) {
+ active_view.controller.reload();
+ }
+ },
show_application: function() {
var res = this._super();
this.start_polling();
@@ -40,12 +79,12 @@ WebClient.include({
},
on_message_warning: function(message){
if(this.notification_manager) {
- this.notification_manager.do_warn(message.title, message.message, message.sticky);
+ this.notification_manager.do_warn(message.title, message.message, message.sticky, message);
}
},
on_message_info: function(message){
if(this.notification_manager) {
- this.notification_manager.do_notify(message.title, message.message, message.sticky);
+ this.notification_manager.do_notify(message.title, message.message, message.sticky, message);
}
}
});
diff --git a/web_notify/static/src/xml/notification.xml b/web_notify/static/src/xml/notification.xml
new file mode 100644
index 000000000..d73fb6f59
--- /dev/null
+++ b/web_notify/static/src/xml/notification.xml
@@ -0,0 +1,24 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/web_notify/views/web_notify.xml b/web_notify/views/web_notify.xml
index b85d2e6ff..4d0095950 100644
--- a/web_notify/views/web_notify.xml
+++ b/web_notify/views/web_notify.xml
@@ -3,7 +3,9 @@
+
+