-
Notifications
You must be signed in to change notification settings - Fork 0
/
flash-notifications.js
46 lines (37 loc) · 1.12 KB
/
flash-notifications.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/* global FlashNotifications:true, FlashNotificationCollection:true */
FlashNotificationCollection = function() {
Meteor.Collection.call(this, null);
};
FlashNotificationCollection.prototype = new Meteor.Collection(null);
FlashNotificationCollection.prototype.add = function(data) {
var self = this;
// defaults
data.pinned = !!data.pinned;
data.timeout = data.timeout || 3000;
// Figure out a pattern for validating enums like feeling
check(data, {
title: String,
description: String,
// One of: "negative", "positive", "neutral'
feeling: String,
icon: String,
pinned: Boolean,
timeout: Number,
// not sure if this is the right way to do it or use a template or
// html string??
actionLink: Match.Optional({
text: String,
classes: Match.Optional(String),
href: Match.Optional(String),
onclick: Match.Optional(Function)
})
});
var res = this.upsert(data, data);
if (!data.pinned) {
Meteor.setTimeout(function() {
self.remove(res.insertedId);
}, data.timeout);
}
return res;
};
FlashNotifications = new FlashNotificationCollection();