From 918dc873768359cbb7de5e83bc900fb0dacce938 Mon Sep 17 00:00:00 2001 From: Riyad Preukschas Date: Thu, 22 Nov 2012 00:42:55 +0100 Subject: [PATCH] Move code for appending a discussion note to notes JS --- app/assets/javascripts/notes.js | 14 ++++++++++++++ app/views/notes/_create_discussion_note.js.haml | 14 +++----------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/app/assets/javascripts/notes.js b/app/assets/javascripts/notes.js index 7f4bd330839..fec91c1fdb5 100644 --- a/app/assets/javascripts/notes.js +++ b/app/assets/javascripts/notes.js @@ -377,6 +377,20 @@ var NoteList = { this.updateVotes(); }, + appendNewDiscussionNote: function(discussionId, diffRowHtml, noteHtml) { + // is this the first note of discussion? + var row = $("form[rel='"+discussionId+"']").closest("tr"); + if (row.is(".js-temp-notes-holder")) { + // insert the note and the reply button after it + row.after(diffRowHtml); + // will be added again below + row.next().find(".note").remove(); + } + + // append new note to all matching discussions + $(".notes[rel='"+discussionId+"']").append(noteHtml); + }, + /** * Recalculates the votes and updates them (if they are displayed at all). * diff --git a/app/views/notes/_create_discussion_note.js.haml b/app/views/notes/_create_discussion_note.js.haml index 968ef0cfbee..91ba8593d45 100644 --- a/app/views/notes/_create_discussion_note.js.haml +++ b/app/views/notes/_create_discussion_note.js.haml @@ -1,13 +1,5 @@ - if note.valid? :plain - // is this the first note of discussion? - var row = $("form[rel='#{note.discussion_id}']").closest("tr"); - if (row.is(".js-temp-notes-holder")) { - // insert the note and the reply button after it - row.after("#{escape_javascript(render "notes/diff_notes_with_reply", notes: [note])}"); - // will be added again below - row.next().find(".note").remove(); - } - - // append new note to all discussions - $(".notes[rel='#{note.discussion_id}']").append("#{escape_javascript(render "notes/note", note: note)}"); + NoteList.appendNewDiscussionNote("#{note.discussion_id}", + "#{escape_javascript(render "notes/diff_notes_with_reply", notes: [note])}", + "#{escape_javascript(render "notes/note", note: note)}");