Files
dss.web/client/app/directives/notifications/notifications.directive.js
Fergal Moran d2c529bafe Screw you git!
2015-12-01 19:50:20 +00:00

46 lines
1.8 KiB
JavaScript

'use strict';
angular.module('dssWebApp')
.directive('dssNotifications', function ($timeout, NotificationModel) {
var markNotifications = function (scope) {
scope.notifications.forEach(function (notification) {
if (notification.accepted_date === null) {
console.log(notification.id);
notification.accepted_date = new Date();
NotificationModel.save(notification);
scope.notificationCount--;
}
});
};
return {
restrict: 'E',
templateUrl: 'app/directives/notifications/notifications.html',
replace: true,
link: function (scope, elem, attrs) {
scope.notifications = [];
NotificationModel.findAll().then(function (results) {
scope.notifications = results;
scope.notificationCount = results.filter(function (x) {
return x.accepted_date === null;
}).length;
});
$('#notifications').data('open', false);
$('#notifications-button').click(function() {
if($('#notifications').data('open')) {
$('#notifications').data('open', false);
markNotifications(scope);
} else
$('#notifications').data('open', true);
});
$(document).click(function() {
if($('#notifications').data('open')) {
$('#notifications').data('open', false);
markNotifications(scope);
}
});
}
}
});