Vulcan/packages/telescope-notifications/lib/client/templates/notifications_menu.js
2014-11-24 11:27:07 +09:00

40 lines
1.3 KiB
JavaScript

Template[getTemplate('notificationsMenu')].helpers({
notificationItem: function () {
return getTemplate('notificationItem');
},
notifications: function(){
return Herald.collection.find({userId: Meteor.userId(), read: false}, {sort: {timestamp: -1}});
},
hasNotifications: function () {
return !!Herald.collection.find({userId: Meteor.userId(), read: false}, {sort: {timestamp: -1}}).count();
},
notification_count: function(){
var notifications=Herald.collection.find({userId: Meteor.userId(), 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=Herald.collection.find({userId: Meteor.userId(), read: false}).fetch();
if(notifications.length==0)
return 'no-notifications';
}
});
Template[getTemplate('notificationsMenu')].events({
'click .notifications-toggle': function(e){
e.preventDefault();
$('body').toggleClass('notifications-open');
},
'click .mark-as-read': function(){
Meteor.call('markAllNotificationsAsRead',
function(error, result){
error && console.log(error);
}
);
}
});