forked from publiclab/plots2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor & Add Comments to create.js.erb; Style Fixes for Question Co…
…mments & Toolbar Buttons (publiclab#9195) * stop instantiating fileupload for non-existent elements; add comments * style fixes for toolbar buttons * shorten width of comment container
- Loading branch information
1 parent
77773b6
commit 1d91bd0
Showing
3 changed files
with
69 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,43 @@ | ||
// this code runs after a new comment is posted. | ||
// 1. it inserts the new comment into the DOM | ||
// 2. it also creates image upload functionality for the new comment form (see /app/assets/javascripts/editorToolbar.js) | ||
|
||
// the new comment will have an 'edit comment' form that needs image upload functionality: | ||
let fileUploadElements = [ | ||
{ | ||
selector: '#comment-form-body-edit-<%= @comment.cid %>', | ||
isButton: false | ||
}, | ||
{ | ||
selector: '#dropzone-small-edit-<%= @comment.cid %>', | ||
isButton: true | ||
} | ||
]; | ||
// if new comment is NOT a reply to another comment | ||
<% if @comment.reply_to.nil? %> | ||
$("#comments-list").append('<%= escape_javascript(render :partial => "notes/comment", :locals => {comment: @comment, answer_id: @answer_id}) %>') | ||
$("#comments-list").append('<%= escape_javascript(render :partial => "notes/comment", :locals => { comment: @comment }) %>'); | ||
// the new comment will also have its own reply section | ||
// this reply comment form needs image upload functionality | ||
fileUploadElements = fileUploadElements.concat([ | ||
{ | ||
selector: '#comment-form-body-reply-<%= @comment.cid %>', | ||
isButton: false | ||
}, | ||
{ | ||
selector: '#dropzone-small-reply-<%= @comment.cid %>', | ||
isButton: true | ||
} | ||
]); | ||
<% else %> | ||
$('#comment-<%= @comment.reply_to %>-reply').before('<%= escape_javascript(render :partial => "notes/comment", :locals => {comment: @comment, answer_id: @answer_id}) %>') | ||
// new comment IS a reply to another comment | ||
// no other elements need upload functionality | ||
$('#comment-<%= @comment.reply_to %>-reply-toggle').before('<%= escape_javascript(render :partial => "notes/comment", :locals => {comment: @comment, answer_id: @answer_id}) %>') | ||
<% end %> | ||
// create image upload functionality for fresh comment form | ||
// create image upload functionality for fresh comment's elements | ||
// see editorToolbar.js | ||
const replyFormBody = $('#comment-form-body-reply-<%= @comment.cid %>'); | ||
const editFormBody = $('#comment-form-body-edit-<%= @comment.cid %>'); | ||
const replyButton = $('#dropzone-small-reply-<%= @comment.cid %>'); | ||
const editButton = $('#dropzone-small-edit-<%= @comment.cid %>'); | ||
const replyFormOptions = getFileUploadOptions(replyFormBody, false); | ||
const editFormOptions = getFileUploadOptions(editFormBody, false); | ||
const replyButtonOptions = getFileUploadOptions(replyButton, true); | ||
const editButtonOptions = getFileUploadOptions(editButton, true); | ||
replyFormBody.fileupload(replyFormOptions); | ||
editFormBody.fileupload(editFormOptions); | ||
replyButton.fileupload(replyButtonOptions); | ||
editButton.fileupload(editButtonOptions); | ||
|
||
$('#answer-<%= @answer_id %>-comment-section .help-block').remove(); | ||
fileUploadElements.forEach(function(element) { | ||
const options = getFileUploadOptions($(element.selector), element.isButton); | ||
$(element.selector).fileupload(options); | ||
}); | ||
notyNotification('mint', 3000, 'success', 'topRight', 'Comment Added!'); | ||
$('#comment-count')[0].innerHTML = parseInt($('#comment-count')[0].innerHTML, 10)+1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters