Browse Source

www: redirect to the status page after a configuration change

Redirect to the status page after a successful configuration change.
H. Peter Anvin 2 years ago
parent
commit
c59bb75269
7 changed files with 14 additions and 15 deletions
  1. 1 1
      esp32/max80/reboot.c
  2. BIN
      esp32/output/max80.ino.bin
  3. 2 1
      esp32/www/config.html
  4. 9 11
      esp32/www/max80.js
  5. 2 2
      esp32/www/update.html
  6. BIN
      fpga/output/v1.fw
  7. BIN
      fpga/output/v2.fw

+ 1 - 1
esp32/max80/reboot.c

@@ -11,7 +11,7 @@ void reboot_now(void)
 
 int reboot_delayed(void)
 {
-    const int reboot_delay = 5; /* seconds */
+    const int reboot_delay = 3; /* seconds */
     TimerHandle_t timer;
 
     timer = xTimerCreate("reboot", configTICK_RATE_HZ*reboot_delay,

BIN
esp32/output/max80.ino.bin


+ 2 - 1
esp32/www/config.html

@@ -8,7 +8,8 @@
   <body>
     <x-inc src="head.html"></x-inc>
     <h1 class="config">Configuration</h1>
-    <form id="setconfig" action="sys/setconfig" method="post" onsubmit="uploadform()">
+    <form id="setconfig" action="sys/setconfig" method="post"
+	  onsubmit="uploadform()" data-ref="10" data-ref-url="status.html">
       <fieldset class="network">
 	<legend>Network</legend>
 	<label class="wifi-ssid">

+ 9 - 11
esp32/www/max80.js

@@ -119,7 +119,8 @@ function load(url,html = false)
 	.catch(() => {});
 }
 
-// POST upload of data from within a form, with progress and response text
+// POST upload of data from within a form, with (optional)
+// progress and response text, and redirect after success
 function upload(form,data) {
     var xhr = new XMLHttpRequest();
 
@@ -165,15 +166,6 @@ function upload(form,data) {
     return xhr;
 }
 
-// Upload a data file blob
-function uploadfile() {
-    event.preventDefault();
-    const form = event.target.form || event.target;
-    var files = form.elements['file'];
-    return (files.files.length == 1)
-	? upload(form,files.files[0]) : files.click();
-}
-
 // key=value formatting of form data; including inverted checkboxes
 function textformdata(form) {
     var data = '';
@@ -196,7 +188,13 @@ function textformdata(form) {
 function uploadform() {
     event.preventDefault();
     const form = event.target.form || event.target;
-    return upload(form,textformdata(form));
+    var files = form.elements['file'];
+    if (files == undefined)
+	return upload(form,textformdata(form));
+    else if (files.files.length == 1)
+	return upload(form,files.files[0]);
+    else
+	return files.click();
 }
 
 // Flip the status of an INPUT element between text and password

+ 2 - 2
esp32/www/update.html

@@ -9,10 +9,10 @@
     <x-inc src="head.html"></x-inc>
     <h1 class="update">Update</h1>
     <form id="upload" action="sys/fwupdate" method="post"
-	  onsubmit="uploadfile()" data-ref="10" data-ref-url="status.html">
+	  onsubmit="uploadform()" data-ref="10" data-ref-url="status.html">
       <fieldset class="fw">
 	<legend>Firmware</legend>
-	<input type="file" name="file" hidden accept=".fw" onchange="uploadfile()" />
+	<input type="file" name="file" hidden accept=".fw" onchange="uploadform()" />
 	<button type="submit" class="fromfile" id="upload.start"
 		onclick="sib(this,'input').value=''">Update from file</button>
 	<progress value="0"></progress>

BIN
fpga/output/v1.fw


BIN
fpga/output/v2.fw