From 6677a2faac6ff1b15d669e2a53c22a7f06e85c80 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Sven=20K=C3=A4stle?= <sven.kaestle@gmx.de>
Date: Sat, 8 Sep 2018 16:29:31 +0200
Subject: [PATCH] refactor: Switch from 'getValueFromUrl' to 'getQueryVariable'

---
 .../src/main/webapp/assets/js/annotationScript.js      | 10 +++++-----
 .../src/main/webapp/assets/js/project-student.js       |  6 +++---
 .../main/webapp/assets/js/unstructuredAnnotation.js    |  4 ++--
 .../src/main/webapp/assets/js/unstructuredUpload.js    |  4 ++--
 gemeinsamforschen/src/main/webapp/assets/js/utility.js |  2 +-
 5 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/gemeinsamforschen/src/main/webapp/assets/js/annotationScript.js b/gemeinsamforschen/src/main/webapp/assets/js/annotationScript.js
index d49f38cd..52fcbdda 100644
--- a/gemeinsamforschen/src/main/webapp/assets/js/annotationScript.js
+++ b/gemeinsamforschen/src/main/webapp/assets/js/annotationScript.js
@@ -9,11 +9,11 @@ var startCharacter, endCharacter;
  * This function will fire when the DOM is ready
  */
 $(document).ready(function() {
-    let fullSubmissionId = getValueFromUrl("fullSubmissionId");
-    let category = getValueFromUrl("category");
+    let fullSubmissionId = getQueryVariable("fullSubmissionId");
+    let category = getQueryVariable("category");
 
     // fetch full submission from database
-    getFullSubmission(getValueFromUrl("fullSubmissionId"), function (response) {
+    getFullSubmission(getQueryVariable("fullSubmissionId"), function (response) {
 
         // set text
         $('#documentText').html(response.text);
@@ -610,8 +610,8 @@ function toggleButtonHandler(id) {
 function saveNewAnnotation(title, comment, startCharacter, endCharacter) {
 
     // initialize target
-    let targetId = getValueFromUrl("fullSubmissionId");
-    let targetCategory = getValueFromUrl("category");
+    let targetId = getQueryVariable("fullSubmissionId");
+    let targetCategory = getQueryVariable("category");
     let userToken = getUserTokenFromUrl();
 
     // build annotationPostRequest
diff --git a/gemeinsamforschen/src/main/webapp/assets/js/project-student.js b/gemeinsamforschen/src/main/webapp/assets/js/project-student.js
index 52d70fce..520600a9 100644
--- a/gemeinsamforschen/src/main/webapp/assets/js/project-student.js
+++ b/gemeinsamforschen/src/main/webapp/assets/js/project-student.js
@@ -1,6 +1,6 @@
 $(document).ready(function(){
     // fetch all submission part project representations from database
-    getSubmissionPartsByProjectId(getValueFromUrl("projectId"), function (response) {
+    getSubmissionPartsByProjectId(getQueryVariable("projectId"), function (response) {
         
         // iterate over response and display each element
         for (let i = 0; i < response.length; i++) {
@@ -12,7 +12,7 @@ $(document).ready(function(){
             let fullSubmissionId = $(this).closest("li").data("fullSubmissionId");
             let category = $(this).closest("li").data("category");
             location.href="annotation-document.jsp?token=" + getUserTokenFromUrl() +
-                "&projectId=" + getValueFromUrl("projectId") +
+                "&projectId=" + getQueryVariable("projectId") +
                 "&fullSubmissionId=" + fullSubmissionId +
                 "&category=" + category;
         });
@@ -37,7 +37,7 @@ $(document).ready(function(){
     });
 
     $('#btnUnstructuredUpload').click(function () {
-        location.href="unstructured-upload.jsp?token="+getUserTokenFromUrl() + "&projectId=" + getValueFromUrl("projectId");
+        location.href="unstructured-upload.jsp?token="+getUserTokenFromUrl() + "&projectId=" + getQueryVariable("projectId");
     })
 });
 
diff --git a/gemeinsamforschen/src/main/webapp/assets/js/unstructuredAnnotation.js b/gemeinsamforschen/src/main/webapp/assets/js/unstructuredAnnotation.js
index ce860a82..f420bbbd 100644
--- a/gemeinsamforschen/src/main/webapp/assets/js/unstructuredAnnotation.js
+++ b/gemeinsamforschen/src/main/webapp/assets/js/unstructuredAnnotation.js
@@ -26,7 +26,7 @@ $(document).ready(function() {
 
     }, function () {
         // jump to upload page on error
-        location.href="unstructured-upload.jsp?token=" + getUserTokenFromUrl() + "&projectId=" + getValueFromUrl("projectId");
+        location.href="unstructured-upload.jsp?token=" + getUserTokenFromUrl() + "&projectId=" + getQueryVariable("projectId");
     });
 
     // set click listener to save button
@@ -285,7 +285,7 @@ function saveButtonHandler() {
 
         $.when.apply($, promises).then(function () {
             // redirect user to project page after saving
-            location.href="project-student.jsp?token=" + getUserTokenFromUrl() + "&projectId=" + getValueFromUrl("projectId");
+            location.href="project-student.jsp?token=" + getUserTokenFromUrl() + "&projectId=" + getQueryVariable("projectId");
         });
 
         // redirect user to project page after saving
diff --git a/gemeinsamforschen/src/main/webapp/assets/js/unstructuredUpload.js b/gemeinsamforschen/src/main/webapp/assets/js/unstructuredUpload.js
index a024e123..66ef3253 100644
--- a/gemeinsamforschen/src/main/webapp/assets/js/unstructuredUpload.js
+++ b/gemeinsamforschen/src/main/webapp/assets/js/unstructuredUpload.js
@@ -14,7 +14,7 @@ $(document).ready(function() {
             var fullSubmissionPostRequest = {
                 user: user,
                 text: text,
-                projectId: getValueFromUrl("projectId")
+                projectId: getQueryVariable("projectId")
             };
 
             // save request in database
@@ -23,7 +23,7 @@ $(document).ready(function() {
                 $('#upload-textarea').val("");
 
                 // jump to next page
-                location.href="unstructured-annotation.jsp?token=" + getUserTokenFromUrl() + "&projectId=" + getValueFromUrl("projectId") + "&submission=" + response.id;
+                location.href="unstructured-annotation.jsp?token=" + getUserTokenFromUrl() + "&projectId=" + getQueryVariable("projectId") + "&submission=" + response.id;
             });
         }
     });
diff --git a/gemeinsamforschen/src/main/webapp/assets/js/utility.js b/gemeinsamforschen/src/main/webapp/assets/js/utility.js
index 40197ba6..31e65be1 100644
--- a/gemeinsamforschen/src/main/webapp/assets/js/utility.js
+++ b/gemeinsamforschen/src/main/webapp/assets/js/utility.js
@@ -13,7 +13,7 @@ function getUserTokenFromUrl() {
 
 }
 
-function getValueFromUrl(name) {
+function getQueryVariable(name) {
     var parts = window.location.search.substr(1).split("&");
     var $_GET = {};
     for (var i = 0; i < parts.length; i++) {
-- 
GitLab