html_confTime.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /* clang-format off */
  2. static const char html_conftime_script[] PROGMEM = R"=====(
  3. <script>
  4. function g(i) { return document.getElementById(i) };
  5. function sp(i){g(i).type=(g(i).type==='text'?'password':'text');}
  6. var xhttp, reqTime, reqFin;
  7. function setCbx(el, da) {
  8. if(da == '1') {
  9. el.checked = true;
  10. el.style.visibility = 'visible';
  11. }
  12. else {
  13. el.checked = false;
  14. el.style.visibility = 'visible';
  15. }
  16. }
  17. function updCbxVal(el) {
  18. if (el.checked) el.value = '1';
  19. else {
  20. el.checked = true;
  21. el.value = '0';
  22. el.style.visibility = 'hidden';
  23. }
  24. }
  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. setInterval(function () { ++reqTime; }, 1000);
  65. </script>
  66. )====="; // html_conftime_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 href='https://github.com/nayarsystems/posix_tz_db/blob/master/zones.csv'>zones.csv</a></p>
  79. <p><b>NTP Sync Interval [s]</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