diff --git a/web_notify/README.rst b/web_notify/README.rst new file mode 100644 index 000000000..9bd748aaf --- /dev/null +++ b/web_notify/README.rst @@ -0,0 +1,77 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 + +========== +Web Notify +========== + +Send instant notification messages to the user in live. + +This technical module allows you to send instant notification messages from the server to the user in live. +Two kinds of notification are supported. + +* Warning: Displayed in a red flying popup div +* Information: Displayed in a light yellow flying popup div + +To send a notification to the user you just need to call one of the new methods defined on res.users: + +.. code-block:: python + + self.env.user.notify_info('My information message') + +or + +.. code-block:: python + + self.env.user.notify_warning('My marning message') + + +Installation +============ + +This module is based on the Instant Messaging Bus. To work properly, the server must be launched in gevent mode. + + +Usage +===== + +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/162/9.0 + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues +`_. In case of trouble, please +check there if your issue has already been reported. If you spotted it first, +help us smashing it by providing a detailed and welcomed feedback. + +Credits +======= + +Images +------ + +* Odoo Community Association: `Icon `_. + +Contributors +------------ + +* Laurent Mignon + +Maintainer +---------- + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +This module is maintained by the OCA. + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +To contribute to this module, please visit https://odoo-community.org. diff --git a/web_notify/__init__.py b/web_notify/__init__.py new file mode 100644 index 000000000..0650744f6 --- /dev/null +++ b/web_notify/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/web_notify/__openerp__.py b/web_notify/__openerp__.py new file mode 100644 index 000000000..a6e542eb5 --- /dev/null +++ b/web_notify/__openerp__.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +# Copyright 2016 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + 'name': 'Web Notify', + 'summary': """ + Send notification messages to user""", + 'version': '9.0.1.0.0', + 'license': 'AGPL-3', + 'author': 'ACSONE SA/NV,Odoo Community Association (OCA)', + 'website': 'https://acsone.eu/', + 'depends': [ + 'web', + 'bus', + ], + 'data': [ + 'views/web_notify.xml' + ], + 'demo': [ + ], +} diff --git a/web_notify/models/__init__.py b/web_notify/models/__init__.py new file mode 100644 index 000000000..883516533 --- /dev/null +++ b/web_notify/models/__init__.py @@ -0,0 +1 @@ +from . import res_users diff --git a/web_notify/models/res_users.py b/web_notify/models/res_users.py new file mode 100644 index 000000000..800380d20 --- /dev/null +++ b/web_notify/models/res_users.py @@ -0,0 +1,32 @@ +# -*- coding: utf-8 -*- +# Copyright 2016 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from openerp import api, models, _ + + +class ResUsers(models.Model): + + _inherit = 'res.users' + + @api.multi + def notify_info(self, message, title=None, sticky=False): + title = title or _('Information') + self._notify_channel('notify_info', message, title, sticky) + + @api.multi + def notify_warning(self, message, title=None, sticky=False): + title = title or _('Warning') + self._notify_channel('notify_warning', message, title, sticky) + + @api.multi + def _notify_channel(self, channel_name_prefix, message, title, sticky): + notification = { + 'message': message, + 'title': title, + 'sticky': sticky + } + bus_bus = self.env['bus.bus'] + for record in self: + channel_name = channel_name_prefix + "_%s" % record.id + bus_bus.sendone(channel_name, notification) diff --git a/web_notify/static/description/icon.png b/web_notify/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/web_notify/static/description/icon.png differ diff --git a/web_notify/static/src/js/web_client.js b/web_notify/static/src/js/web_client.js new file mode 100644 index 000000000..3c908a074 --- /dev/null +++ b/web_notify/static/src/js/web_client.js @@ -0,0 +1,53 @@ +odoo.define('web_notify.WebClient', function (require) { +"use strict"; + +var WebClient = require('web.WebClient'); +var base_bus = require('bus.bus'); +var _ = require('_'); + +WebClient.include({ + init: function(parent, client_options){ + this._super(parent, client_options); + }, + show_application: function() { + this._super(); + this.start_polling(); + }, + on_logout: function() { + var self = this; + base_bus.bus.off('notification', this, this.bus_notification); + this._super(); + }, + start_polling: function() { + this.channel_warning = 'notify_warning_' + this.session.uid; + this.channel_info = 'notify_info_' + this.session.uid; + base_bus.bus.add_channel(this.channel_warning); + base_bus.bus.add_channel(this.channel_info); + base_bus.bus.on('notification', this, this.bus_notification); + base_bus.bus.start_polling(); + }, + bus_notification: function(notifications) { + var self = this; + _.each(notifications, function (notification) { + var channel = notification[0]; + var message = notification[1]; + if (channel === self.channel_warning) { + self.on_message_warning(message); + } else if (channel == self.channel_info) { + self.on_message_info(message); + } + }); + }, + on_message_warning: function(message){ + if(this.notification_manager) { + this.notification_manager.do_warn(message.title, message.message, message.sticky); + } + }, + on_message_info: function(message){ + if(this.notification_manager) { + this.notification_manager.do_notify(message.title, message.message, message.sticky); + } + } +}); + +}); \ No newline at end of file diff --git a/web_notify/views/web_notify.xml b/web_notify/views/web_notify.xml new file mode 100644 index 000000000..b85d2e6ff --- /dev/null +++ b/web_notify/views/web_notify.xml @@ -0,0 +1,10 @@ + + + +