Browse Source

Use new classes for the interactive notifications

pull/1029/head
Guewen Baconnier 6 years ago
committed by Yannick Vaucher
parent
commit
bf7fda1980
  1. 24
      web_notify/static/src/js/notification.js
  2. 36
      web_notify/static/src/js/web_client.js
  3. 4
      web_notify/static/src/xml/notification.xml

24
web_notify/static/src/js/notification.js

@ -8,7 +8,8 @@ odoo.define('web_notify.notification', function (require) {
Notification = base_notification.Notification, Notification = base_notification.Notification,
Warning = base_notification.Warning; Warning = base_notification.Warning;
Notification.include({
var InteractiveNotification = Notification.extend({
template: 'InteractiveNotification',
events: _.extend( events: _.extend(
{}, {},
Notification.prototype.events, Notification.prototype.events,
@ -23,7 +24,7 @@ odoo.define('web_notify.notification', function (require) {
} }
), ),
init: function(parent, title, text, sticky, options) { init: function(parent, title, text, sticky, options) {
this._super.apply(this, arguments);
this._super.apply(this, [parent, title, text, sticky]);
this.options = options || {}; this.options = options || {};
}, },
reload_active_view: function() { reload_active_view: function() {
@ -35,14 +36,23 @@ odoo.define('web_notify.notification', function (require) {
} }
}); });
var InteractiveWarning = InteractiveNotification.extend({
template: 'InteractiveWarning',
});
base_notification.NotificationManager.include({ 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));
interactive_notify(title, text, sticky, options) {
return this.display(new InteractiveNotification(this, title, text, sticky, options));
}, },
interactive_warn(title, text, sticky, options) {
return this.display(new InteractiveWarning(this, title, text, sticky, options));
}
}); });
return {
InteractiveNotification: InteractiveNotification,
InteractiveWarning: InteractiveWarning
};
}); });

36
web_notify/static/src/js/web_client.js

@ -8,11 +8,17 @@ var core = require('web.core'),
Widget.include({ Widget.include({
do_notify: function(title, message, sticky, options) {
this.trigger_up('notification', {title: title, message: message, sticky: sticky, options: options});
do_interactive_notify: function(title, message, sticky, options) {
this.trigger_up(
'interactive_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});
do_interactive_warn: function(title, message, sticky, options) {
this.trigger_up(
'interactive_warning',
{title: title, message: message,
sticky: sticky, options: options});
}, },
}); });
@ -22,14 +28,20 @@ WebClient.include({
{}, {},
WebClient.prototype.custom_events, WebClient.prototype.custom_events,
{reload_active_view: 'reload_active_view', {reload_active_view: 'reload_active_view',
notification: function (e) {
interactive_notification: function (e) {
if(this.notification_manager) { if(this.notification_manager) {
this.notification_manager.notify(e.data.title, e.data.message, e.data.sticky, e.data.options);
this.notification_manager.interactive_notify(
e.data.title, e.data.message,
e.data.sticky, e.data.options
);
} }
}, },
warning: function (e) {
interactive_warning: function (e) {
if(this.notification_manager) { if(this.notification_manager) {
this.notification_manager.warn(e.data.title, e.data.message, e.data.sticky, e.data.options);
this.notification_manager.interactive_warn(
e.data.title, e.data.message,
e.data.sticky, e.data.options
);
} }
} }
} }
@ -79,12 +91,16 @@ WebClient.include({
}, },
on_message_warning: function(message){ on_message_warning: function(message){
if(this.notification_manager) { if(this.notification_manager) {
this.notification_manager.do_warn(message.title, message.message, message.sticky, message);
this.notification_manager.do_interactive_warn(
message.title, message.message, message.sticky, message
);
} }
}, },
on_message_info: function(message){ on_message_info: function(message){
if(this.notification_manager) { if(this.notification_manager) {
this.notification_manager.do_notify(message.title, message.message, message.sticky, message);
this.notification_manager.do_interactive_notify(
message.title, message.message, message.sticky, message
);
} }
} }
}); });

4
web_notify/static/src/xml/notification.xml

@ -17,14 +17,14 @@
</div> </div>
</t> </t>
<t t-extend="Notification">
<t t-name="InteractiveNotification" t-extend="Notification">
<t t-jquery=".o_notification_content" t-operation="after"> <t t-jquery=".o_notification_content" t-operation="after">
<t t-call="Notification.reload"/> <t t-call="Notification.reload"/>
<t t-call="Notification.do_action"/> <t t-call="Notification.do_action"/>
</t> </t>
</t> </t>
<t t-extend="Warning">
<t t-name="InteractiveWarning" t-extend="Warning">
<t t-jquery=".o_notification_content" t-operation="after"> <t t-jquery=".o_notification_content" t-operation="after">
<t t-call="Notification.reload"/> <t t-call="Notification.reload"/>
<t t-call="Notification.do_action"/> <t t-call="Notification.do_action"/>

Loading…
Cancel
Save