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

46 lines
1.3 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
2015-03-24 17:03:37 +09:00
if (!!this.mobile) {
var dropdownMode = 'list';
} else if (getSetting('navLayout', 'top-nav') === 'top-nav') {
var dropdownMode = 'hover';
} else {
var dropdownMode = 'accordion';
}
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,
2015-03-23 11:28:36 +09:00
dropdownClass: 'header-submodule',
2015-03-24 17:03:37 +09:00
dropdownMode: dropdownMode
2015-03-22 12:27:05 +09:00
}
2014-08-20 17:03:54 +09:00
}
2015-03-22 12:27:05 +09:00
});