overleaf/services/web/public/coffee/main/project-list/notifications-controller.coffee
James Allen d904e50041 Make project invite notification dynamic and accept via ajax request
Needs translations:

  "joining": "Joining",
  "notification_project_invite_message": "<b>{{ userName }}</b> would like you to join <b>{{ projectName }}</b>",
  "notification_project_invite_accepted_message": "You've joined <b>{{ projectName }}</b>",
  "open_project": "Open Project"
2016-09-21 11:59:35 +01:00

38 lines
No EOL
1.1 KiB
CoffeeScript

define [
"base"
], (App) ->
App.controller "NotificationsController", ($scope, $http) ->
for notification in $scope.notifications
notification.hide = false
$scope.dismiss = (notification) ->
$http({
url: "/notifications/#{notification._id}"
method: "DELETE"
headers:
"X-Csrf-Token": window.csrfToken
})
.success (data) ->
notification.hide = true
App.controller "ProjectInviteNotificationController", ($scope, $http) ->
# Shortcuts for translation keys
$scope.projectName = $scope.notification.messageOpts.projectName
$scope.userName = $scope.notification.messageOpts.userName
$scope.accept = () ->
$scope.notification.inflight = true
$http({
url: "/project/#{$scope.notification.messageOpts.projectId}/invite/#{$scope.notification.messageOpts.token}/accept"
method: "POST"
headers:
"X-Csrf-Token": window.csrfToken
"X-Requested-With": "XMLHttpRequest"
})
.success () ->
$scope.notification.inflight = false
$scope.notification.accepted = true
.error () ->
$scope.notification.inflight = false
$scope.notification.error = true