Move notifications into a separate view
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
'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);
|
||||
|
||||
$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();
|
||||
});
|
||||
}]);
|
||||
Reference in New Issue
Block a user