Commit 7e1c91e0 authored by Douwe Maan's avatar Douwe Maan

Add confirmation when canceling creating/editing with changes

parent 88889d16
...@@ -104,19 +104,31 @@ class @Notes ...@@ -104,19 +104,31 @@ class @Notes
return if isMetaKey e return if isMetaKey e
$textarea = $(e.target) $textarea = $(e.target)
# Edit previous note when UP arrow is hit
if $textarea.val() is '' and e.which is 38 if $textarea.val() is '' and e.which is 38
myLastNote = $("li.note[data-author-id='#{gon.current_user_id}'][data-editable]:last") myLastNote = $("li.note[data-author-id='#{gon.current_user_id}'][data-editable]:last")
if myLastNote.length if myLastNote.length
myLastNoteEditBtn = myLastNote.find('.js-note-edit') myLastNoteEditBtn = myLastNote.find('.js-note-edit')
myLastNoteEditBtn.trigger('click', [true, myLastNote]) myLastNoteEditBtn.trigger('click', [true, myLastNote])
# Cancel creating diff note or editing any note when ESCAPE is hit
if e.which is 27 if e.which is 27
discussionNoteForm = $textarea.closest(".js-discussion-note-form") discussionNoteForm = $textarea.closest(".js-discussion-note-form")
if discussionNoteForm.length if discussionNoteForm.length
if $textarea.val() isnt ''
return unless confirm('Are you sure you want to cancel creating this comment?')
@removeDiscussionNoteForm(discussionNoteForm) @removeDiscussionNoteForm(discussionNoteForm)
return return
editNote = $textarea.closest(".note") editNote = $textarea.closest(".note")
if editNote.length if editNote.length
originalText = $textarea.closest('form').data('original-note')
newText = $textarea.val()
if originalText isnt newText
return unless confirm('Are you sure you want to cancel editing this comment?')
@removeNoteEditForm(editNote) @removeNoteEditForm(editNote)
......
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