Vulcan/client/views/notifications/notifications.js

44 lines
1.1 KiB
JavaScript
Raw Normal View History

2012-10-04 11:17:57 +10:00
Template.notifications.helpers({
notifications: function(){
2013-01-14 10:54:58 +09:00
return Notifications.find({userId: Meteor.userId()}, {sort: {timestamp: -1}});
2012-10-04 17:25:10 +09:00
},
notification_count: function(){
2013-01-14 10:54:58 +09:00
var notifications=Notifications.find({userId: Meteor.userId(), 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(){
2013-01-14 10:54:58 +09:00
var notifications=Notifications.find({userId: Meteor.userId(), read: false}).fetch();
if(notifications.length==0)
2012-10-05 13:59:40 +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(){
Notifications.update(
2013-01-14 10:54:58 +09:00
{userId: Meteor.userId()},
{
$set:{
read: true
}
},
{multi: true},
function(error, result){
if(error){
console.log(error);
}
}
);
2012-10-04 17:25:10 +09:00
}
2012-10-05 13:29:35 +09:00
})