diff --git a/gemeinsamforschen/src/main/webapp/assets/js/unstructuredUpload.js b/gemeinsamforschen/src/main/webapp/assets/js/unstructuredUpload.js index eee1a0da02430822ee70e9378b2916c5e88ff287..0eeb2e903b92c0397cf7a10c7ad815bc924ab179 100644 --- a/gemeinsamforschen/src/main/webapp/assets/js/unstructuredUpload.js +++ b/gemeinsamforschen/src/main/webapp/assets/js/unstructuredUpload.js @@ -5,12 +5,45 @@ $(document).ready(function() { $('#btnNext').click(function () { if ($('#upload-textarea-form').valid()) { - location.href="project-student.jsp?token="+getUserTokenFromUrl(); + + // fetch user and text + let user = getUserTokenFromUrl(); + let text = $('#upload-textarea').val(); + + // build request + var fullSubmissionPostRequest = { + user: user, + text: text + }; + + // save request in database + createFullSubmission(fullSubmissionPostRequest, function (response) { + // clear textarea + $('#upload-textarea').val(""); + + // jump to next page + location.href="project-student.jsp?token=" + getUserTokenFromUrl() + "&submission=" + response.id; + }); } }); $('#btnBack').click(function () { - location.href="project-student.jsp?token="+getUserTokenFromUrl(); + // if there is text inside the textarea + if ($('#upload-textarea').val().trim().length > 0) { + // show user alert message that the text will be lost + if (window.confirm("Möchten Sie zur vorherigen Seite zurückkehren? \nIhr bisheriger Text wird nicht gespeichert.")) { + // clear textarea + $('#upload-textarea').val(""); + + // jump to previous page + location.href="project-student.jsp?token="+getUserTokenFromUrl(); + } + } + // nothing to check + else { + // jump to previous page + location.href="project-student.jsp?token="+getUserTokenFromUrl(); + } }); /** diff --git a/gemeinsamforschen/src/main/webapp/assets/js/unstructuredUploadRest.js b/gemeinsamforschen/src/main/webapp/assets/js/unstructuredUploadRest.js new file mode 100644 index 0000000000000000000000000000000000000000..e3fab82bcdcc3684d598805b093f01f4d4b874bd --- /dev/null +++ b/gemeinsamforschen/src/main/webapp/assets/js/unstructuredUploadRest.js @@ -0,0 +1,39 @@ +/** + * POST: Save an full submission in the database + * + * @param fullSubmissionPostRequest The post request + * @param responseHandler The response handler + */ +function createFullSubmission(fullSubmissionPostRequest, responseHandler) { + var url = "../rest/submissions/full/"; + var json = JSON.stringify(fullSubmissionPostRequest); + $.ajax({ + url: url, + type: "POST", + data: json, + contentType: "application/json", + dataType: "json", + success: function (response) { + responseHandler(response); + } + }); +} + +/** + * GET: Get a specific full submission for a given id + * + * @param id The id of the full submission + * @param responseHandler The response handler + */ +function getAnnotation(id, responseHandler) { + var url = "../rest/submissions/full/" + id; + $.ajax({ + url: url, + type: "GET", + dataType: "json", + success: function (response) { + // handle the response + responseHandler(response); + } + }) +} \ No newline at end of file diff --git a/gemeinsamforschen/src/main/webapp/pages/unstructured-upload.jsp b/gemeinsamforschen/src/main/webapp/pages/unstructured-upload.jsp index 562b0340f07d1e4ab71ee674b8948e13e5d81427..b8746eab0c3c624f39a1cc11094080f1079b074f 100644 --- a/gemeinsamforschen/src/main/webapp/pages/unstructured-upload.jsp +++ b/gemeinsamforschen/src/main/webapp/pages/unstructured-upload.jsp @@ -16,8 +16,10 @@ <!-- css - upload-unstructured --> <link rel="stylesheet" type="text/css" href="../assets/css/unstructured-upload.css"> - <!-- js - annotationScript --> + <!-- js - unstructuredUpload --> <script src="../assets/js/unstructuredUpload.js"></script> + <!-- js - unstructuredUploadRest --> + <script src="../assets/js/unstructuredUploadRest.js"></script> </head>