Commit 918dc873768359cbb7de5e83bc900fb0dacce938
1 parent
fac4e3f2
Exists in
master
and in
4 other branches
Move code for appending a discussion note to notes JS
Showing
2 changed files
with
17 additions
and
11 deletions
Show diff stats
app/assets/javascripts/notes.js
... | ... | @@ -377,6 +377,20 @@ var NoteList = { |
377 | 377 | this.updateVotes(); |
378 | 378 | }, |
379 | 379 | |
380 | + appendNewDiscussionNote: function(discussionId, diffRowHtml, noteHtml) { | |
381 | + // is this the first note of discussion? | |
382 | + var row = $("form[rel='"+discussionId+"']").closest("tr"); | |
383 | + if (row.is(".js-temp-notes-holder")) { | |
384 | + // insert the note and the reply button after it | |
385 | + row.after(diffRowHtml); | |
386 | + // will be added again below | |
387 | + row.next().find(".note").remove(); | |
388 | + } | |
389 | + | |
390 | + // append new note to all matching discussions | |
391 | + $(".notes[rel='"+discussionId+"']").append(noteHtml); | |
392 | + }, | |
393 | + | |
380 | 394 | /** |
381 | 395 | * Recalculates the votes and updates them (if they are displayed at all). |
382 | 396 | * | ... | ... |
app/views/notes/_create_discussion_note.js.haml
1 | 1 | - if note.valid? |
2 | 2 | :plain |
3 | - // is this the first note of discussion? | |
4 | - var row = $("form[rel='#{note.discussion_id}']").closest("tr"); | |
5 | - if (row.is(".js-temp-notes-holder")) { | |
6 | - // insert the note and the reply button after it | |
7 | - row.after("#{escape_javascript(render "notes/diff_notes_with_reply", notes: [note])}"); | |
8 | - // will be added again below | |
9 | - row.next().find(".note").remove(); | |
10 | - } | |
11 | - | |
12 | - // append new note to all discussions | |
13 | - $(".notes[rel='#{note.discussion_id}']").append("#{escape_javascript(render "notes/note", note: note)}"); | |
3 | + NoteList.appendNewDiscussionNote("#{note.discussion_id}", | |
4 | + "#{escape_javascript(render "notes/diff_notes_with_reply", notes: [note])}", | |
5 | + "#{escape_javascript(render "notes/note", note: note)}"); | ... | ... |