2014-07-05 11:24:28 +09:00
|
|
|
Template[getTemplate('notifications')].helpers({
|
2012-10-04 11:17:57 +10:00
|
|
|
notifications: function(){
|
2013-01-14 10:54:58 +09:00
|
|
|
return Notifications.find({userId: Meteor.userId()}, {sort: {timestamp: -1}});
|
2012-10-04 17:25:10 +09:00
|
|
|
},
|
|
|
|
notification_count: function(){
|
2013-01-14 10:54:58 +09:00
|
|
|
var notifications=Notifications.find({userId: Meteor.userId(), read: false}).fetch();
|
2012-10-05 10:23:38 +09:00
|
|
|
if(notifications.length==0){
|
2013-11-06 01:01:56 +01:00
|
|
|
return i18n.t('No notifications');
|
2012-10-05 10:23:38 +09:00
|
|
|
}else if(notifications.length==1){
|
2013-11-06 01:01:56 +01:00
|
|
|
return i18n.t('1 notification');
|
2012-10-04 17:25:10 +09:00
|
|
|
}else{
|
2013-11-06 01:01:56 +01:00
|
|
|
return notifications.length+' '+i18n.t('notifications');
|
2012-10-04 17:25:10 +09:00
|
|
|
}
|
|
|
|
},
|
|
|
|
notification_class: function(){
|
2013-01-14 10:54:58 +09:00
|
|
|
var notifications=Notifications.find({userId: Meteor.userId(), read: false}).fetch();
|
2012-10-05 10:23:38 +09:00
|
|
|
if(notifications.length==0)
|
2012-10-05 13:59:40 +09:00
|
|
|
return 'no-notifications';
|
2012-10-04 11:17:57 +10:00
|
|
|
}
|
2012-10-04 17:25:10 +09:00
|
|
|
});
|
|
|
|
|
2014-07-05 11:24:28 +09:00
|
|
|
Template[getTemplate('notifications')].events({
|
2012-10-05 10:44:29 +09:00
|
|
|
'click .notifications-toggle': function(e){
|
|
|
|
e.preventDefault();
|
2012-10-04 17:25:10 +09:00
|
|
|
$('body').toggleClass('notifications-open');
|
|
|
|
},
|
2012-10-05 10:23:38 +09:00
|
|
|
'click .mark-as-read': function(){
|
2013-03-14 09:45:57 +11:00
|
|
|
Meteor.call('markAllNotificationsAsRead',
|
2012-10-08 11:23:12 +09:00
|
|
|
function(error, result){
|
2013-03-14 09:45:57 +11:00
|
|
|
error && console.log(error);
|
2012-10-08 11:23:12 +09:00
|
|
|
}
|
2013-03-14 09:45:57 +11:00
|
|
|
);
|
2012-10-04 17:25:10 +09:00
|
|
|
}
|
2012-10-05 13:29:35 +09:00
|
|
|
})
|