Vulcan/client/views/notifications.js
2012-10-05 10:34:34 +09:00

29 lines
No EOL
902 B
JavaScript

Template.notifications.helpers({
notifications: function(){
return Notifications.find({userId: Meteor.user()._id}, {sort: {timestamp: -1}});
},
notification_count: function(){
var notifications=Notifications.find({userId: Meteor.user()._id, read: false}).fetch();
if(notifications.length==0){
return 'No notifications';
}else if(notifications.length==1){
return '1 notification';
}else{
return notifications.length+' notifications';
}
},
notification_class: function(){
var notifications=Notifications.find({userId: Meteor.user()._id, read: false}).fetch();
if(notifications.length==0)
return 'no-notifications';
}
});
Template.notifications.events({
'click .notifications-toggle': function(){
$('body').toggleClass('notifications-open');
},
'click .mark-as-read': function(){
Meteor.call('markAllNotificationsAsRead', Meteor.user());
}
})