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

37 lines
1 KiB
JavaScript
Raw Normal View History

2014-08-20 17:03:54 +09:00
Template[getTemplate('notificationsMenu')].helpers({
notifications: function(){
2015-03-22 12:27:05 +09:00
var notificationsCount;
var notifications=Herald.collection.find({userId: Meteor.userId(), read: false}, {sort: {timestamp: -1}}).fetch();
2014-08-20 17:03:54 +09:00
if(notifications.length==0){
2015-03-22 12:27:05 +09:00
notificationsCount = __('no_notifications');
2014-08-20 17:03:54 +09:00
}else if(notifications.length==1){
2015-03-22 12:27:05 +09:00
notificationsCount = __('1_notification');
2014-08-20 17:03:54 +09:00
}else{
2015-03-22 12:27:05 +09:00
notificationsCount = notifications.length+' '+__('notifications');
2014-08-20 17:03:54 +09:00
}
2015-03-22 12:27:05 +09:00
var markAllAsRead = [{
template: 'notificationsMarkAsRead'
}];
if (notifications.length) {
var dropdownItems = markAllAsRead.concat(_.map(notifications, function (notification) {
return {
template: "notificationItem",
data: notification
}
}));
} else {
var dropdownItems = [];
}
return {
dropdownName: 'notifications',
dropdownLabel: notificationsCount,
2015-03-23 10:32:56 +09:00
dropdownItems: dropdownItems,
dropdownClass: 'header-submodule'
2015-03-22 12:27:05 +09:00
}
2014-08-20 17:03:54 +09:00
}
2015-03-22 12:27:05 +09:00
});