limitless.controller('Zupit.Limitless.Notifications.NotificationGridController', ['$scope', 'Zupit.Core.AppService', 'Zupit.Core.PersistenceService', 'Zupit.Core.HttpClient', '$translate', 'Zupit.Core.KendoHelper', '$state', function ($scope, app, persistence, $http, $translate, $kendo, $state) { $scope.gridOptions = $kendo.gridOptions([ $kendo.dateBoundColumn('timestamp', 'TIMESTAMP', true, true, '{0:dd/MM/yyyy HH:mm}','15%'), $kendo.dateBoundColumn('from', 'FROM',true,true,undefined,'15%'), $kendo.templateDateBoundColumn('body','
', 'MESSAGE',false,false), $kendo.customButtonColumn('userNotificationId',''), ]); $scope.dsTest = $kendo.dataSource(function (e) { $http.get("api/notifications/all" + "?kendo=" + kendo.stringify(e.data)).then(function (data) { e.success(data); }, function (err) { e.error(err); }); }, { fields: { timestamp: { type: "date" }, from: { type: "string" }, body: { type: "string" } } }); function sendNewNotificationCount() { $http.get('api/notifications/new').then(function (ret) { var count = 0; if (ret.succeded) count = ret.data; $rootScope.$broadcast('NewNotificationCount', count); }); } $scope.goto = function (e, notification) { e.stopPropagation(); debugger; 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; $scope.grid.dataSource.read(); sendNewNotificationCount(); }); } $scope.readAll = function () { $http.post('api/notifications/markAllAsRead/').then(function (ret) { $scope.grid.dataSource.read(); }); } } ]);