Vulcan/client/views/notifications.js

30 lines
927 B
JavaScript
Raw Normal View History

2012-10-04 11:17:57 +10:00
Template.notifications.helpers({
notifications: function(){
return Notifications.find({userId: Meteor.user()._id}, {sort: {timestamp: -1}});
2012-10-04 17:25:10 +09:00
},
notification_count: function(){
var notifications=Notifications.find({userId: Meteor.user()._id, read: false}).fetch();
if(notifications.length==0){
2012-10-04 17:25:10 +09:00
return 'No notifications';
}else if(notifications.length==1){
2012-10-04 17:25:10 +09:00
return '1 notification';
}else{
return notifications.length+' notifications';
2012-10-04 17:25:10 +09:00
}
},
notification_class: function(){
var notifications=Notifications.find({userId: Meteor.user()._id, read: false}).fetch();
if(notifications.length==0)
2012-10-04 17:25:10 +09:00
return 'no-notifications';
2012-10-04 11:17:57 +10:00
}
2012-10-04 17:25:10 +09:00
});
Template.notifications.events({
2012-10-05 10:44:29 +09:00
'click .notifications-toggle': function(e){
e.preventDefault();
2012-10-04 17:25:10 +09:00
$('body').toggleClass('notifications-open');
},
'click .mark-as-read': function(){
Meteor.call('markAllNotificationsAsRead', Meteor.user());
2012-10-04 17:25:10 +09:00
}
})