Commit e24ceecd authored by Randall Leeds's avatar Randall Leeds

restore behavior when saving new annotations

In the editor, should show detail view of the new annotation,
while, in the detail viewer, should stay put.
parent 072183e7
......@@ -272,20 +272,23 @@ class Editor
$location, $routeParams, $scope,
annotator, threading
) ->
done = ->
$location.path('/app').search(null).replace()
save = ->
$location.path('/viewer').replace()
annotator.provider.onEditorSubmit()
annotator.provider.onEditorHide()
annotator.hide()
annotator.subscribe 'annotationCreated', annotator.provider.onEditorSubmit
annotator.subscribe 'annotationCreated', done
annotator.subscribe 'annotationDeleted', done
cancel = ->
search = $location.search() or {}
delete search.id
$location.path('/viewer').search(search).replace()
annotator.provider.onEditorHide()
annotator.subscribe 'annotationCreated', save
annotator.subscribe 'annotationDeleted', cancel
$scope.$on '$destroy', ->
annotator.unsubscribe 'annotationCreated',
annotator.provider.onEditorSubmit
annotator.unsubscribe 'annotationCreated', done
annotator.unsubscribe 'annotationDeleted', done
annotator.unsubscribe 'annotationCreated', save
annotator.unsubscribe 'annotationDeleted', cancel
thread = (threading.getContainer $routeParams.id)
annotation = thread.message?.annotation
......@@ -304,10 +307,21 @@ class Viewer
annotator, threading
) ->
{plugins, provider} = annotator
refresh = => this.refresh $scope, $routeParams, threading, plugins.Heatmap
update = -> $scope.$apply refresh
listening = false
refresh = =>
this.refresh $scope, $routeParams, threading, plugins.Heatmap
if listening
if $scope.detail or $routeParams.bucket?
plugins.Heatmap.unsubscribe 'updated', refresh
listening = false
else
unless $scope.detail or $routeParams.bucket?
plugins.Heatmap.subscribe 'updated', refresh
listening = true
$scope.annotations = []
$scope.detail = false
$scope.thread = null
$scope.showDetail = ($event) ->
......@@ -330,16 +344,11 @@ class Viewer
provider.setActiveHighlights highlights
$scope.$on '$destroy', ->
plugins.Heatmap.unsubscribe 'updated', refresh
if listening then plugins.Heatmap.unsubscribe 'updated', refresh
$scope.$on '$routeUpdate', ->
refresh()
if $routeParams.bucket?
plugins.Heatmap.unsubscribe 'updated', refresh
else
plugins.Heatmap.subscribe 'updated', refresh
$scope.$on '$routeUpdate', refresh
$scope.$evalAsync -> $scope.$emit '$routeUpdate'
refresh()
refresh: ($scope, $routeParams, threading, heatmap) =>
if $routeParams.id?
......
......@@ -119,6 +119,13 @@ class Hypothesis extends Annotator
Object.defineProperty annotation, 'id',
enumerable: true
# If the annotation is loaded in a view, switch the view
# to reference the new id.
search = $location.search()
if search? and search.id == annotation.id
search.id = data.id
$location.search(search).replace()
# Update the annotation with the new data
annotation = angular.extend annotation, data
......
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