2019-01-09 15:18:10 +01:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
/* global asyncForEach:false */
|
|
|
|
|
/* global angular:false */
|
|
|
|
|
|
|
|
|
|
angular.module('Application').controller('NotificationsController', ['$scope', 'Client', function ($scope, Client) {
|
|
|
|
|
|
|
|
|
|
$scope.notifications = {
|
|
|
|
|
notifications: [],
|
|
|
|
|
activeNotification: null,
|
|
|
|
|
busy: true,
|
|
|
|
|
all: false,
|
|
|
|
|
|
|
|
|
|
refresh: function () {
|
|
|
|
|
Client.getNotifications($scope.notifications.all ? null : false, 1, 20, function (error, result) {
|
|
|
|
|
if (error) return console.error(error);
|
|
|
|
|
|
2019-01-09 17:16:41 +01:00
|
|
|
result.forEach(function (r) {
|
|
|
|
|
r.isCollapsed = r.acknowledged;
|
|
|
|
|
});
|
|
|
|
|
|
2019-01-09 15:18:10 +01:00
|
|
|
$scope.notifications.notifications = result;
|
|
|
|
|
|
|
|
|
|
$scope.notifications.busy = false;
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
showOld: function () {
|
|
|
|
|
$scope.notifications.all = true;
|
|
|
|
|
$scope.notifications.refresh();
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
clicked: function (notification) {
|
|
|
|
|
if ($scope.notifications.activeNotification === notification) return $scope.notifications.activeNotification = null;
|
|
|
|
|
$scope.notifications.activeNotification = notification;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
ack: function (notification, callback) {
|
|
|
|
|
callback = callback || function (error) { if (error) console.error(error); };
|
|
|
|
|
|
|
|
|
|
Client.ackNotification(notification.id, function (error) {
|
|
|
|
|
if (error) return callback(error);
|
|
|
|
|
|
|
|
|
|
$scope.$parent.notificationAcknowledged(notification.id);
|
|
|
|
|
$scope.notifications.refresh();
|
|
|
|
|
|
|
|
|
|
callback();
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
action: function (notification) {
|
|
|
|
|
if (notification.action) window.location = notification.action;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
clearAll: function () {
|
|
|
|
|
$scope.notifications.busy = true;
|
|
|
|
|
|
|
|
|
|
asyncForEach($scope.notifications.notifications, function (notification, callback) {
|
|
|
|
|
$scope.notifications.ack(notification, callback);
|
|
|
|
|
}, function (error) {
|
|
|
|
|
if (error) console.error(error);
|
|
|
|
|
|
|
|
|
|
$scope.notifications.busy = false;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Client.onReady(function () {
|
|
|
|
|
$scope.notifications.refresh();
|
|
|
|
|
});
|
|
|
|
|
}]);
|