notifications-controller.coffee 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. define [
  2. "base"
  3. ], (App) ->
  4. App.controller "NotificationsController", ($scope, $http) ->
  5. for notification in $scope.notifications
  6. notification.hide = false
  7. $scope.dismiss = (notification) ->
  8. $http({
  9. url: "/notifications/#{notification._id}"
  10. method: "DELETE"
  11. headers:
  12. "X-Csrf-Token": window.csrfToken
  13. })
  14. .then () ->
  15. notification.hide = true
  16. App.controller "ProjectInviteNotificationController", ($scope, $http) ->
  17. # Shortcuts for translation keys
  18. $scope.projectName = $scope.notification.messageOpts.projectName
  19. $scope.userName = $scope.notification.messageOpts.userName
  20. $scope.accept = () ->
  21. $scope.notification.inflight = true
  22. $http({
  23. url: "/project/#{$scope.notification.messageOpts.projectId}/invite/token/#{$scope.notification.messageOpts.token}/accept"
  24. method: "POST"
  25. headers:
  26. "X-Csrf-Token": window.csrfToken
  27. "X-Requested-With": "XMLHttpRequest"
  28. })
  29. .then () ->
  30. $scope.notification.inflight = false
  31. $scope.notification.accepted = true
  32. .catch () ->
  33. $scope.notification.inflight = false
  34. $scope.notification.error = true
  35. App.controller "OverleafV2NotificationController", ($scope, localStorage) ->
  36. $scope.visible = !localStorage('overleaf_v2_notification_hidden_at')
  37. $scope.dismiss = () ->
  38. $scope.visible = false
  39. localStorage('overleaf_v2_notification_hidden_at', Date.now())
  40. App.controller "OverleafV1NotificationController", ($scope, localStorage) ->
  41. $scope.visible = !localStorage('overleaf_v1_notification_hidden_at')
  42. $scope.toggle = () ->
  43. $scope.visible = !$scope.visible
  44. if !$scope.visible
  45. localStorage('overleaf_v1_notification_hidden_at', Date.now())
  46. else
  47. localStorage('overleaf_v1_notification_hidden_at', null)