From 4c2624785f6bdfad002659ebce6e9625c5a75327 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20M=C3=BChlstrasser?= Date: Tue, 4 Nov 2014 21:56:09 +0100 Subject: [PATCH] Implement local file upload with form. This fixes the issue that after selecting a file it cannot be uploaded directly again without selecting another file in between. --- configs/c1p/serial/all.xml | 2 +- configs/c1p/serial/samples.xml | 2 +- my_modules/c1pjs-client/lib/serial.js | 10 +++++++--- my_modules/c1pjs-client/templates/components.xsl | 7 ++++++- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/configs/c1p/serial/all.xml b/configs/c1p/serial/all.xml index b4372ece7..7833c5e49 100644 --- a/configs/c1p/serial/all.xml +++ b/configs/c1p/serial/all.xml @@ -21,5 +21,5 @@ SPACEWAR Load File - + diff --git a/configs/c1p/serial/samples.xml b/configs/c1p/serial/samples.xml index 49900f086..bb0b268be 100644 --- a/configs/c1p/serial/samples.xml +++ b/configs/c1p/serial/samples.xml @@ -10,5 +10,5 @@ PRESIDENTS Load File - + diff --git a/my_modules/c1pjs-client/lib/serial.js b/my_modules/c1pjs-client/lib/serial.js index 71c2f9cdc..bf51851b5 100644 --- a/my_modules/c1pjs-client/lib/serial.js +++ b/my_modules/c1pjs-client/lib/serial.js @@ -127,15 +127,19 @@ C1PSerialPort.prototype.setBinding = function(c, t, s, e) case "uploadSerial": this.bindings[s] = e; var serial = this; - e.addEventListener('change', function () { - var file = e.files[0]; + e.onsubmit = function (event) { + var file = event.currentTarget[1].files[0]; + var reader = new FileReader(); reader.onload = function () { // serial.println("uploading " + file.name + "..."); serial.loadFile(file.name, reader.result, 0); }; reader.readAsText(file); - }); + + // Prevent reloading of web page after form submission + return false; + }; return true; default: break; diff --git a/my_modules/c1pjs-client/templates/components.xsl b/my_modules/c1pjs-client/templates/components.xsl index ec4a38463..b333923b3 100644 --- a/my_modules/c1pjs-client/templates/components.xsl +++ b/my_modules/c1pjs-client/templates/components.xsl @@ -286,7 +286,12 @@
- +
+
+ + +
+