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
},
2014-12-01 16:53:41 +09:00
notificationCount: 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){
2014-11-24 11:27:07 +09:00
return __('no_notifications');
2014-08-20 17:03:54 +09:00
}else if(notifications.length==1){
2014-11-24 11:27:07 +09:00
return __('1_notification');
2014-08-20 17:03:54 +09:00
}else{
2014-11-24 11:27:07 +09:00
return notifications.length+' '+__('notifications');
2014-08-20 17:03:54 +09:00
}
},
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(){
2014-12-01 16:53:41 +09:00
Meteor.call('heraldMarkAllAsRead',
2014-08-20 17:03:54 +09:00
function(error, result){
error && console.log(error);
}
);
}
2014-10-02 16:42:31 -04:00
});