Commit aece5afe authored by Randall Leeds's avatar Randall Leeds

fix some bridge errors

parent c73a10f1
...@@ -80,14 +80,14 @@ class Annotator.Plugin.Bridge extends Annotator.Plugin ...@@ -80,14 +80,14 @@ class Annotator.Plugin.Bridge extends Annotator.Plugin
msg: msg msg: msg
beforeAnnotationCreated: (annotation) => beforeAnnotationCreated: (annotation) =>
unless annotation.$$tag? return if annotation.$$tag?
tag = this.createAnnotation() this.beforeCreateAnnotation annotation
this._tag annotation, tag
annotationDeleted: (annotation) => annotationDeleted: (annotation) =>
return unless @cache[annotation.$$tag?] return unless annotation.$$tag? and @cache[annotation.$$tag]
delete @cache[annotation.$$tag] this.deleteAnnotation annotation, (err) =>
this.deleteAnnotation annotation if err then @annotator.setupAnnotation annotation
else delete @cache[annotation.$$tag]
annotationsLoaded: (annotations) => annotationsLoaded: (annotations) =>
this.setupAnnotation a for a in annotations this.setupAnnotation a for a in annotations
...@@ -96,8 +96,8 @@ class Annotator.Plugin.Bridge extends Annotator.Plugin ...@@ -96,8 +96,8 @@ class Annotator.Plugin.Bridge extends Annotator.Plugin
@channel @channel
## Remote method call bindings ## Remote method call bindings
.bind('createAnnotation', (txn, tag) => .bind('beforeCreateAnnotation', (txn, annotation) =>
annotation = this._tag {}, tag annotation = this._parse annotation
@annotator.publish 'beforeAnnotationCreated', annotation @annotator.publish 'beforeAnnotationCreated', annotation
this._format annotation this._format annotation
) )
...@@ -111,8 +111,12 @@ class Annotator.Plugin.Bridge extends Annotator.Plugin ...@@ -111,8 +111,12 @@ class Annotator.Plugin.Bridge extends Annotator.Plugin
) )
.bind('deleteAnnotation', (txn, annotation) => .bind('deleteAnnotation', (txn, annotation) =>
delete @cache[annotation.tag] annotation = this._parse annotation
this._format (@annotator.deleteAnnotation (this._parse annotation)) delete @cache[annotation.$$tag]
annotation = @annotator.deleteAnnotation annotation
result = this._format annotation
delete @cache[annotation.$$tag]
result
) )
## Notifications ## Notifications
...@@ -121,19 +125,18 @@ class Annotator.Plugin.Bridge extends Annotator.Plugin ...@@ -121,19 +125,18 @@ class Annotator.Plugin.Bridge extends Annotator.Plugin
) )
.bind('showViewer', (ctx, annotations) => .bind('showViewer', (ctx, annotations) =>
@annotator.showEditor (this._parse a for a in annotations) @annotator.showViewer (this._parse a for a in annotations)
) )
createAnnotation: (cb) -> beforeCreateAnnotation: (annotation, cb) ->
tag = window.btoa Math.random()
@channel.call @channel.call
method: 'createAnnotation' method: 'beforeCreateAnnotation'
params: tag params: this._format annotation
success: (annotation) => success: (annotation) =>
annotation = this._parse annotation annotation = this._parse annotation
cb? null, annotation cb? null, annotation
error: (error, reason) => cb? {error, reason} error: (error, reason) => cb? {error, reason}
tag annotation
setupAnnotation: (annotation, cb) -> setupAnnotation: (annotation, cb) ->
@channel.call @channel.call
...@@ -156,7 +159,7 @@ class Annotator.Plugin.Bridge extends Annotator.Plugin ...@@ -156,7 +159,7 @@ class Annotator.Plugin.Bridge extends Annotator.Plugin
annotation annotation
deleteAnnotation: (annotation, cb) -> deleteAnnotation: (annotation, cb) ->
@channel.notify @channel.call
method: 'deleteAnnotation' method: 'deleteAnnotation'
params: this._format annotation params: this._format annotation
success: (annotation) => success: (annotation) =>
......
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