2015-07-14 12:57:40 +09:00
|
|
|
var getNotifications = function () {
|
|
|
|
return Herald.collection.find({userId: Meteor.userId(), read: false}, {sort: {timestamp: -1}}).fetch();
|
|
|
|
};
|
|
|
|
|
2015-05-18 10:12:48 +09:00
|
|
|
Template.notifications_menu.helpers({
|
2015-07-14 12:57:40 +09:00
|
|
|
hasNotifications: function () {
|
|
|
|
var notifications = getNotifications();
|
|
|
|
return notifications.length;
|
|
|
|
},
|
2015-04-22 07:50:11 +09:00
|
|
|
menuLabel: function () {
|
|
|
|
var notificationsCount;
|
2015-07-14 12:57:40 +09:00
|
|
|
var notifications = getNotifications();
|
2015-04-22 07:50:11 +09:00
|
|
|
|
2015-05-01 18:22:00 +02:00
|
|
|
if(notifications.length === 0){
|
2015-09-23 10:23:39 +09:00
|
|
|
notificationsCount = i18n.t('no_notifications');
|
2015-05-01 18:22:00 +02:00
|
|
|
}else if(notifications.length === 1){
|
2015-09-23 10:23:39 +09:00
|
|
|
notificationsCount = i18n.t('1_notification');
|
2015-04-22 07:50:11 +09:00
|
|
|
}else{
|
2015-09-23 10:23:39 +09:00
|
|
|
notificationsCount = notifications.length+' '+ i18n.t('notifications');
|
2015-04-22 07:50:11 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
return notificationsCount;
|
|
|
|
},
|
|
|
|
menuItems: function () {
|
2015-07-14 12:57:40 +09:00
|
|
|
var notifications = getNotifications();
|
2015-04-22 07:50:11 +09:00
|
|
|
var markAllAsRead = [{
|
2015-05-18 10:12:48 +09:00
|
|
|
template: 'notifications_mark_as_read'
|
2015-04-22 07:50:11 +09:00
|
|
|
}];
|
2015-05-01 18:22:00 +02:00
|
|
|
var menuItems;
|
2015-04-22 07:50:11 +09:00
|
|
|
if (notifications.length) {
|
2015-05-01 18:22:00 +02:00
|
|
|
menuItems = markAllAsRead.concat(_.map(notifications, function (notification) {
|
2015-04-22 07:50:11 +09:00
|
|
|
return {
|
2015-05-18 10:12:48 +09:00
|
|
|
template: "notification_item",
|
2015-04-22 07:50:11 +09:00
|
|
|
data: notification
|
2015-05-01 18:22:00 +02:00
|
|
|
};
|
2015-04-22 07:50:11 +09:00
|
|
|
}));
|
|
|
|
} else {
|
2015-05-01 18:22:00 +02:00
|
|
|
menuItems = [];
|
2015-04-22 07:50:11 +09:00
|
|
|
}
|
|
|
|
return menuItems;
|
|
|
|
},
|
2015-10-19 10:39:57 +09:00
|
|
|
menuType: function () {
|
2015-10-08 11:13:48 +09:00
|
|
|
if (this.zone === "mobileNav") {
|
2015-10-19 10:39:57 +09:00
|
|
|
return 'collapsible';
|
2015-04-22 07:50:11 +09:00
|
|
|
} else if (Settings.get('navLayout', 'top-nav') === 'top-nav') {
|
2015-10-19 10:39:57 +09:00
|
|
|
return 'dropdown';
|
2015-04-22 07:50:11 +09:00
|
|
|
} else {
|
2015-10-19 10:39:57 +09:00
|
|
|
return 'collapsible';
|
2015-04-22 07:50:11 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|