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 = ->
|
2017-06-20 11:04:06 -04:00
|
|
|
$http.get("/announcements").then (response) ->
|
|
|
|
$scope.announcements = response.data
|
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
|
|
|
|
2017-02-15 07:43:13 -05:00
|
|
|
$scope.logAnnouncementClick = ->
|
2017-02-15 07:16:35 -05:00
|
|
|
event_tracking.sendMB "announcement-read-more-clicked", { blogPostId: $scope.announcements[0].id }
|
|
|
|
|
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-12-07 09:57:54 -05:00
|
|
|
$scope.showAll = ->
|
|
|
|
$scope.ui.newItems = 0
|
2016-11-29 12:12:53 -05:00
|
|
|
|