From b87c930a454f1d3a670f752b9a200acea0e938f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sven=20K=C3=A4stle?= <sven.kaestle@gmx.de> Date: Wed, 11 Jul 2018 00:22:43 +0200 Subject: [PATCH] feat: Add delete button to edit modal --- .../main/webapp/assets/js/annotationScript.js | 39 ++++++++++--------- .../main/webapp/pages/annotation-document.jsp | 3 +- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/gemeinsamforschen/src/main/webapp/assets/js/annotationScript.js b/gemeinsamforschen/src/main/webapp/assets/js/annotationScript.js index 8a71da55..8b817d77 100644 --- a/gemeinsamforschen/src/main/webapp/assets/js/annotationScript.js +++ b/gemeinsamforschen/src/main/webapp/assets/js/annotationScript.js @@ -151,6 +151,25 @@ $(document).ready(function() { } }); + /** + * Delete an annotation from list and server + */ + $('#btnDelete').click(function () { + // get id from edit modal + var id = $('#annotation-edit-modal').data('id'); + + // delte annotation from server and from list + deleteAnnotation(id, function () { + // remove annotation from list + $('#' + id).closest('.listelement').remove() + // remove highlighted text + deleteHighlightedText(); + + // hide and clear the modal + $('#annotation-edit-modal').modal('hide'); + }) + }); + /** * Clear the title and comment input field of the create modal */ @@ -231,14 +250,14 @@ function alterAnnotation(id, annotationPatchRequest, responseHandler) { * * @param id The annotation id */ -function deleteAnnotation(id) { +function deleteAnnotation(id, responseHandler) { var url = "../rest/annotations/" + id; $.ajax({ url: url, type: "DELETE", dataType: "json", success: function (response) { - // Nothing to do + responseHandler(response) } }); } @@ -267,21 +286,6 @@ function getAnnotations(targetId, responseHandler) { }); } -/** - * Delete annotation from list - * - * @param elem The parent li element - * @param id The id of the annotation - */ -function deleteAnnotationHandler(elem, id) { - // remove annotation from list - elem.remove() - // remove highlighted text - deleteHighlightedText(); - // remove annotation from database - deleteAnnotation(id) -} - /** * Display annotation in the list * @@ -601,7 +605,6 @@ function saveNewAnnotation(title, comment, startCharacter, endCharacter) { }); } - /** * Open edit modal with title and comment from given card * diff --git a/gemeinsamforschen/src/main/webapp/pages/annotation-document.jsp b/gemeinsamforschen/src/main/webapp/pages/annotation-document.jsp index db090cfc..36738f2a 100644 --- a/gemeinsamforschen/src/main/webapp/pages/annotation-document.jsp +++ b/gemeinsamforschen/src/main/webapp/pages/annotation-document.jsp @@ -105,7 +105,6 @@ </form> <!-- modal footer --> <div class="modal-footer"> - <button type="button" class="btn btn-secondary" data-dismiss="modal">Abbrechen</button> <button id="btnSave" type="button" class="btn btn-success">Speichern</button> </div> </div> @@ -138,7 +137,7 @@ </form> <!-- modal footer --> <div class="modal-footer"> - <button type="button" class="btn btn-secondary" data-dismiss="modal">Abbrechen</button> + <button id="btnDelete" type="button" class="btn btn-danger">Löschen</button> <button id="btnEdit" type="button" class="btn btn-success">Bearbeiten</button> </div> </div> -- GitLab