Vulcan/packages/telescope-notifications/lib/client/templates/notifications_menu.js

41 lines
1.3 KiB
JavaScript
Raw Normal View History

2014-08-20 17:03:54 +09:00
Template[getTemplate('notificationsMenu')].helpers({
notificationItem: function () {
return getTemplate('notificationItem');
},
notifications: function(){
2014-10-02 16:42:31 -04:00
return Herald.collection.find({userId: Meteor.userId(), read: false}, {sort: {timestamp: -1}});
2014-08-20 17:03:54 +09:00
},
hasNotifications: function () {
2014-10-02 16:42:31 -04:00
return !!Herald.collection.find({userId: Meteor.userId(), read: false}, {sort: {timestamp: -1}}).count();
2014-08-20 17:03:54 +09:00
},
notification_count: function(){
2014-10-02 16:42:31 -04:00
var notifications=Herald.collection.find({userId: Meteor.userId(), read: false}).fetch();
2014-08-20 17:03:54 +09:00
if(notifications.length==0){
return i18n.t('No notifications');
}else if(notifications.length==1){
return i18n.t('1 notification');
}else{
return notifications.length+' '+i18n.t('notifications');
}
},
notification_class: function(){
2014-10-02 16:42:31 -04:00
var notifications=Herald.collection.find({userId: Meteor.userId(), read: false}).fetch();
2014-08-20 17:03:54 +09:00
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);
}
);
}
2014-10-02 16:42:31 -04:00
});