From d7603f5e20faa8e6b3de4c8a979b65a6814cdd5f Mon Sep 17 00:00:00 2001 From: noi5e Date: Mon, 15 Feb 2021 08:37:31 -0800 Subject: [PATCH] Merge comments/edit & comments/form Partials (#9183) * merge comments/_edit & comments/_form partials * delete templates functionality * merge comments/_edit & comments/_form partials; change #edit-comment-form-wrapper to #comment-form-wrapper-edit * stop attaching ajax:event to edit forms * stop running scripts on edit forms * add hidden_field_tag for reply_to --- app/assets/javascripts/comment.js | 10 +- app/views/comments/_edit.html.erb | 104 -------------- app/views/comments/_form.html.erb | 209 ++++++++++++++++++++--------- app/views/editor/_toolbar.html.erb | 13 -- app/views/notes/_comment.html.erb | 13 +- 5 files changed, 163 insertions(+), 186 deletions(-) delete mode 100644 app/views/comments/_edit.html.erb diff --git a/app/assets/javascripts/comment.js b/app/assets/javascripts/comment.js index 039b5af104..6fb1f75fa3 100644 --- a/app/assets/javascripts/comment.js +++ b/app/assets/javascripts/comment.js @@ -1,6 +1,8 @@ $(function() { + // attach AJAX eventHandlers to comment forms for form submission + // EXCEPT for edit comment forms (those don't use AJAX form submission) $('.comment-form').each(function() { - if(!$(this).hasClass('bound-success')) { + if(!$(this).hasClass('bound-success') && !$(this).hasClass('edit-comment-form')) { $(this).addClass('bound-success').on('ajax:success', function(e, data, status, xhr){ $(this).find('.text-input').prop('disabled',false); $(this).find('.text-input').val(''); @@ -12,7 +14,7 @@ $(function() { }); } - if(!$(this).hasClass('bound-beforeSend')) { + if(!$(this).hasClass('bound-beforeSend') && !$(this).hasClass('edit-comment-form')) { $(this).addClass('bound-beforeSend').on('ajax:beforeSend', function(event){ $(this).find(".text-input").prop('disabled',true) $(this).find('.text-input').val(''); @@ -20,7 +22,7 @@ $(function() { }); } - if(!$(this).hasClass('bound-error')) { + if(!$(this).hasClass('bound-error') && !$(this).hasClass('edit-comment-form')) { $(this).addClass('bound-error').on('ajax:error', function(e,response){ notyNotification('mint', 3000, 'error', 'topRight', 'Some error occured while adding comment'); $(this).find('.text-input').prop('disabled',false); @@ -31,7 +33,7 @@ $(function() { }); } - if(!$(this).hasClass('bound-keypress')) { + if(!$(this).hasClass('bound-keypress') && !$(this).hasClass('edit-comment-form')) { $(this).addClass('bound-keypress'); $(this).find('.text-input').val(''); diff --git a/app/views/comments/_edit.html.erb b/app/views/comments/_edit.html.erb deleted file mode 100644 index 588f03495d..0000000000 --- a/app/views/comments/_edit.html.erb +++ /dev/null @@ -1,104 +0,0 @@ - \ No newline at end of file diff --git a/app/views/comments/_form.html.erb b/app/views/comments/_form.html.erb index f64ec05607..4c9400c699 100644 --- a/app/views/comments/_form.html.erb +++ b/app/views/comments/_form.html.erb @@ -1,118 +1,186 @@ + +<% comment_id_string = comment ? comment.id.to_s : nil %> -<% comment_form_id = get_comment_form_id(location, local_assigns[:reply_to], nil) %> -
-
" <% if local_assigns[:aid].blank? %>method="post"<% end %>> - <% if current_user && current_user.id == @node.uid %> - - Add a template - +<% comment_form_id = get_comment_form_id(location, local_assigns[:reply_to], comment_id_string) %> +
+ " +> + + action = "/comment/update/<%= comment.id %>" + class="edit-comment-form well" + style="display: none;" + <% else %> + action="/comment/create/<%= @node.nid %>" + class="comment-form" + <%# data-remote="true" means the form is submitted with AJAX %> + <%# see https://guides.rubyonrails.org/working_with_javascript_in_rails.html#remote-elements %> + data-remote="true" <% end %> -

<%= title %>

+ method="post" + > +

+ <%= title %> +

+ - + - <% locals = (location == :reply) ? - { :location => location, :reply_to => reply_to } : - { :location => location } - %> + <% locals = {} %> + <% locals[:location] = location %> + <% locals[:reply_to] = reply_to if location == :reply %> + <% locals[:comment_id] = comment.id.to_s if comment %> <%= render :partial => "editor/toolbar", :locals => locals %> - <% if local_assigns[:reply_to].present? %> <%= hidden_field_tag :reply_to, local_assigns[:reply_to] %> <% end %> - - - -
- <% - body = body || params[:body] - # Look for comment templates - if params[:body].nil? && @node && @node.has_power_tag('comment-template') - body = Node.find_by(slug: @node.power_tag('comment-template')).try(:body) - end - %> - <% if is_new_contributor %> + + +
+ <% if location != :edit && is_new_contributor %>
<% cache('feature_welcome-msg', skip_digest: true) do %> <%= feature("welcome-msg") %> <% end %>
<% end %> - + placeholder="<%= placeholder %>" + ><%= location == :edit ? comment.comment : params[:body] %>

- - - + + -

-