From 7cffbef9e2ae537353e70e077628b6d1e82ba1ea Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Sat, 10 Nov 2018 23:15:35 +0400 Subject: [PATCH] delete paper --- src/main/resources/public/js/papers.js | 41 +++++++++++++++++-- .../resources/templates/papers/papers.html | 18 ++++++-- 2 files changed, 52 insertions(+), 7 deletions(-) diff --git a/src/main/resources/public/js/papers.js b/src/main/resources/public/js/papers.js index b2b81a6..3b78d8a 100644 --- a/src/main/resources/public/js/papers.js +++ b/src/main/resources/public/js/papers.js @@ -1,19 +1,52 @@ var urlPapers = "/api/1.0/papers"; var urlPaperStatuses = "/api/1.0/papers/statuses"; +var urlDeletePaper = "/api/1.0/papers/"; -function showPapers(papersElement) { +function showPapers(papersElement, paperRowClass) { getFromRest(urlPapers, function (paperList) { paperList.forEach(function (paper, index) { - $(papersElement).parent().append("
" + - "
" + + $(papersElement).parent().append("
" + + "
" + " \n" + " " + " " + " " + " " + paper.title + "" + + "'>" + paper.title + "
" + + "
" + + "" + + "" + "
"); }); + + $(paperRowClass).mouseenter(function (event) { + var paperRow = $(event.target).closest(paperRowClass); + $(paperRow).css("background-color", "#f8f9fa"); + $(paperRow).find(".remove-paper").removeClass("d-none"); + + }); + $(paperRowClass).mouseleave(function (event) { + var paperRow = $(event.target).closest(paperRowClass); + $(paperRow).css("background-color", "white"); + $(paperRow).closest(paperRowClass).find(".remove-paper").addClass("d-none"); + }); + }); +} + +function deletePaper(id, papersElement, paperRowClass) { + $("#remove-paper-modal").modal('show'); + + $("#modal-btn-yes").on("click", function () { + deleteFromRest(urlDeletePaper + id, function () { + showFeedbackMessage("Статья удалена"); + $(paperRowClass).remove(); + showPapers(papersElement, paperRowClass); + }); + $("#remove-paper-modal").modal('hide'); + }); + + $("#modal-btn-no").on("click", function () { + $("#remove-paper-modal").modal('hide'); }); } diff --git a/src/main/resources/templates/papers/papers.html b/src/main/resources/templates/papers/papers.html index 83cf15a..1c5322a 100644 --- a/src/main/resources/templates/papers/papers.html +++ b/src/main/resources/templates/papers/papers.html @@ -28,12 +28,24 @@
+