diff --git a/app/assets/javascripts/comments.js.erb b/app/assets/javascripts/comments.js.erb index bfdc5a599..b1a694f26 100644 --- a/app/assets/javascripts/comments.js.erb +++ b/app/assets/javascripts/comments.js.erb @@ -16,18 +16,21 @@ var Comments = (function() { $.each(comments, function(){ var that = $(this); var link = that.attr('data-href'); - $.ajax({ method: 'GET', - url: link, - beforeSend: animateSpinner(that, true) }) - .done(function(data) { - that.html(data.html); - initCommentForm(that); - initCommentsLink(that); - scrollBottom(that.find('.content-comments')); - }) - .always(function() { - animateSpinner(that, false); - }); + if(that.html().length === 0) { + $.ajax({ method: 'GET', + url: link, + beforeSend: animateSpinner(that, true) }) + .done(function(data) { + that.html(data.html); + + }) + .always(function() { + animateSpinner(that, false); + }); + } + initCommentForm(that); + initCommentsLink(that); + scrollBottom(that.find('.content-comments')); }); } } @@ -238,7 +241,8 @@ var Comments = (function() { } function initDeleteComments(parent) { - $(parent).on('click', '[data-action=delete-comment]', function() { + $(parent).on('click', '[data-action=delete-comment]', function(ev) { + ev.preventDefault(); var $this = $(this); if (confirm($this.attr('data-confirm-message'))) { $.ajax({ diff --git a/app/controllers/result_comments_controller.rb b/app/controllers/result_comments_controller.rb index 6d4c48544..f96febdfc 100644 --- a/app/controllers/result_comments_controller.rb +++ b/app/controllers/result_comments_controller.rb @@ -18,9 +18,9 @@ class ResultCommentsController < ApplicationController # messages. 'list' partial is used for showing more # comments. partial = 'index.html.erb' - partial = 'list.html.erb' if @last_comment_id > 0 + partial = 'list.html.erb' if @last_comment_id.positive? more_url = '' - if @comments.count > 0 + if @comments.size.positive? more_url = url_for(result_result_comments_path(@result, format: :json, from: @comments @@ -28,11 +28,14 @@ class ResultCommentsController < ApplicationController end render json: { perPage: @per_page, - resultsNumber: @comments.length, + resultsNumber: @comments.size, moreUrl: more_url, - html: render_to_string(partial: partial, - locals: { comments: @comments, - more_comments_url: more_url }) + html: render_to_string( + partial: partial, + locals: { + result: @result, comments: @comments, per_page: @per_page + } + ) } end end diff --git a/app/controllers/step_comments_controller.rb b/app/controllers/step_comments_controller.rb index 713592122..825479b6a 100644 --- a/app/controllers/step_comments_controller.rb +++ b/app/controllers/step_comments_controller.rb @@ -19,20 +19,21 @@ class StepCommentsController < ApplicationController # messages. 'list' partial is used for showing more # comments. partial = 'index.html.erb' - partial = 'list.html.erb' if @last_comment_id > 0 + partial = 'list.html.erb' if @last_comment_id.positive? more_url = '' - if @comments.count > 0 + if @comments.size.positive? more_url = url_for(step_step_comments_path(@step, format: :json, from: @comments.first.id)) end render json: { perPage: @per_page, - resultsNumber: @comments.length, + resultsNumber: @comments.size, moreUrl: more_url, - html: render_to_string(partial: partial, - locals: { comments: @comments, - more_comments_url: more_url }) + html: render_to_string( + partial: partial, + locals: { step: @step, comments: @comments, per_page: @per_page } + ) } end end diff --git a/app/views/comments/_edit.html.erb b/app/views/comments/_edit.html.erb index 3ff6603cf..b756f358e 100644 --- a/app/views/comments/_edit.html.erb +++ b/app/views/comments/_edit.html.erb @@ -14,6 +14,6 @@ - <%= t('general.cancel') %> + <%= t('general.cancel') %> <% end %> diff --git a/app/views/my_modules/_result.html.erb b/app/views/my_modules/_result.html.erb index 66a9c2b3f..40fb1268e 100644 --- a/app/views/my_modules/_result.html.erb +++ b/app/views/my_modules/_result.html.erb @@ -51,6 +51,8 @@