Commit a1ae261d authored by Gergely Ujvari's avatar Gergely Ujvari

Store persona in the rootScope

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