Commit a1ae261d authored by Gergely Ujvari's avatar Gergely Ujvari

Store persona in the rootScope

parent 3765a865
class AccountController
@inject = ['$scope', '$filter', 'flash', 'session', 'identity', 'formHelpers']
constructor: ($scope, $filter, flash, session, identity, formHelpers) ->
@inject = [ '$rootScope', '$scope', '$filter',
'flash', 'session', 'identity', 'formHelpers']
constructor: ($rootScope, $scope, $filter,
flash, session, identity, formHelpers) ->
persona_filter = $filter('persona')
$scope.subscriptionDescription =
reply: 'Receive notification emails when: - Someone replies to one of my annotations'
......@@ -31,7 +33,7 @@ class AccountController
$scope.$broadcast 'formState', form.$name, '' # Update status btn
$scope.tab = 'Account'
session.profile({user_id: $scope.persona}).$promise
session.profile({user_id: $rootScope.persona}).$promise
.then (result) =>
$scope.subscriptions = result.subscriptions
......@@ -45,7 +47,7 @@ class AccountController
# The extension is then removed from the page.
# Confirmation of success is given.
return unless form.$valid
username = persona_filter $scope.persona
username = persona_filter $rootScope.persona
packet =
username: username
pwd: form.pwd.$modelValue
......@@ -60,7 +62,7 @@ class AccountController
formHelpers.applyValidationErrors(form)
return unless form.$valid
username = persona_filter $scope.persona
username = persona_filter $rootScope.persona
packet =
username: username
pwd: form.pwd.$modelValue
......@@ -75,7 +77,7 @@ class AccountController
$scope.updated = (index, form) ->
packet =
username: $scope.persona
username: $rootScope.persona
subscriptions: JSON.stringify $scope.subscriptions[index]
successHandler = angular.bind(null, onSuccess, form)
......
......@@ -81,7 +81,7 @@ class AppController
Store = plugins.Store
delete plugins.Store
if $scope.persona or annotator.socialView.name is 'none'
if $rootScope.persona or annotator.socialView.name is 'none'
annotator.addPlugin 'Store', annotator.options.Store
$scope.store = plugins.Store
......@@ -106,7 +106,7 @@ class AppController
Store.updateAnnotation = angular.noop
# Sort out which annotations should remain in place.
user = $scope.persona
user = $rootScope.persona
view = annotator.socialView.name
cull = (acc, annotation) ->
if view is 'single-player' and annotation.user != user
......@@ -147,7 +147,7 @@ class AppController
user: token.userId
userAuthorize: authorizeAction
$scope.$apply ->
$scope.persona = token.userId
$rootScope.persona = token.userId
reset()
onlogout = ->
......@@ -159,15 +159,15 @@ class AppController
plugins.Permissions?.destroy()
delete plugins.Permissions
$scope.persona = null
$rootScope.persona = null
checkingToken = false
reset()
onready = ->
if not checkingToken and typeof $scope.persona == 'undefined'
if not checkingToken and typeof $rootScope.persona == 'undefined'
# If we're not checking the token and persona is undefined, onlogin
# hasn't run, which means we aren't authenticated.
$scope.persona = null
$rootScope.persona = null
reset()
if isFirstRun
......@@ -193,7 +193,7 @@ class AppController
$scope.$watch 'socialView.name', (newValue, oldValue) ->
return if newValue is oldValue
initStore()
if newValue is 'single-player' and not $scope.persona
if newValue is 'single-player' and not $rootScope.persona
annotator.show()
flash 'info',
'You will need to sign in for your highlights to be saved.'
......
......@@ -37,9 +37,9 @@ validate = (value) ->
# {@link annotator annotator service} for persistence.
###
AnnotationController = [
'$scope', '$timeout',
'$rootScope', '$scope', '$timeout',
'annotator', 'drafts', 'flash', 'documentHelpers', 'timeHelpers',
($scope, $timeout,
($rootScope, $scope, $timeout,
annotator, drafts, flash, documentHelpers, timeHelpers
) ->
@annotation = {}
......@@ -182,15 +182,16 @@ AnnotationController = [
reply = {references, uri}
annotator.publish 'beforeAnnotationCreated', reply
reply.permissions.update = [model.user]
reply.permissions.delete = [model.user]
reply.permissions.admin = [model.user]
if $rootScope.persona?
reply.permissions.update = [$rootScope.persona]
reply.permissions.delete = [$rootScope.persona]
reply.permissions.admin = [$rootScope.persona]
# If replying to a public annotation make the response public.
if 'group:__world__' in (model.permissions.read or [])
reply.permissions.read = ['group:__world__']
else
reply.permissions.read = [model.user]
# If replying to a public annotation make the response public.
if 'group:__world__' in (model.permissions.read or [])
reply.permissions.read = ['group:__world__']
else
reply.permissions.read = [$rootScope.persona]
###*
# @ngdoc method
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment