html_confTime.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /* clang-format off */
  2. //<script>
  3. // function g(i) { return document.getElementById(i) };
  4. // function sp(i){g(i).type=(g(i).type==='text'?'password':'text');}
  5. // var xhttp, reqTime, reqFin;
  6. // function setCbx(el, da) {
  7. // if(da == '1') {
  8. // el.checked = true;
  9. // el.style.visibility = 'visible';
  10. // }
  11. // else {
  12. // el.checked = false;
  13. // el.style.visibility = 'visible';
  14. // }
  15. // }
  16. // function updCbxVal(el) {
  17. // if (el.checked) el.value = '1';
  18. // else {
  19. // el.checked = true;
  20. // el.value = '0';
  21. // el.style.visibility = 'hidden';
  22. // }
  23. // }
  24. static const char html_conftime_script[] PROGMEM = R"=====(
  25. function transmit(f) {
  26. if (!xhttp) {
  27. reqTime = 0;
  28. reqFin = false;
  29. updCbxVal(g('NTPEnable'));
  30. xhttp = new XMLHttpRequest();
  31. xhttp.timeout = 1000;
  32. xhttp.overrideMimeType('application/json');
  33. xhttp.open('POST', 'confDataTime');
  34. xhttp.send(f ? (new FormData(f)) : '');
  35. xhttp.onreadystatechange = function () {
  36. if (xhttp.readyState === XMLHttpRequest.DONE && xhttp.status === 200) {
  37. var data = JSON.parse(xhttp.responseText);
  38. setCbx(g('NTPEnable'), data.NTPEnable);
  39. g('NTPServer1').value = data.NTPServer1;
  40. g('NTPServer2').value = data.NTPServer2;
  41. g('TZStr').value = data.TZStr;
  42. g('NTPSyncInt').value = data.NTPSyncInt;
  43. xhttp = null;
  44. reqFin = true;
  45. }
  46. else {
  47. if(!reqFin && reqTime > 10) {
  48. xhttp = null;
  49. reqFin = true;
  50. }
  51. }
  52. }
  53. }
  54. return false;
  55. }
  56. //transmit();
  57. function saveConf() {
  58. updCbxVal(g('NTPEnable'));
  59. g('frmConf').submit();
  60. }
  61. function init() {
  62. transmit();
  63. }
  64. )====="; // html_conftime_script
  65. // setInterval(function () { ++reqTime; }, 1000);
  66. //</script>
  67. static const char html_conftime_body[] PROGMEM = R"=====(
  68. <b>Configuration - Date &amp; Time</b>
  69. <div class='config'>
  70. <form id='frmConf' action='setConfTime' method='POST'>
  71. <br>
  72. <fieldset>
  73. <legend>NTP-Server</legend>
  74. <p><b>Enable NTP Time Sync</b>&nbsp;<input type='checkbox' name='NTPEnable' id='NTPEnable'></p>
  75. <p><b>NTP Server 1</b><br><input type='text' name='NTPServer1' id='NTPServer1'></p>
  76. <p><b>NTP Server 2</b><br><input type='text' name='NTPServer2' id='NTPServer2'></p>
  77. <p><b>Timezone String</b><br><input type='text' name='TZStr' id='TZStr'></p>
  78. <p class='n'>a valid TZ string (right column) from here: <br><a target='_blank' href='https://github.com/nayarsystems/posix_tz_db/blob/master/zones.csv'>zones.csv</a></p>
  79. <p><b>NTP Sync Interval [m]</b><br><input type='text' name='NTPSyncInt' id='NTPSyncInt'></p>
  80. </fieldset>
  81. <div></div><br>
  82. </form>
  83. <div></div>
  84. <table style='width:100%'>
  85. <td style='width:50%'><button onclick='location="conf";' class='bgrey'>Cancel</button></td>
  86. <td style='width:50%'><button onclick='return saveConf()' class='bred'>Save</button></td>
  87. </tr></table>
  88. </div>
  89. )====="; // html_conftime_body