limitless.directive('notificationsList', [ 'Zupit.Core.AppService', 'config', 'Zupit.Core.HttpClient', 'Zupit.Core.NotificationService','$state','$rootScope', function (app, config, $http, $notifier,$state,$rootScope) { return { restrict: 'E', replace: true, scope: { user:'=' }, templateUrl:config.baseUrl + 'app/components/notificationsList.html', controller:function($scope) { $scope.notifications = []; function sendNewNotificationCount() { $http.get('api/notifications/new').then(function (ret) { var count = 0; if (ret.succeded) count = ret.data; $rootScope.$broadcast('NewNotificationCount', count); }); } $scope.loading = true; function load() { $scope.loading = true; sendNewNotificationCount(); $http.get('api/notifications/recent').then(function (ret) { if (ret.succeded) { $scope.notifications = ret.data; } $scope.loading = false; }); } //if (user!==undefined && user!==null && user.isAuthenticated) // load(); $scope.$on('NewUserNotificationEvent', function () { load(); }); $scope.$watch('user', function(newv, oldv) { if (newv !== undefined && newv !== null && newv.isAuthenticated) load(); }); $scope.goto = function (e, notification) { e.stopPropagation(); if (!notification.read) { $http.post('api/notifications/markAsRead/' + notification.userNotificationId).then(function(ret) { notification.read = true; sendNewNotificationCount(); $state.go(notification.state, notification.stateParams); }); } else { $state.go(notification.state, notification.stateParams); } } $scope.markAsRead = function (notification) { if (notification.read) return; $http.post('api/notifications/markAsRead/' + notification.userNotificationId).then(function (ret) { notification.read = true; sendNewNotificationCount(); }); } $scope.readAll=function() { $http.post('api/notifications/markAllAsRead/').then(function (ret) { load(); }); } } } } ]); limitless.directive('bindHtmlCompile', ['$compile', function ($compile) { return { restrict: 'A', link: function (scope, element, attrs) { scope.$watch(function () { return scope.$eval(attrs.bindHtmlCompile); }, function (value) { element.html(value && value.toString()); var compileScope = scope; if (attrs.bindHtmlScope) { compileScope = scope.$eval(attrs.bindHtmlScope); } $compile(element.contents())(compileScope); }); } }; }]);