Commit cee230a1 authored by Riyad Preukschas's avatar Riyad Preukschas

Update JS for adding and removing diff line notes

parent 653f7ec4
No related merge requests found
...@@ -17,8 +17,9 @@ var NoteList = { ...@@ -17,8 +17,9 @@ var NoteList = {
// get initial set of notes // get initial set of notes
this.getContent(); this.getContent();
$('.delete-note').live('ajax:success', function() { $("#notes-list, #new-notes-list").on("ajax:success", ".delete-note", function() {
$(this).closest('li').fadeOut(); }); $(this).closest('li').fadeOut();
});
$(".note-form-holder").on("ajax:before", function(){ $(".note-form-holder").on("ajax:before", function(){
$(".submit_note").disable() $(".submit_note").disable()
...@@ -197,13 +198,41 @@ var NoteList = { ...@@ -197,13 +198,41 @@ var NoteList = {
var PerLineNotes = { var PerLineNotes = {
init: init:
function() { function() {
$(".line_note_link, .line_note_reply_link").on("click", function(e) { /**
* Called when clicking on the "add note" or "reply" button for a diff line.
*
* Shows the note form below the line.
* Sets some hidden fields in the form.
*/
$(".diff_file_content").on("click", ".line_note_link, .line_note_reply_link", function(e) {
var form = $(".per_line_form"); var form = $(".per_line_form");
$(this).closest("tr").after(form); $(this).closest("tr").after(form);
form.find("#note_line_code").val($(this).attr("line_code")); form.find("#note_line_code").val($(this).data("lineCode"));
form.show(); form.show();
return false; return false;
}); });
disableButtonIfEmptyField(".line-note-text", ".submit_inline_note"); disableButtonIfEmptyField(".line-note-text", ".submit_inline_note");
/**
* Called in response to successfully deleting a note on a diff line.
*
* Removes the actual note from view.
* Removes the reply button if the last note for that line has been removed.
*/
$(".diff_file_content").on("ajax:success", ".delete-note", function() {
var trNote = $(this).closest("tr");
trNote.fadeOut(function() {
$(this).remove();
});
// check if this is the last note for this line
// elements must really be removed for this to work reliably
var trLine = trNote.prev();
var trRpl = trNote.next();
if (trLine.hasClass("line_holder") && trRpl.hasClass("reply")) {
trRpl.fadeOut(function() { $(this).remove(); });
}
});
} }
} }
- if note.valid? - if note.valid?
:plain :plain
// hide and reset the form
$(".per_line_form").hide(); $(".per_line_form").hide();
$('.line-note-form-holder textarea').val(""); $('.line-note-form-holder textarea').val("");
$("a.line_note_reply_link[line_code='#{note.line_code}']").closest("tr").remove();
// find the reply button for this line
// (might not be there if this is the first note)
var trRpl = $("a.line_note_reply_link[data-line-code='#{note.line_code}']").closest("tr");
if (trRpl.size() == 0) {
// find the commented line ...
var trEl = $(".#{note.line_code}").parent(); var trEl = $(".#{note.line_code}").parent();
trEl.after("#{escape_javascript(render partial: "notes/per_line_show", locals: {note: note})}"); // ... and insert the note and the reply button after it
trEl.after("#{escape_javascript(render partial: "notes/reply_button", locals: {line_code: note.line_code})}"); trEl.after("#{escape_javascript(render "notes/reply_button", line_code: note.line_code)}");
trEl.after("#{escape_javascript(render "notes/per_line_show", note: note)}");
} else {
// instert new note before reply button
trRpl.before("#{escape_javascript(render "notes/per_line_show", note: note)}");
}
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