summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/widgets/notification.js
diff options
context:
space:
mode:
authorqsm-odoo <qsm@odoo.com>2015-07-22 15:37:13 +0200
committerqsm-odoo <qsm@odoo.com>2015-07-23 10:51:12 +0200
commit86c399f3bde4efb271677914bc9f2721d77a681b (patch)
tree775660ba56c564478d9d9b93c307c498db7d4967 /addons/web/static/src/js/widgets/notification.js
parent84197b51eeacb7228ea05eef946eba3f6f9725b2 (diff)
[IMP] web: New notification system
Backport of the Notification system
Diffstat (limited to 'addons/web/static/src/js/widgets/notification.js')
-rw-r--r--addons/web/static/src/js/widgets/notification.js79
1 files changed, 54 insertions, 25 deletions
diff --git a/addons/web/static/src/js/widgets/notification.js b/addons/web/static/src/js/widgets/notification.js
index d9376155787..314034ef748 100644
--- a/addons/web/static/src/js/widgets/notification.js
+++ b/addons/web/static/src/js/widgets/notification.js
@@ -1,44 +1,73 @@
-odoo.define('web.Notification', function (require) {
+odoo.define('web.notification', function (require) {
"use strict";
+var core = require('web.core');
var Widget = require('web.Widget');
+var _t = core._t;
var Notification = Widget.extend({
template: 'Notification',
- init: function() {
+ events: {
+ 'click .o_close': function(e) {
+ e.preventDefault();
+ this.destroy(true);
+ }
+ },
+ init: function(parent, title, text, sticky) {
this._super.apply(this, arguments);
+ this.title = title;
+ this.text = text;
+ this.sticky = !!sticky;
},
start: function() {
this._super.apply(this, arguments);
- this.$el.notify({
- speed: 500,
- expires: 2500
+
+ var self = this;
+ this.$el.animate({opacity: 1.0}, 400, "swing", function() {
+ if(!self.sticky) {
+ setTimeout(function() {
+ self.destroy(true);
+ }, 2500);
+ }
});
},
- notify: function(title, text, sticky) {
- sticky = !!sticky;
- var opts = {};
- if (sticky) {
- opts.expires = false;
+ destroy: function(animate) {
+ if(!animate) {
+ return this._super.apply(this, arguments);
}
- return this.$el.notify('create', {
- title: title,
- text: text
- }, opts);
+
+ var self = this,
+ superDestroy = this._super;
+ this.$el.animate({opacity: 0.0}, 400, "swing", function() {
+ self.$el.animate({height: 0}, 400, "swing", function() {
+ superDestroy.call(self);
+ });
+ });
+ },
+});
+
+var Warning = Notification.extend({
+ template: 'Warning',
+});
+
+var NotificationManager = Widget.extend({
+ className: 'o_notification_manager',
+
+ display: function(notification) {
+ return notification.appendTo(this.$el);
+ },
+ notify: function(title, text, sticky) {
+ return this.display(new Notification(this, title, text, sticky));
},
warn: function(title, text, sticky) {
- sticky = !!sticky;
- var opts = {};
- if (sticky) {
- opts.expires = false;
- }
- return this.$el.notify('create', 'oe_notification_alert', {
- title: title,
- text: text
- }, opts);
- }
+ return this.display(new Warning(this, title, text, sticky));
+ },
});
-return Notification;
+return {
+ Notification: Notification,
+ Warning: Warning,
+ NotificationManager: NotificationManager,
+};
});