Commit 00d98163 authored by Randall Leeds's avatar Randall Leeds

Refactor the reset event slightly

Refactor the reset scope event for quicker app startup and stop
using the reserved prefix that angular uses.

- Rename $reset to reset
- At the App controller, invoke the initialization code immediately
  rather than broadcasting an event. Every component should start
  by initializing itself rather than waiting for an event to be
  broadcast.
parent baf9906d
...@@ -42,6 +42,15 @@ class App ...@@ -42,6 +42,15 @@ class App
) -> ) ->
{plugins, host, providers} = annotator {plugins, host, providers} = annotator
_reset = =>
delete annotator.ongoing_edit
base = angular.copy @scope
angular.extend $scope, base,
frame: $scope.frame or @scope.frame
socialView: annotator.socialView
_reset()
session.$promise.then (data) -> session.$promise.then (data) ->
angular.extend $scope.model, data angular.extend $scope.model, data
...@@ -88,7 +97,7 @@ class App ...@@ -88,7 +97,7 @@ class App
$scope.reloadAnnotations() $scope.reloadAnnotations()
else if oldValue? else if oldValue?
session.$logout => session.$logout =>
$scope.$broadcast '$reset' $scope.$broadcast 'reset'
if annotator.tool isnt 'comment' if annotator.tool isnt 'comment'
annotator.setTool 'comment' annotator.setTool 'comment'
...@@ -122,7 +131,7 @@ class App ...@@ -122,7 +131,7 @@ class App
$timeout.cancel authTimeout $timeout.cancel authTimeout
unless $scope.model.persona unless $scope.model.persona
authTimeout = $timeout (-> $scope.$broadcast '$reset'), 60000 authTimeout = $timeout (-> $scope.$broadcast 'reset'), 60000
unless tab unless tab
$scope.ongoingHighlightSwitch = false $scope.ongoingHighlightSwitch = false
delete annotator.ongoing_edit delete annotator.ongoing_edit
...@@ -147,12 +156,7 @@ class App ...@@ -147,12 +156,7 @@ class App
$scope.$on 'showAuth', (event, show=true) -> $scope.$on 'showAuth', (event, show=true) ->
$scope.sheet.collapsed = !show $scope.sheet.collapsed = !show
$scope.$on '$reset', => $scope.$on 'reset', _reset
delete annotator.ongoing_edit
base = angular.copy @scope
angular.extend $scope, base,
frame: $scope.frame or @scope.frame
socialView: annotator.socialView
$scope.$on 'success', (event, action) -> $scope.$on 'success', (event, action) ->
angular.extend $scope.model, session.model angular.extend $scope.model, session.model
...@@ -161,8 +165,6 @@ class App ...@@ -161,8 +165,6 @@ class App
else else
$scope.sheet.collapsed = true $scope.sheet.collapsed = true
$scope.$broadcast '$reset'
$rootScope.viewState = $rootScope.viewState =
sort: '' sort: ''
view: 'Document' view: 'Document'
...@@ -637,7 +639,7 @@ class Auth ...@@ -637,7 +639,7 @@ class Auth
console.log(field, error) console.log(field, error)
flash('error', error) flash('error', error)
$scope.$on '$reset', _reset $scope.$on 'reset', _reset
$scope.submit = (form) -> $scope.submit = (form) ->
angular.extend session, $scope.model angular.extend session, $scope.model
......
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