2016-11-11 12:03:01 -05:00
|
|
|
define [
|
|
|
|
"base"
|
|
|
|
], (App) ->
|
2016-12-07 09:26:10 -05:00
|
|
|
App.controller "AnnouncementsController", ($scope, $http, event_tracking, $window, _) ->
|
2016-11-29 12:12:53 -05:00
|
|
|
$scope.announcements = []
|
2016-12-05 10:32:38 -05:00
|
|
|
$scope.ui =
|
|
|
|
isOpen: false
|
2016-12-07 09:26:10 -05:00
|
|
|
newItems: 0
|
|
|
|
|
2016-11-29 12:12:53 -05:00
|
|
|
refreshAnnouncements = ->
|
|
|
|
$http.get("/announcements").success (announcements) ->
|
|
|
|
$scope.announcements = announcements
|
2016-12-07 09:26:10 -05:00
|
|
|
$scope.ui.newItems = _.filter(announcements, (announcement) -> !announcement.read).length
|
2016-11-29 12:12:53 -05:00
|
|
|
|
2016-12-07 09:26:10 -05:00
|
|
|
markAnnouncementsAsRead = ->
|
|
|
|
event_tracking.sendMB "announcement-alert-dismissed", { blogPostId: $scope.announcements[0].id }
|
2016-11-11 12:03:01 -05:00
|
|
|
|
2016-11-29 12:12:53 -05:00
|
|
|
refreshAnnouncements()
|
2016-11-11 12:03:01 -05:00
|
|
|
|
2016-12-07 09:26:10 -05:00
|
|
|
$scope.toggleAnnouncementsUI = ->
|
|
|
|
$scope.ui.isOpen = !$scope.ui.isOpen
|
|
|
|
|
|
|
|
if !$scope.ui.isOpen and $scope.ui.newItems
|
|
|
|
$scope.ui.newItems = 0
|
|
|
|
markAnnouncementsAsRead()
|
|
|
|
|
2016-11-29 12:12:53 -05:00
|
|
|
|