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.
This commit is contained in:
Stephan Mühlstrasser 2014-11-04 21:56:09 +01:00
commit 4c2624785f
4 changed files with 15 additions and 6 deletions

View file

@ -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;

View file

@ -286,7 +286,12 @@
<div><xsl:value-of select="."/></div>
</xsl:when>
<xsl:when test="@type = 'file'">
<input class="{$APPCLASS}-{@class}" type="file" data-value="{$type},{$binding}"/>
<form class="{$APPCLASS}-{@class}" data-value="{$type},{$binding}">
<fieldset>
<input type="file"/>
<input type="submit" value="Load Local File" />
</fieldset>
</form>
</xsl:when>
<xsl:when test="@type = 'separator'">
<hr/>