Add file input for data reading

This commit is contained in:
Codrin Pavel
2019-11-30 21:55:29 +02:00
parent 317b7e6ef8
commit 128b603153
7 changed files with 39 additions and 11 deletions

17
_assets/js/file_reader.js Normal file
View File

@@ -0,0 +1,17 @@
function getFileContents(file) {
var file = document.getElementById("fileUpload").files[0];
var fileContents = false;
if (file) {
var reader = new FileReader();
reader.readAsText(file, "UTF-8");
reader.onload = function (evt) {
var warData = JSON.parse(evt.target.result);
initApp(warData, 'withSave', warData);
}
reader.onerror = function (evt) {
console.error('error reading the file.')
}
}
}