Revamped note form options.

This commit is contained in:
Riyad Preukschas 2012-12-03 22:34:50 +01:00
parent 4ed8278870
commit b47173da6a
4 changed files with 101 additions and 90 deletions

View file

@ -32,12 +32,6 @@ var NoteList = {
// get initial set of notes
NoteList.getContent();
$("#note_attachment").change(function(e){
var val = $('.input-file').val();
var filename = val.replace(/^.*[\\\/]/, '');
$(".file_name").text(filename);
});
// add a new diff note
$(document).on("click",
".js-add-diff-note-button",
@ -53,6 +47,11 @@ var NoteList = {
".js-note-preview-button",
NoteList.previewNote);
// update the file name when an attachment is selected
$(document).on("change",
".js-note-attachment-input",
NoteList.updateFormAttachment);
// hide diff note form
$(document).on("click",
".js-close-discussion-note-form",
@ -63,35 +62,22 @@ var NoteList = {
".js-note-delete",
NoteList.removeNote);
// clean up previews for main target form
// reset main target form after submit
$(document).on("ajax:complete",
".js-main-target-form",
NoteList.cleanupMainTargetForm);
NoteList.resetMainTargetForm);
$(document).on("click",
".js-choose-note-attachment-button",
NoteList.chooseNoteAttachment);
},
/**
* Event handlers
* When clicking on buttons
*/
/**
*
*/
cleanupMainTargetForm: function(){
var form = $(this);
// remove validation errors
form.find(".js-errors").remove();
// reset text and preview
var previewContainer = form.find(".js-toggler-container.note_text_and_preview");
if (previewContainer.is(".on")) {
previewContainer.removeClass("on");
}
form.find(".js-note-text").val("").trigger("input");
},
/**
* Called when clicking on the "add a comment" button on the side of a diff line.
*
@ -121,6 +107,17 @@ var NoteList = {
}
},
/**
* Called when clicking the "Choose File" button.
*
* Opesn the file selection dialog.
*/
chooseNoteAttachment: function() {
var form = $(this).closest("form");
form.find(".js-note-attachment-input").click();
},
/**
* Shows the note preview.
*
@ -307,6 +304,11 @@ var NoteList = {
}
});
// remove notify commit author checkbox for non-commit notes
if (form.find("#note_noteable_type").val() !== "Commit") {
form.find(".js-notify-commit-author").remove();
}
GitLab.GfmAutoComplete.setup();
form.show();
@ -499,6 +501,41 @@ var NoteList = {
$("#new-notes-list").prepend(html);
},
/**
* Called in response the main target form has been successfully submitted.
*
* Removes any errors.
* Resets text and preview.
* Resets buttons.
*/
resetMainTargetForm: function(){
var form = $(this);
// remove validation errors
form.find(".js-errors").remove();
// reset text and preview
var previewContainer = form.find(".js-toggler-container.note_text_and_preview");
if (previewContainer.is(".on")) {
previewContainer.removeClass("on");
}
form.find(".js-note-text").val("").trigger("input");
},
/**
* Called after an attachment file has been selected.
*
* Updates the file name for the selected attachment.
*/
updateFormAttachment: function() {
var form = $(this).closest("form");
// get only the basename
var filename = $(this).val().replace(/^.*[\\\/]/, '');
form.find(".js-attachment-filename").text(filename);
},
/**
* Recalculates the votes and updates them (if they are displayed at all).
*