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

42 lines
1.2 KiB
JavaScript
Raw Normal View History

2014-08-20 17:03:54 +09:00
Template[getTemplate('notificationsMenu')].helpers({
2015-03-28 10:54:41 +09:00
menuLabel: 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-28 10:54:41 +09:00
return notificationsCount;
},
menuItems: function () {
var notifications=Herald.collection.find({userId: Meteor.userId(), read: false}, {sort: {timestamp: -1}}).fetch();
2015-03-22 12:27:05 +09:00
var markAllAsRead = [{
template: 'notificationsMarkAsRead'
}];
if (notifications.length) {
2015-03-28 10:54:41 +09:00
var menuItems = markAllAsRead.concat(_.map(notifications, function (notification) {
2015-03-22 12:27:05 +09:00
return {
template: "notificationItem",
data: notification
}
}));
} else {
2015-03-28 10:54:41 +09:00
var menuItems = [];
2015-03-22 12:27:05 +09:00
}
2015-03-28 10:54:41 +09:00
return menuItems;
},
menuMode: function () {
if (!!this.mobile) {
return 'list';
} else if (getSetting('navLayout', 'top-nav') === 'top-nav') {
return 'dropdown';
} else {
return 'accordion';
}
2014-08-20 17:03:54 +09:00
}
2015-03-22 12:27:05 +09:00
});