summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/notes.js.coffee
diff options
context:
space:
mode:
Diffstat (limited to 'app/assets/javascripts/notes.js.coffee')
-rw-r--r--app/assets/javascripts/notes.js.coffee32
1 files changed, 19 insertions, 13 deletions
diff --git a/app/assets/javascripts/notes.js.coffee b/app/assets/javascripts/notes.js.coffee
index efb3e8e2198..ad216910c8d 100644
--- a/app/assets/javascripts/notes.js.coffee
+++ b/app/assets/javascripts/notes.js.coffee
@@ -114,9 +114,9 @@ class @Notes
@refresh()
, @pollingInterval
- refresh: ->
+ refresh: =>
return if @refreshing is true
- refreshing = true
+ @refreshing = true
if not document.hidden and document.URL.indexOf(@noteable_url) is 0
@getContent()
@@ -134,8 +134,8 @@ class @Notes
@renderDiscussionNote(note)
else
@renderNote(note)
- always: =>
- @refreshing = false
+ .always () =>
+ @refreshing = false
###
Increase @pollingInterval up to 120 seconds on every function call,
@@ -162,13 +162,14 @@ class @Notes
renderNote: (note) ->
unless note.valid
if note.award
- flash = new Flash('You have already used this award emoji!', 'alert')
+ flash = new Flash('You have already awarded this emoji!', 'alert')
flash.pinTo('.header-content')
return
if note.award
- awardsHandler.addAwardToEmojiBar(note.note)
- awardsHandler.scrollToAwards()
+ votesBlock = $('.js-awards-block').eq 0
+ gl.awardsHandler.addAwardToEmojiBar votesBlock, note.name
+ gl.awardsHandler.scrollToAwards()
# render note if it not present in loaded list
# or skip if rendered
@@ -285,6 +286,7 @@ class @Notes
form.addClass "js-main-target-form"
form.find("#note_line_code").remove()
+ form.find("#note_type").remove()
###
General note form setup.
@@ -328,7 +330,7 @@ class @Notes
@renderDiscussionNote(note)
# cleanup after successfully creating a diff/discussion note
- @removeDiscussionNoteForm($("#new-discussion-note-form-#{note.discussion_id}"))
+ @removeDiscussionNoteForm($(xhr.target))
###
Called in response to the edit note form being submitted
@@ -352,8 +354,7 @@ class @Notes
Called in response to clicking the edit note link
Replaces the note text with the note edit form
- Adds a hidden div with the original content of the note to fill the edit note form with
- if the user cancels
+ Adds a data attribute to the form with the original content of the note for cancellations
###
showEditForm: (e, scrollTo, myLastNote) ->
e.preventDefault()
@@ -369,6 +370,8 @@ class @Notes
done = ($noteText) ->
# Neat little trick to put the cursor at the end
noteTextVal = $noteText.val()
+ # Store the original note text in a data attribute to retrieve if a user cancels edit.
+ form.find('form.edit-note').data 'original-note', noteTextVal
$noteText.val('').val(noteTextVal);
new GLForm form
@@ -391,14 +394,16 @@ class @Notes
###
Called in response to clicking the edit note link
- Hides edit form
+ Hides edit form and restores the original note text to the editor textarea.
###
cancelEdit: (e) ->
e.preventDefault()
note = $(this).closest(".note")
+ form = note.find(".current-note-edit-form")
note.removeClass "is-editting"
- note.find(".current-note-edit-form")
- .removeClass("current-note-edit-form")
+ form.removeClass("current-note-edit-form")
+ # Replace markdown textarea text with original note text.
+ form.find(".js-note-text").val(form.find('form.edit-note').data('original-note'))
###
Called in response to deleting a note of any kind.
@@ -472,6 +477,7 @@ class @Notes
setupDiscussionNoteForm: (dataHolder, form) =>
# setup note target
form.attr 'id', "new-discussion-note-form-#{dataHolder.data("discussionId")}"
+ form.find("#note_type").val dataHolder.data("noteType")
form.find("#line_type").val dataHolder.data("lineType")
form.find("#note_commit_id").val dataHolder.data("commitId")
form.find("#note_line_code").val dataHolder.data("lineCode")