Revamped note form options.
This commit is contained in:
parent
4ed8278870
commit
b47173da6a
|
@ -32,12 +32,6 @@ var NoteList = {
|
||||||
// get initial set of notes
|
// get initial set of notes
|
||||||
NoteList.getContent();
|
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
|
// add a new diff note
|
||||||
$(document).on("click",
|
$(document).on("click",
|
||||||
".js-add-diff-note-button",
|
".js-add-diff-note-button",
|
||||||
|
@ -53,6 +47,11 @@ var NoteList = {
|
||||||
".js-note-preview-button",
|
".js-note-preview-button",
|
||||||
NoteList.previewNote);
|
NoteList.previewNote);
|
||||||
|
|
||||||
|
// update the file name when an attachment is selected
|
||||||
|
$(document).on("change",
|
||||||
|
".js-note-attachment-input",
|
||||||
|
NoteList.updateFormAttachment);
|
||||||
|
|
||||||
// hide diff note form
|
// hide diff note form
|
||||||
$(document).on("click",
|
$(document).on("click",
|
||||||
".js-close-discussion-note-form",
|
".js-close-discussion-note-form",
|
||||||
|
@ -63,35 +62,22 @@ var NoteList = {
|
||||||
".js-note-delete",
|
".js-note-delete",
|
||||||
NoteList.removeNote);
|
NoteList.removeNote);
|
||||||
|
|
||||||
// clean up previews for main target form
|
// reset main target form after submit
|
||||||
$(document).on("ajax:complete",
|
$(document).on("ajax:complete",
|
||||||
".js-main-target-form",
|
".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.
|
* 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.
|
* 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();
|
GitLab.GfmAutoComplete.setup();
|
||||||
|
|
||||||
form.show();
|
form.show();
|
||||||
|
@ -499,6 +501,41 @@ var NoteList = {
|
||||||
$("#new-notes-list").prepend(html);
|
$("#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).
|
* Recalculates the votes and updates them (if they are displayed at all).
|
||||||
*
|
*
|
||||||
|
|
|
@ -227,6 +227,11 @@ ul.notes {
|
||||||
.discussion {
|
.discussion {
|
||||||
.new_note {
|
.new_note {
|
||||||
margin: 8px 5px 8px 0;
|
margin: 8px 5px 8px 0;
|
||||||
|
|
||||||
|
.note_options {
|
||||||
|
// because of the smaller width and the extra "cancel" button
|
||||||
|
margin-top: 8px;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.new_note {
|
.new_note {
|
||||||
|
@ -236,51 +241,39 @@ ul.notes {
|
||||||
float: left;
|
float: left;
|
||||||
margin-top: 8px;
|
margin-top: 8px;
|
||||||
}
|
}
|
||||||
|
.clearfix {
|
||||||
|
margin-bottom: 0;
|
||||||
|
}
|
||||||
.note_options {
|
.note_options {
|
||||||
h6 {
|
h6 {
|
||||||
line-height: 32px;
|
@extend .left;
|
||||||
padding-right: 15px;
|
line-height: 20px;
|
||||||
|
padding-right: 16px;
|
||||||
|
padding-bottom: 16px;
|
||||||
|
}
|
||||||
|
label {
|
||||||
|
padding: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: start cleanup
|
.attachment {
|
||||||
.attachments {
|
@extend .right;
|
||||||
position: relative;
|
position: relative;
|
||||||
width: 350px;
|
width: 350px;
|
||||||
height: 50px;
|
height: 50px;
|
||||||
overflow: hidden;
|
|
||||||
margin:0 0 5px !important;
|
margin:0 0 5px !important;
|
||||||
|
|
||||||
.input_file {
|
// hide the actual file field
|
||||||
.file_name {
|
input {
|
||||||
line-height: 30px;
|
display: none;
|
||||||
width: 240px;
|
}
|
||||||
height: 28px;
|
|
||||||
overflow: hidden;
|
.choose-btn {
|
||||||
}
|
float: right;
|
||||||
.file_upload {
|
|
||||||
position: absolute;
|
|
||||||
right:14px;
|
|
||||||
top:7px;
|
|
||||||
}
|
|
||||||
.input-file {
|
|
||||||
width: 260px;
|
|
||||||
height: 41px;
|
|
||||||
float: right;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.input-file {
|
.notify_options {
|
||||||
font: 500px monospace;
|
@extend .right;
|
||||||
opacity:0;
|
|
||||||
filter: alpha(opacity=0);
|
|
||||||
position: absolute;
|
|
||||||
z-index: 1;
|
|
||||||
top:0;
|
|
||||||
right:0;
|
|
||||||
padding:0;
|
|
||||||
margin: 0;
|
|
||||||
}
|
}
|
||||||
// TODO: end cleanup
|
|
||||||
}
|
}
|
||||||
.note_text_and_preview {
|
.note_text_and_preview {
|
||||||
// makes the "absolute" position for links relative to this
|
// makes the "absolute" position for links relative to this
|
||||||
|
|
|
@ -140,24 +140,6 @@ class Note < ActiveRecord::Base
|
||||||
@notify_author ||= false
|
@notify_author ||= false
|
||||||
end
|
end
|
||||||
|
|
||||||
# Check if we can notify commit author
|
|
||||||
# with email about our comment
|
|
||||||
#
|
|
||||||
# If commit author email exist in project
|
|
||||||
# and commit author is not passed user we can
|
|
||||||
# send email to him
|
|
||||||
#
|
|
||||||
# params:
|
|
||||||
# user - current user
|
|
||||||
#
|
|
||||||
# return:
|
|
||||||
# Boolean
|
|
||||||
#
|
|
||||||
def notify_only_author?(user)
|
|
||||||
for_commit? && commit_author &&
|
|
||||||
commit_author.email != user.email
|
|
||||||
end
|
|
||||||
|
|
||||||
# Returns true if this is an upvote note,
|
# Returns true if this is an upvote note,
|
||||||
# otherwise false is returned
|
# otherwise false is returned
|
||||||
def upvote?
|
def upvote?
|
||||||
|
|
|
@ -22,23 +22,22 @@
|
||||||
.clearfix
|
.clearfix
|
||||||
|
|
||||||
.note_options
|
.note_options
|
||||||
.attachments.right
|
.attachment
|
||||||
%h6.left Attachment:
|
%h6 Attachment:
|
||||||
%span.file_name File name...
|
.file_name.js-attachment-filename File name...
|
||||||
|
%a.choose-btn.btn.small.js-choose-note-attachment-button Choose File ...
|
||||||
|
.hint Any file up to 10 MB
|
||||||
|
|
||||||
.input.input_file
|
= f.file_field :attachment, class: "js-note-attachment-input"
|
||||||
%a.file_upload.btn.small Upload File
|
|
||||||
= f.file_field :attachment, class: "input-file"
|
|
||||||
%span.hint Any file less than 10 MB
|
|
||||||
|
|
||||||
.notify_opts.right
|
.notify_options
|
||||||
%h6.left Notify via email:
|
%h6 Notify via email:
|
||||||
= label_tag :notify do
|
= label_tag :notify do
|
||||||
= check_box_tag :notify, 1, !@note.for_commit?
|
= check_box_tag :notify, 1, !@note.for_commit?
|
||||||
%span Project team
|
Project team
|
||||||
|
|
||||||
- if @note.notify_only_author?(current_user) # FIXME: put in JS
|
.js-notify-commit-author
|
||||||
= label_tag :notify_author do
|
= label_tag :notify_author do
|
||||||
= check_box_tag :notify_author, 1 , !@note.for_commit?
|
= check_box_tag :notify_author, 1 , !@note.for_commit?
|
||||||
%span Commit author
|
Commit author
|
||||||
.clearfix
|
.clearfix
|
||||||
|
|
Loading…
Reference in a new issue