[Notifications] Extract autoDismiss logic

This commit is contained in:
Alex M
2016-10-08 22:51:01 +03:00
parent 9456370077
commit d1d2067ad5

View File

@@ -332,21 +332,7 @@ define(
onDismiss: function (callback) { onDismiss: function (callback) {
topic.listen(callback); topic.listen(callback);
}, }
autoDismiss: (function () {
if (notificationModel.severity === "info") {
return true;
}
return notificationModel.autoDismiss;
})(),
autoDismissTimeout: (function () {
if (typeof notificationModel.autoDismiss === "number") {
return notificationModel.autoDismiss;
}
return self.AUTO_DISMISS_TIMEOUT;
})()
}; };
//Notifications support a 'dismissable' attribute. This is a //Notifications support a 'dismissable' attribute. This is a
@@ -398,23 +384,33 @@ define(
* @private * @private
*/ */
NotificationService.prototype.setActiveNotification = function (notification) { NotificationService.prototype.setActiveNotification = function (notification) {
var timeout; var timeout;
this.active.notification = notification; var shouldAutoDismiss;
var usesCustomTimeout;
this.active.notification = notification;
/* if (!notification) {
If autoDismiss has been specified, OR there are other delete this.active.timeout;
notifications queued for display, setup a timeout to return;
dismiss the dialog. }
*/
if (notification && (notification.autoDismiss || this.selectNextNotification())) { usesCustomTimeout = typeof notification.model.autoDismiss === "number";
timeout = notification.autoDismissTimeout || this.AUTO_DISMISS_TIMEOUT;
this.active.timeout = this.$timeout(function () { if (notification.model.severity === "info" || usesCustomTimeout) {
notification.dismissOrMinimize(); shouldAutoDismiss = true;
}, timeout); } else {
} else { shouldAutoDismiss = notification.model.autoDismiss;
delete this.active.timeout; }
}
}; if (shouldAutoDismiss || this.selectNextNotification()) {
timeout = usesCustomTimeout ? notification.model.autoDismiss : this.AUTO_DISMISS_TIMEOUT;
this.active.timeout = this.$timeout(function () {
notification.dismissOrMinimize();
}, timeout);
} else {
delete this.active.timeout;
}
};
/** /**
* Used internally by the NotificationService * Used internally by the NotificationService