Andrew Boyson / web

Dependents:   oldheating gps motorhome heating

base/firmware/web-firmware-script.inc

Committer:
andrewboyson
Date:
2019-05-02
Revision:
114:900e33dfa460
Parent:
110:8ab752842d25
Child:
115:24cb6e84ddd6

File content as of revision 114:900e33dfa460:

"'use strict';\n"
"\n"
"var file;\n"
"var xhr;\n"
"\n"
"function logUpload(text)\n"
"{\n"
"    document.getElementById('uploadresult').textContent = text;\n"
"}\n"
"function xhrUploadResponse()\n"
"{\n"
"    var topics = xhr.responseText.split('\\f');\n"
"    logUpload(topics[0]);\n"
"    if (topics.length > 1) document.getElementById('list').textContent = topics[1];\n"
"}\n"
"function xhrUploadOnLoad()\n"
"{\n"
"    if (xhr.status == 200) xhrUploadResponse();\n"
"    else                   logUpload('Upload failed');\n"
"}\n"
"function xhrUploadOnError()\n"
"{\n"
"    logUpload('Upload error');\n"
"}\n"
"function xhrUploadStart()\n"
"{\n"
"    logUpload('Uploading...');\n"
"    \n"
"    xhr = new XMLHttpRequest();\n"
"\n"
"    xhr.onload  = xhrUploadOnLoad;\n"
"    xhr.onerror = xhrUploadOnError;\n"
"\n"
"    xhr.open('POST', '/firmware-ajax'); //Defaults to async=true\n"
"    xhr.send(file);\n"
"}\n"
"\n"
"function startUpload()\n"
"{\n"
"    var fileInput = document.getElementById('fileInput');\n"
"\n"
"    if (fileInput.files.length == 0)\n"
"    {\n"
"        logUpload('Please choose a file');\n"
"        return;\n"
"    }\n"
"\n"
"    if (fileInput.files.length > 1)\n"
"    {\n"
"        logUpload('Please choose just one file');\n"
"        return;\n"
"    }\n"
"    \n"
"    file = fileInput.files[0];\n"
"    \n"
"    xhrUploadStart();\n"
"}\n"
"function logRestart(text)\n"
"{\n"
"    document.getElementById('restartresult').textContent = text;\n"
"}\n"
"function redirect()\n"
"{\n"
"    location.href = '/firmware';\n"
"}\n"
"function xhrRestartOnLoad()\n"
"{\n"
"    if (xhr.status == 200) logRestart('Restart should never have returned');\n"
"    else                   logRestart('Restart failed');\n"
"}\n"
"function xhrRestartStart()\n"
"{\n"
"    logRestart('Restarting...');\n"
"    \n"
"    xhr = new XMLHttpRequest();\n"
"\n"
"    xhr.onload  = xhrRestartOnLoad;\n"
"\n"
"    xhr.open('GET', '/firmware-ajax?restart='); //Defaults to async=true\n"
"    xhr.send();\n"
"    \n"
"    setTimeout(redirect, 2000);\n"
"}\n"
"function restart()\n"
"{\n"
"    xhrRestartStart();\n"
"}\n"
"function resetPassword()\n"
"{\n"
"    xhr = new XMLHttpRequest();\n"
"\n"
"    xhr.onload  = xhrRestartOnLoad;\n"
"\n"
"    xhr.open('GET', '/firmware-ajax?resetpassword='); //Defaults to async=true\n"
"    xhr.send();\n"
"    \n"
"    location.href = '/firmware';\n"
"}\n"
""