Vulcan/client/views/notifications/notifications.js

35 lines
1,019 B
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){
return i18n.t('No notifications');
}else if(notifications.length==1){
return i18n.t('1 notification');
2012-10-04 17:25:10 +09:00
}else{
return notifications.length+' '+i18n.t('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(){
2013-03-14 09:45:57 +11:00
Meteor.call('markAllNotificationsAsRead',
function(error, result){
2013-03-14 09:45:57 +11:00
error && console.log(error);
}
2013-03-14 09:45:57 +11:00
);
2012-10-04 17:25:10 +09:00
}
2012-10-05 13:29:35 +09:00
})