Permalink
Browse files

[FIX] calendar: notifications may appear

Following the transformation into notification service, performed by
commit 07cd24b, calendar has been
forgotten.
  • Loading branch information...
Gorash committed Oct 10, 2018
1 parent f9a16f7 commit 4aec0b7740bd57249d504616345ece90fb31c524
@@ -57,24 +57,22 @@ WebClient.include({
// Clear previously set timeouts and destroy currently displayed calendar notifications
clearTimeout(this.get_next_calendar_notif_timeout);
_.each(this.calendar_notif_timeouts, clearTimeout);
_.each(this.calendar_notif, function(notif) {
if (!notif.isDestroyed()) {
notif.destroy();
}
_.each(this.calendar_notif, function (notificationID) {
self.call('notification', 'close', notificationID, true);
});
this.calendar_notif_timeouts = {};
this.calendar_notif = {};
// For each notification, set a timeout to display it
_.each(notifications, function(notif) {
self.calendar_notif_timeouts[notif.event_id] = setTimeout(function() {
var notification = new CalendarNotification(self.notification_manager, {
var notificationID = self.call('notification', 'notify', {
Notification: CalendarNotification,
title: notif.title,
text: notif.message,
eventID: notif.event_id,
});
self.notification_manager.display(notification);
self.calendar_notif[notif.event_id] = notification;
self.calendar_notif[notif.event_id] = notificationID;
}, notif.timer * 1000);
last_notif_timer = Math.max(last_notif_timer, notif.timer);
});
@@ -56,6 +56,8 @@ var NotificationService = AbstractService.extend({
* Note that this method does not wait for the appendTo method to complete.
*
* @param {Object} params
* @param {function} [params.Notification] javascript class of a notification
* to instantiate by default use 'web.Notification'
* @param {string} params.title notification title
* @param {string} params.message notification main message
* @param {string} params.type 'notification' or 'warning'
@@ -76,7 +78,8 @@ var NotificationService = AbstractService.extend({
this.$el = $('<div class="o_notification_manager"/>');
this.$el.prependTo('body');
}
var notification = this.notifications[++id] = new Notification(this, params);
var NotificationWidget = params.Notification || Notification;
var notification = this.notifications[++id] = new NotificationWidget(this, params);
notification.appendTo(this.$el);
return id;
},
@@ -244,4 +244,38 @@ QUnit.module('Services', {
});
});
QUnit.test('Display a custom notification', function (assert) {
var done = assert.async();
assert.expect(3);
var Custom = Notification.extend({
init: function (parent, params) {
this._super.apply(this, arguments);
assert.ok(params.customParams, 'instantiate custom notification');
},
start: function () {
var self = this;
return this._super().then(function () {
self.$el.html('Custom');
});
},
});
var view = createView(this.viewParams);
view.call('notification', 'notify', {
Notification: Custom,
customParams: true,
});
assert.strictEqual(
$('body .o_notification_manager .o_notification:contains(Custom)').length, 1,
"should display the notification");
view.destroy();
setTimeout(function () {
assert.strictEqual(
$('body .o_notification_manager .o_notification').length, 0,
"should destroy the notification");
done();
});
});
});});

0 comments on commit 4aec0b7

Please sign in to comment.