Merge pull request #7 from smuehlst/c1pserialupload
Add "Load Local File" feature to C1Pjs
This commit is contained in:
commit
c1bfb436a3
4 changed files with 44 additions and 0 deletions
|
|
@ -21,4 +21,5 @@
|
|||
<item ref="/sites/www.osiweb.org/programs/basic/OsiBas/spacewar.bas">SPACEWAR</item>
|
||||
</control>
|
||||
<control type="button" class="input" binding="loadSerial">Load File</control>
|
||||
<control type="file" class="input" binding="uploadSerial"/>
|
||||
</serial>
|
||||
|
|
|
|||
|
|
@ -10,4 +10,5 @@
|
|||
<item ref="/apps/c1p/BASIC/OSI/SAMPLE6.BAS">PRESIDENTS</item>
|
||||
</control>
|
||||
<control type="button" class="input" binding="loadSerial">Load File</control>
|
||||
<control type="file" class="input" binding="uploadSerial"/>
|
||||
</serial>
|
||||
|
|
|
|||
|
|
@ -124,6 +124,40 @@ C1PSerialPort.prototype.setBinding = function(c, t, s, e)
|
|||
};
|
||||
}(this);
|
||||
return true;
|
||||
case "uploadSerial":
|
||||
// Check for availability of FileReader
|
||||
if (window.FileReader && window.File && window.FileList && window.Blob ) {
|
||||
var serial = this;
|
||||
this.bindings[s] = e;
|
||||
|
||||
// Enable "Load Local File" button only if a file is actually selected
|
||||
e.addEventListener('change', function () {
|
||||
var fieldset = e.children[0];
|
||||
var files = fieldset.children[0].files;
|
||||
var submit = fieldset.children[1];
|
||||
|
||||
submit.disabled = (files.length == 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.toString(), 0);
|
||||
};
|
||||
reader.readAsText(file);
|
||||
|
||||
// Prevent reloading of web page after form submission
|
||||
return false;
|
||||
};
|
||||
}
|
||||
else {
|
||||
this.println("FileReader support not available, disabling local file upload");
|
||||
e.parentNode.removeChild(e);
|
||||
}
|
||||
return true;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -285,6 +285,14 @@
|
|||
<xsl:when test="@type = 'heading'">
|
||||
<div><xsl:value-of select="."/></div>
|
||||
</xsl:when>
|
||||
<xsl:when test="@type = 'file'">
|
||||
<form class="{$APPCLASS}-{@class}" data-value="{$type},{$binding}">
|
||||
<fieldset>
|
||||
<input type="file"/>
|
||||
<input type="submit" value="Load Local File" disabled="true"/>
|
||||
</fieldset>
|
||||
</form>
|
||||
</xsl:when>
|
||||
<xsl:when test="@type = 'separator'">
|
||||
<hr/>
|
||||
</xsl:when>
|
||||
|
|
|
|||
Loading…
Reference in a new issue