Commit 4413d4d4 authored by Ujvari Gergely's avatar Ujvari Gergely

Issue 181: Asks before switching from detail view if an unsaved not-empty reply is open.

parent 31619902
class Hypothesis extends Annotator class Hypothesis extends Annotator
# Annotator state variables. # Annotator state variables.
this::bucket = -1 # * The index of the bucket shown in the summary view this::bucket = -1 # * The index of the bucket shown in the summary view
this::detail = false # * Whether the viewer shows a summary or detail listing this::detail = false # * Whether the viewer shows a summary or detail listing
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
# Plugin configuration # Plugin configuration
options: options:
Heatmap: {} Heatmap: {}
...@@ -323,6 +324,10 @@ class Hypothesis extends Annotator ...@@ -323,6 +324,10 @@ class Hypothesis extends Annotator
@provider.setupAnnotation stub @provider.setupAnnotation stub
showViewer: (annotations=[], detail=false) => showViewer: (annotations=[], detail=false) =>
if @visible and not detail
if not this._canCloseUnsaved()
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) ->
m = mail.message(null, a.id, a.thread?.split('/') or []) m = mail.message(null, a.id, a.thread?.split('/') or [])
...@@ -482,9 +487,11 @@ class Hypothesis extends Annotator ...@@ -482,9 +487,11 @@ class Hypothesis extends Annotator
editor = this._createEditor() editor = this._createEditor()
editor.load(reply) editor.load(reply)
@reply_editor = 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
d3.select(editor.element[0]).select('form') d3.select(editor.element[0]).select('form')
.data([reply]) .data([reply])
...@@ -498,7 +505,9 @@ class Hypothesis extends Annotator ...@@ -498,7 +505,9 @@ class Hypothesis extends Annotator
.classed('writer', true) .classed('writer', true)
editor.element.appendTo(item.node()) editor.element.appendTo(item.node())
editor.on('hide', => item.remove()) editor.on('hide', =>
item.remove()
@reply_editor = null)
editor.element.find(":input:first").focus() editor.element.find(":input:first").focus()
context = items.select '.thread' context = items.select '.thread'
...@@ -555,6 +564,18 @@ class Hypothesis extends Annotator ...@@ -555,6 +564,18 @@ class Hypothesis extends Annotator
@provider.hideFrame() @provider.hideFrame()
$("#toolbar").removeClass "shown" $("#toolbar").removeClass "shown"
_canCloseUnsaved: ->
#See if there's an unsaved/uncancelled reply
can_close = true
unsaved_text = null
if @reply_editor
@reply_editor.show()
unsaved_text = @reply_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 can_close
@reply_editor = null
can_close
threadId: (annotation) -> threadId: (annotation) ->
if annotation?.thread? if annotation?.thread?
......
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