config.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. var feed_interval_frequency = 1000;
  2. var mac_re = /^[0-9a-f]{1,2}([\.:-])(?:[0-9a-f]{1,2}\1){4}[0-9a-f]{1,2}$/mi;
  3. // https://stackoverflow.com/questions/14636536/how-to-check-if-a-variable-is-an-integer-in-javascript#14794066
  4. function isInt(value) {
  5. return !isNaN(value) &&
  6. parseInt(Number(value)) == value &&
  7. !isNaN(parseInt(value, 10));
  8. }
  9. function scrollTop()
  10. {
  11. window.scrollTo({
  12. top: 0,
  13. behavior: "smooth"
  14. });
  15. }
  16. window.onload = function()
  17. {
  18. var feed = document.getElementById("current_feed");
  19. function update_image()
  20. {
  21. feed.src = feed.src.split("&")[0] + "&load=" + new Date().getTime();
  22. }
  23. feed_interval = setInterval(update_image, feed_interval_frequency);
  24. document.querySelector('[name="update_config"]').addEventListener('submit',
  25. function(e){
  26. const mac_addrs = document.getElementsByClassName('mac_addr');
  27. for (let i=0; i < mac_addrs.length; i++) {
  28. mac_addrs[i].classList.remove("fail_val");
  29. if (mac_addrs[i].value == "") { continue; }
  30. if (!mac_re.test(mac_addrs[i].value)) {
  31. mac_addrs[i].classList.add("fail_val");
  32. scrollTop();
  33. console.log("failed on mac address test for " + mac_addrs[i].name + " for value " + mac_addrs[i].value);
  34. e.preventDefault();
  35. }
  36. }
  37. const numerics = document.getElementsByClassName('numeric');
  38. for (let i=0; i < numerics.length; i++) {
  39. numerics[i].classList.remove("fail_val");
  40. if (numerics[i].value == "") { continue; }
  41. if (!isInt(numerics[i].value)) {
  42. numerics[i].classList.add("fail_val");
  43. scrollTop();
  44. console.log("failed on integer test for " + numerics[i].name);
  45. e.preventDefault();
  46. }
  47. }
  48. }
  49. );
  50. }