Commit 5c82eb04 authored by Ujvari Gergely's avatar Ujvari Gergely

Added fix for issue #181 to handle well multiple opened editors.

parent c2c38d47
...@@ -5,7 +5,7 @@ class Hypothesis extends Annotator ...@@ -5,7 +5,7 @@ class Hypothesis extends Annotator
this::hash = -1 # * cheap UUID :cake: this::hash = -1 # * cheap UUID :cake:
this::cache = {} # * object cache this::cache = {} # * object cache
this::visible = false # * Whether the sidebar is visible this::visible = false # * Whether the sidebar is visible
this::reply_editor = null # * Whether there is an open reply editor this::unsaved_drafts = [] # * Unsaved drafts currenty open
# Plugin configuration # Plugin configuration
options: options:
...@@ -487,11 +487,11 @@ class Hypothesis extends Annotator ...@@ -487,11 +487,11 @@ class Hypothesis extends Annotator
editor = this._createEditor() editor = this._createEditor()
editor.load(reply) editor.load(reply)
@reply_editor = editor @unsaved_drafts.push editor
editor.element.removeClass('annotator-outer') editor.element.removeClass('annotator-outer')
editor.on 'save', (annotation) => editor.on 'save', (annotation) =>
this.publish 'annotationCreated', [annotation] this.publish 'annotationCreated', [annotation]
@reply_editor = null @unsaved_drafts.splice(@unsaved_drafts.indexOf(editor),1)
d3.select(editor.element[0]).select('form') d3.select(editor.element[0]).select('form')
.data([reply]) .data([reply])
...@@ -507,7 +507,7 @@ class Hypothesis extends Annotator ...@@ -507,7 +507,7 @@ class Hypothesis extends Annotator
editor.element.appendTo(item.node()) editor.element.appendTo(item.node())
editor.on('hide', => editor.on('hide', =>
item.remove() item.remove()
@reply_editor = null) @unsaved_drafts.splice(@unsaved_drafts.indexOf(editor),1))
editor.element.find(":input:first").focus() editor.element.find(":input:first").focus()
context = items.select '.thread' context = items.select '.thread'
...@@ -567,14 +567,17 @@ class Hypothesis extends Annotator ...@@ -567,14 +567,17 @@ class Hypothesis extends Annotator
_canCloseUnsaved: -> _canCloseUnsaved: ->
#See if there's an unsaved/uncancelled reply #See if there's an unsaved/uncancelled reply
can_close = true can_close = true
unsaved_text = null open_editors = 0
if @reply_editor for editor in @unsaved_drafts
@reply_editor.show() editor.show()
unsaved_text = @reply_editor.element[0].ownerDocument.activeElement.value unsaved_text = editor.element[0].ownerDocument.activeElement.value
can_close = unsaved_text == null or unsaved_text.length < 1 or confirm "You have an unsaved reply. Do you really want to close the view?" if unsaved_text != null and unsaved_text.toString().length > 0 then open_editors += 1
if can_close
@reply_editor = null if open_editors > 0
ctext = if open_editors > 1 then "You have " + open_editors + " unsaved replies. Do you really want to close the view?" else "You have an unsaved reply. Do you really want to close the view?"
if not confirm ctext then can_close = false
if can_close then @unsaved_drafts = []
can_close can_close
threadId: (annotation) -> threadId: (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