From 303cb4308a1a11518a0728163c84b7c3439f2415 Mon Sep 17 00:00:00 2001 From: zmagod Date: Thu, 22 Sep 2016 13:46:27 +0200 Subject: [PATCH 1/2] fixes load comments [fixes SCI-471] --- app/assets/javascripts/step_result_comments.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/app/assets/javascripts/step_result_comments.js b/app/assets/javascripts/step_result_comments.js index 7b07b4dcd..5f3826de6 100644 --- a/app/assets/javascripts/step_result_comments.js +++ b/app/assets/javascripts/step_result_comments.js @@ -130,9 +130,10 @@ .change(function() { $(".step-save") .on("click", function() { - setTimeout(function() { - initializeComments(); - }, 500); + $(document) + .on('ajax:success', function(){ + initializeComments(); + }); }); }); } else if ( document.getElementById("results") !== null ) { @@ -140,9 +141,10 @@ .change(function() { $(".save-result") .on("click", function() { - setTimeout(function() { - initializeComments(); - }, 500); + $(document) + .on('ajax:success', function(){ + initializeComments(); + }); }); }); } From 0317872bc0875fdcaa7b040375b7b96fa8b7fbfb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Zrim=C5=A1ek?= Date: Thu, 22 Sep 2016 17:57:04 +0200 Subject: [PATCH 2/2] Added check if no comments are present for file result, which caused JS error. --- .../javascripts/step_result_comments.js | 35 ++++++++++--------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/app/assets/javascripts/step_result_comments.js b/app/assets/javascripts/step_result_comments.js index 5f3826de6..306a179a1 100644 --- a/app/assets/javascripts/step_result_comments.js +++ b/app/assets/javascripts/step_result_comments.js @@ -12,23 +12,24 @@ } else if ( $(".result-comment") && $(".result-comment").length > 0 ) { comments = $(".result-comment"); } - $.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")); - animateSpinner(that, false); - }) - .always(function() { - animateSpinner(that, false); - }); - }); + if(!_.isUndefined(comments)) { + $.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); + }); + }); + } } // scroll to the botttom