Commit 852084c7 authored by Ujvari Gergely's avatar Ujvari Gergely

Issue #181 -Extended close-confirm functionality to newly created annotations too.

parent 5c82eb04
...@@ -29,6 +29,10 @@ class Hypothesis extends Annotator ...@@ -29,6 +29,10 @@ class Hypothesis extends Annotator
this.publish event, [annotation] this.publish event, [annotation]
addPlugin: => this.addPlugin arguments... addPlugin: => this.addPlugin arguments...
createAnnotation: => createAnnotation: =>
if not this._canCloseUnsaved()
@editor.hide()
this.show()
return
@cache[h = ++@hash] = this.createAnnotation() @cache[h = ++@hash] = this.createAnnotation()
h h
showEditor: (stub) => showEditor: (stub) =>
...@@ -42,6 +46,7 @@ class Hypothesis extends Annotator ...@@ -42,6 +46,7 @@ class Hypothesis extends Annotator
else else
showAuth true showAuth true
@editor.hide() @editor.hide()
if @unsaved_drafts.indexOf(@editor) > -1 then @unsaved_drafts.splice(@unsaved_drafts.indexOf(@editor),1)
this.show() this.show()
# This guy does stuff when you "back out" of the interface. # This guy does stuff when you "back out" of the interface.
# (Currently triggered by a click on the source page.) # (Currently triggered by a click on the source page.)
...@@ -324,9 +329,8 @@ class Hypothesis extends Annotator ...@@ -324,9 +329,8 @@ class Hypothesis extends Annotator
@provider.setupAnnotation stub @provider.setupAnnotation stub
showViewer: (annotations=[], detail=false) => showViewer: (annotations=[], detail=false) =>
if @visible and not detail if (@visible and not detail) or @unsaved_drafts.indexOf(@editor) > -1
if not this._canCloseUnsaved() if not this._canCloseUnsaved() then return
return
# Thread the messages using JWZ # Thread the messages using JWZ
messages = mail.messageThread().thread annotations.map (a) -> messages = mail.messageThread().thread annotations.map (a) ->
...@@ -407,7 +411,6 @@ class Hypothesis extends Annotator ...@@ -407,7 +411,6 @@ class Hypothesis extends Annotator
else else
d3.select(this).html(quote) d3.select(this).html(quote)
highlights = [] highlights = []
excerpts.each (d) => excerpts.each (d) =>
h = d.message.annotation.hash h = d.message.annotation.hash
...@@ -514,6 +517,7 @@ class Hypothesis extends Annotator ...@@ -514,6 +517,7 @@ class Hypothesis extends Annotator
items = thread context, '.annotation' items = thread context, '.annotation'
@editor.hide() @editor.hide()
if @unsaved_drafts.indexOf(@editor) > -1 then @unsaved_drafts.splice(@unsaved_drafts.indexOf(@editor),1)
@viewer.show() @viewer.show()
updateViewer: (annotations) => updateViewer: (annotations) =>
...@@ -527,6 +531,7 @@ class Hypothesis extends Annotator ...@@ -527,6 +531,7 @@ class Hypothesis extends Annotator
if not annotation.user? if not annotation.user?
@plugins.Permissions.addFieldsToAnnotation(annotation) @plugins.Permissions.addFieldsToAnnotation(annotation)
@unsaved_drafts.push @editor
@viewer.hide() @viewer.hide()
@editor.load(annotation) @editor.load(annotation)
@editor.element.find('.annotator-controls').remove() @editor.element.find('.annotator-controls').remove()
...@@ -571,7 +576,7 @@ class Hypothesis extends Annotator ...@@ -571,7 +576,7 @@ class Hypothesis extends Annotator
for editor in @unsaved_drafts for editor in @unsaved_drafts
editor.show() editor.show()
unsaved_text = editor.element[0].ownerDocument.activeElement.value unsaved_text = editor.element[0].ownerDocument.activeElement.value
if unsaved_text != null and unsaved_text.toString().length > 0 then open_editors += 1 if typeof unsaved_text != 'undefined' and unsaved_text.toString().length > 0 then open_editors += 1
if open_editors > 0 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?" 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?"
......
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