2016-11-11 17:03:01 +00:00
|
|
|
define [
|
|
|
|
"base"
|
|
|
|
], (App) ->
|
2016-12-07 14:26:10 +00:00
|
|
|
App.controller "AnnouncementsController", ($scope, $http, event_tracking, $window, _) ->
|
2016-11-29 17:12:53 +00:00
|
|
|
$scope.announcements = []
|
2016-12-05 15:32:38 +00:00
|
|
|
$scope.ui =
|
|
|
|
isOpen: false
|
2016-12-07 14:26:10 +00:00
|
|
|
newItems: 0
|
|
|
|
|
2016-11-29 17:12:53 +00:00
|
|
|
refreshAnnouncements = ->
|
2017-06-20 15:04:06 +00:00
|
|
|
$http.get("/announcements").then (response) ->
|
|
|
|
$scope.announcements = response.data
|
2017-06-29 10:04:52 +00:00
|
|
|
$scope.ui.newItems = _.filter($scope.announcements, (announcement) -> !announcement.read).length
|
2016-11-29 17:12:53 +00:00
|
|
|
|
2016-12-07 14:26:10 +00:00
|
|
|
markAnnouncementsAsRead = ->
|
|
|
|
event_tracking.sendMB "announcement-alert-dismissed", { blogPostId: $scope.announcements[0].id }
|
2016-11-11 17:03:01 +00:00
|
|
|
|
2017-02-15 12:43:13 +00:00
|
|
|
$scope.logAnnouncementClick = ->
|
2017-02-15 12:16:35 +00:00
|
|
|
event_tracking.sendMB "announcement-read-more-clicked", { blogPostId: $scope.announcements[0].id }
|
|
|
|
|
2016-11-29 17:12:53 +00:00
|
|
|
refreshAnnouncements()
|
2016-11-11 17:03:01 +00:00
|
|
|
|
2016-12-07 14:26:10 +00: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 14:57:54 +00:00
|
|
|
$scope.showAll = ->
|
|
|
|
$scope.ui.newItems = 0
|
2016-11-29 17:12:53 +00:00
|
|
|
|