From 9cd99fc532096f81cbd3ce9dafd3ebbcd53dfb81 Mon Sep 17 00:00:00 2001 From: Luka Murn Date: Thu, 25 Aug 2016 17:01:30 +0200 Subject: [PATCH] Display "no comments" if you delete the last comment --- app/assets/javascripts/comments.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/comments.js b/app/assets/javascripts/comments.js index 4e20507f9..62fb1c5c3 100644 --- a/app/assets/javascripts/comments.js +++ b/app/assets/javascripts/comments.js @@ -30,13 +30,19 @@ function initDeleteComments(parent) { dataType: "json", success: function(data) { // There are 3 possible actions: - // - (A) comment is the last comment in project (not handled differently) + // - (A) comment is the last comment in project // - (B) comment is the last comment inside specific date (remove the date separator) // - (C) comment is a usual comment + var commentEl = $this.closest(".comment"); - var otherComments = commentEl.siblings(".comment"); + + // Case A + if (commentEl.prevAll(".comment").length == 0 && commentEl.next().length == 0) { + commentEl.after("
  • " + I18n.t("projects.index.no_comments") + "
  • "); + } + + // Case B if (commentEl.prev(".comment-date-separator").length > 0 && commentEl.next(".comment").length == 0) { - // Case B commentEl.prev(".comment-date-separator").remove(); } commentEl.remove();