Fixed client side code to adopt filename from event stream

Change-Id: I7a71f1ef77f7beea6bc335d9d2889e798b973838
diff --git a/plugin/src/main/resources/assets/export.js b/plugin/src/main/resources/assets/export.js
index e612ead..bc4b6c2 100644
--- a/plugin/src/main/resources/assets/export.js
+++ b/plugin/src/main/resources/assets/export.js
@@ -43,7 +43,7 @@
     const form = e.target;
     const url = new URL(form.action !== undefined ? form.action : "", location);
     const query = url.searchParams;
-
+    
     let field;
     let inputs = form.querySelectorAll("input:not([type=radio]):not([type=checkbox])");
     for (let i = 0; i < inputs.length; i++) {
@@ -60,7 +60,7 @@
         query.append(inputs[i].name, inputs[i].value)
       };
     };
-
+    
     reqStream(url.href);
     return false;
   };
@@ -69,34 +69,66 @@
 
 // Create an eventsource listener for target
 function reqStream (target) {
+
+  let relocationURL;
+
   const sse = new EventSource(target);
   const prog = document.getElementById('progress');
+
   sse.addEventListener('Progress', function (e) {
     prog.value = e.data;
     prog.textualData = e.data + "%";
   });
+
   sse.addEventListener('Error', function (e) {
     prog.style.display = "none";
     sse.close();
-    window.plugin.log(0, e.data);
+    window.Plugin.log(0, e.data);
   });
+
   sse.addEventListener('Relocate', function (e) {
-    window.Plugin.log(0,e.data);
+    if (e.data == undefined || e.data.length == 0) {
+      window.Plugin.log(0,"Unable to export file");
+      return;
+    };
+
+    const data = e.data.split(";");
+
+    if (data.length == 2 && data[0]) {
+
+      relocationURL = new URL(target);
+      relocationURL.search = '';
+      relocationURL.pathname += '/' + data[0];
+
+      if (data[1] != null && data[1].length > 0) {
+        relocationURL.searchParams.append("fname",data[1]);
+      };
+      
+      return;
+    };
+
+    window.Plugin.log(0,"Unable to export file");
+    
     // Todo:
     //   Start a timer to automatically close
     //   the eventsource
+
   });
+
   sse.addEventListener('Process', function (e) {
     prog.style.display = "block";
     if (e.data == "init") {
-      prog.value = 0;
-      prog.textualData = "0%";
+      prog.value = 1;
+      prog.textualData = "1%";
       window.Plugin.resize();
     }
     else if (e.data == 'done') {
       sse.close();
       prog.value = 100;
       prog.textualData = "100%";
+
+      if (relocationURL != null)
+        location.href = relocationURL.href;
     }
   });
 };
diff --git a/plugin/src/main/resources/assets/templates/export.ftl b/plugin/src/main/resources/assets/templates/export.ftl
index 8a1ccd7..e19950c 100644
--- a/plugin/src/main/resources/assets/templates/export.ftl
+++ b/plugin/src/main/resources/assets/templates/export.ftl
@@ -60,9 +60,9 @@
             <input name="hitc" id="hitc" type="number" min="1" max="10000" value="20" />
           </fieldset>
 
-          <input type="submit" value="Exportieren">
-
           <progress id="progress" value="0" max="100" style="display: none;">0%</progress>
+          
+          <input type="submit" value="Exportieren">
 
         </fieldset>
       </form>
diff --git a/plugin/src/main/resources/exportPlugin.conf b/plugin/src/main/resources/exportPlugin.conf
index 0d3374a..d36cb15 100644
--- a/plugin/src/main/resources/exportPlugin.conf
+++ b/plugin/src/main/resources/exportPlugin.conf
@@ -19,4 +19,7 @@
 # TODO: Define this constants after discussing it. 
 # Maybe we need a distinction between users at the IDS and external users
 # See also: https://www.ids-mannheim.de/cosmas2/script-app/hilfe/sitzung.html
-conf.max_exp_limit=10000
\ No newline at end of file
+conf.max_exp_limit=10000
+
+# The file directory to serve from
+# conf.file_dir=./files/
\ No newline at end of file