diff options
| author | Christophe Matthieu <chm@odoo.com> | 2018-03-29 17:46:24 +0200 |
|---|---|---|
| committer | Géry Debongnie <ged@odoo.com> | 2018-04-19 17:17:54 +0200 |
| commit | 07cd24b1ecf3ab8edd3fffbf2fcd3a3e685f357c (patch) | |
| tree | 3fc6a94ed00c2501e83a102f07438ea87097fca8 /addons/web/static/src/js/chrome/abstract_web_client.js | |
| parent | 67a7d1f2b5ec1cdc2fa6677a359fc6cf10f02b85 (diff) | |
[IMP] web: convert notification popup in service and add buttons params
this.call('web.Notification', 'notify', params)
Display a notification at the appropriate location, and returns the
reference id to the same widget. Note that this method does not wait
for the appendTo method to complete.
@param {Object} params
@param {string} params.title notification title
@param {string} params.message notification main message
@param {string} params.type 'notification' or 'warning'
@param {boolean} [params.sticky=false] if true, the notification will stay
visible until the user clicks on it.
@param {string} [params.className] className to add on the dom
@param {function} [params.onClose] callback when the user click on the x
or when the notification is auto close (no sticky)
@param {Array<Object>} params.buttons
@param {function} params.buttons[0].click callback on click
@param {Boolean} [params.buttons[0].primary] display the button as primary
@param {string} [params.buttons[0].text] button label
@param {string} [params.buttons[0].icon] font-awsome className or image src
@returns {Number} notification id
this.call('web.Notification', 'close', notificationId)
Diffstat (limited to 'addons/web/static/src/js/chrome/abstract_web_client.js')
| -rw-r--r-- | addons/web/static/src/js/chrome/abstract_web_client.js | 72 |
1 files changed, 35 insertions, 37 deletions
diff --git a/addons/web/static/src/js/chrome/abstract_web_client.js b/addons/web/static/src/js/chrome/abstract_web_client.js index 3492af748f5..612d04c577a 100644 --- a/addons/web/static/src/js/chrome/abstract_web_client.js +++ b/addons/web/static/src/js/chrome/abstract_web_client.js @@ -21,7 +21,6 @@ var Dialog = require('web.Dialog'); var dom = require('web.dom'); var KeyboardNavigationMixin = require('web.KeyboardNavigationMixin'); var Loading = require('web.Loading'); -var NotificationManager = require('web.NotificationManager'); var RainbowMan = require('web.RainbowMan'); var ServiceProviderMixin = require('web.ServiceProviderMixin'); var session = require('web.session'); @@ -31,6 +30,7 @@ var _t = core._t; var qweb = core.qweb; var AbstractWebClient = Widget.extend(ServiceProviderMixin, KeyboardNavigationMixin, { + dependencies: ['notification'], events: _.extend(KeyboardNavigationMixin.events, {}), custom_events: { clear_uncommitted_changes: function (e) { @@ -46,13 +46,6 @@ var AbstractWebClient = Widget.extend(ServiceProviderMixin, KeyboardNavigationMi // the next events are dedicated to generic services required by // downstream widgets. Mainly side effects, such as rpcs, notifications // or cache. - - // notifications, warnings and effects - notification: function (e) { - if (this.notification_manager) { - this.notification_manager.notify(e.data.title, e.data.message, e.data.sticky); - } - }, warning: '_onDisplayWarning', load_action: '_onLoadAction', load_views: function (event) { @@ -120,7 +113,6 @@ var AbstractWebClient = Widget.extend(ServiceProviderMixin, KeyboardNavigationMi self.bind_events(); return $.when( self.set_action_manager(), - self.set_notification_manager(), self.set_loading() ); }).then(function () { @@ -174,8 +166,8 @@ var AbstractWebClient = Widget.extend(ServiceProviderMixin, KeyboardNavigationMi } this._hideAccessKeyOverlay(); }); - core.bus.on('connection_lost', this, this.on_connection_lost); - core.bus.on('connection_restored', this, this.on_connection_restored); + core.bus.on('connection_lost', this, this._onConnectionLost); + core.bus.on('connection_restored', this, this._onConnectionRestored); // crash manager integration session.on('error', crash_manager, crash_manager.rpc_error); @@ -222,10 +214,6 @@ var AbstractWebClient = Widget.extend(ServiceProviderMixin, KeyboardNavigationMi }); }); }, - set_notification_manager: function () { - this.notification_manager = new NotificationManager(this); - return this.notification_manager.appendTo(this.$el); - }, set_loading: function () { this.loading = new Loading(this); return this.loading.appendTo(this.$el); @@ -309,24 +297,6 @@ var AbstractWebClient = Widget.extend(ServiceProviderMixin, KeyboardNavigationMi // -------------------------------------------------------------- // Connection notifications // -------------------------------------------------------------- - on_connection_lost: function () { - this.connection_notification = this.notification_manager.notify( - _t('Connection lost'), - _t('Trying to reconnect...'), - true - ); - }, - on_connection_restored: function () { - if (this.connection_notification) { - this.connection_notification.destroy(); - this.notification_manager.notify( - _t('Connection restored'), - _t('You are back online'), - false - ); - this.connection_notification = false; - } - }, /** * Handler to be overridden, called each time the UI is updated by the * ActionManager. @@ -348,6 +318,34 @@ var AbstractWebClient = Widget.extend(ServiceProviderMixin, KeyboardNavigationMi //-------------------------------------------------------------------------- /** + * Whenever the connection is lost, we need to notify the user. + * + * @private + */ + _onConnectionLost: function () { + this.connectionNotificationID = this.call('notification', 'notify', { + title: _t('Connection lost'), + message: _t('Trying to reconnect...'), + sticky: true + }); + }, + /** + * Whenever the connection is restored, we need to notify the user. + * + * @private + */ + _onConnectionRestored: function () { + if (this.connectionNotificationID) { + this.call('notification', 'close', this.connectionNotificationID); + this.call('notification', 'notify', { + title: _t('Connection restored'), + message: _t('You are back online'), + sticky: false + }); + this.connectionNotificationID = false; + } + }, + /** * @private * @param {OdooEvent} e * @param {Object} e.data.filter the filter description @@ -360,7 +358,7 @@ var AbstractWebClient = Widget.extend(ServiceProviderMixin, KeyboardNavigationMi .then(e.data.on_success); }, /** - * Displays a warning in a dialog of with the NotificationManager + * Displays a warning in a dialog or with the notification service * * @private * @param {OdooEvent} e @@ -368,7 +366,7 @@ var AbstractWebClient = Widget.extend(ServiceProviderMixin, KeyboardNavigationMi * @param {string} e.data.title the warning's title * @param {string} [e.data.type] 'dialog' to display in a dialog * @param {boolean} [e.data.sticky] whether or not the warning should be - * sticky (if displayed with the NotificationManager) + * sticky (if displayed with the Notification) */ _onDisplayWarning: function (e) { var data = e.data; @@ -378,8 +376,8 @@ var AbstractWebClient = Widget.extend(ServiceProviderMixin, KeyboardNavigationMi title: data.title, $content: qweb.render("CrashManager.warning", data), }).open(); - } else if (this.notification_manager) { - this.notification_manager.warn(e.data.title, e.data.message, e.data.sticky); + } else { + this.call('notification', 'notify', e.data); } }, /** |
