/* clang-format off */


//<script>
//  function g(i) { return document.getElementById(i) };
//  function sp(i){g(i).type=(g(i).type==='text'?'password':'text');}
//  var xhttp, reqTime, reqFin;
//  function selectElement(el, val) {    
//    el.value = val;
//  }
//  function setCbx(el, da) {
//    if(da == '1') {
//      el.checked = true;
//      el.style.visibility = 'visible';
//    }
//    else {
//      el.checked = false;
//      el.style.visibility = 'visible';
//    }
//  }
//  function updCbxVal(el) {
//    if (el.checked) el.value = '1';
//    else {
//      el.checked = true;
//    el.value = '0';
//      el.style.visibility = 'hidden';
//    }
//  }
  
static const char html_confSens_script[] PROGMEM = R"=====(
  function transmit(f) {
    if (!xhttp) {   
    reqTime = 0;
    reqFin = false;
    //updCbxVal(g('autoSaveTemp'));
    //updCbxVal(g('autoSaveMode'));
    //updCbxVal(g('saveToMqttRet'));
    //updCbxVal(g('PIRenDisp'));
    //updCbxVal(g('PIRenDispPs0'));
    //updCbxVal(g('togTHdisp'));
    xhttp = new XMLHttpRequest();
    xhttp.timeout = 1000;
    xhttp.overrideMimeType('application/json');
    xhttp.open('POST', 'confDataSens');
    xhttp.send(f ? (new FormData(f)) : '');
    xhttp.onreadystatechange = function () {
      if (xhttp.readyState === XMLHttpRequest.DONE && xhttp.status === 200) {
        var data = JSON.parse(xhttp.responseText);
        selectElement(g('assignSens_0'), data.assignSens_0);
        selectElement(g('assignSens_1'), data.assignSens_1);
        selectElement(g('assignSens_2'), data.assignSens_2);
        //g('tempMin').value = data.tempMin;
        //g('tempMax').value = data.tempMax;
        //g('measInt').value = data.measInt;
        //g('dispInt').value = data.dispInt;
        //g('dispTout').value = data.dispTout;
        //setCbx(g('autoSaveTemp'), data.autoSaveTemp);
        //setCbx(g('autoSaveMode'), data.autoSaveMode);
        //setCbx(g('saveToMqttRet'), data.saveToMqttRet);
        //setCbx(g('PIRenDisp'), data.PIRenDisp);
        //setCbx(g('PIRenDispPs0'), data.PIRenDispPs0);
        //setCbx(g('togTHdisp'), data.togTHdisp);
        xhttp = null;
        reqFin = true;
       }
       else {
         if(!reqFin && reqTime > 10) {
           xhttp = null;
           reqFin = true;
         }
       }
     }
   }
    return false;
  }
  //transmit();
  function saveConf() {
    //updCbxVal(g('autoSaveTemp'));
    //updCbxVal(g('autoSaveMode'));
    //updCbxVal(g('saveToMqttRet'));
    //updCbxVal(g('PIRenDisp'));
    //updCbxVal(g('PIRenDispPs0'));
    //updCbxVal(g('togTHdisp'));
    g('frmConf').submit();
  }
  function init() {
    transmit();
  }
)====="; // html_confSens_script
//  setInterval(function () { ++reqTime; }, 1000);
//</script>


static const char html_confDisplay_body[] PROGMEM = R"=====(
<b>Configuration - Display</b>
<div class='config'>
<form id='frmConf' action='setConfDisplay' method='POST'>
<br>

<fieldset>
<legend>Interval / Timeout</legend>
<p><b>Display Update Interval [s]</b><br><input type='number' name='dispInt' id='dispInt'></p>
<p><b>Display Timeout [s]</b><br><input type='number' name='dispTout' id='dispTout'></p>
</fieldset>


<div></div><br>
</form>
<div></div>
<table style='width:100%'>
<td style='width:50%'><button onclick='location="conf";' class='bgrey'>Cancel</button></td>
<td style='width:50%'><button onclick='return saveConf()' class='bred'>Save</button></td>
</tr></table>
</div>
)====="; // html_confDisplay_body
