This repository has been archived by the owner on Jan 20, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnotification-ui.js
108 lines (93 loc) · 2.77 KB
/
notification-ui.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
define([
'scripts/core/event-bus',
'css!./less/notifications',
], function (eventBus) {
'use strict';
var notificationController = [
'$scope', 'notification-service',
function ($scope, notificationService) {
$scope.unreadCounter = 0;
$scope.notifications = notificationService.getAll();
$scope.onNotificationClick = function (notification) {
notification.seen = true;
if (notification.onClick) {
notification.onClick();
$scope.showNotificaionList = false;
}
};
$scope.toggleNotificationList = function (notification) {
$scope.showNotificaionList = !$scope.showNotificaionList;
/* The notification list was just hidden --
* mark all notifications as seen
*/
if (!$scope.showNotificaionList) {
$scope.readAll();
}
};
$scope.removeNotification = function (notification) {
notificationService.rem(notification);
};
$scope.removeAll = function (notification) {
_.forEach($scope.notifications, $scope.removeNotification);
};
$scope.readAll = function (notification) {
_.forEach($scope.notifications, function (notification) {
notification.seen = true;
});
};
eventBus.vent.on('notification:new', function (notification) {
if (!$scope.$$phase) { $scope.$apply(); }
});
eventBus.vent.on('notification:rem', function (notification) {
if (!$scope.$$phase) { $scope.$apply(); }
});
eventBus.vent.on('notification:seen', function (notification) {
if (!$scope.$$phase) { $scope.$apply(); }
});
$scope.$watch('notifications', function (newVal, oldVal, $scope) {
var total = $scope.notifications.length;
var seen = _.filter($scope.notifications, { seen: true }).length;
$scope.unreadCounter = total - seen;
}, true);
}
];
var onOutClickDirective = [
'$document',
function ($document) {
return {
restrict: 'A',
link: function (scope, element, attrs) {
$document.bind('click', function (event) {
if (element.find(event.target).length) return;
scope.$apply(function () {
scope.$eval(attrs.onOutClick);
});
});
},
};
}
];
function initModule(extModule) {
extModule.controller('notification-ui', notificationController);
extModule.directive('cawNotifications', function () {
return {
restrict: 'E',
replace: true,
templateUrl: 'extensions/hpsw/notifications/1.00/notifications.html'
};
});
extModule.directive('onOutClick', onOutClickDirective);
}
var runModule = [
'mastheadService', 'notification-service',
function (mastheadService, notificationService) {
mastheadService.forNotifications(function (domElement) {
$(domElement).append($('<caw-notifications>'));
});
}
];
return {
init: initModule,
run: runModule,
};
});