RTL00_WEB_WS2812/Firmware/RTLGDB/WEBFiles/elements.js

93 lines
2.4 KiB
JavaScript
Raw Normal View History

2017-12-24 09:49:22 +00:00
function openTab(evt, tabID)
{
// Показываем выбранный контент
var i, tabcontent, tablinks;
tabcontent = document.getElementsByClassName("tabcontent");
for (i = 0; i < tabcontent.length; i++)
{
if (tabcontent[i].id == tabID)
tabcontent[i].style.display = "block";
else
tabcontent[i].style.display = "none";
}
// Выделяем выбранную кнопку
tablinks = document.getElementsByClassName("tablinks");
for (i = 0; i < tablinks.length; i++)
{
tablinks[i].className = tablinks[i].className.replace(" active", "");
}
evt.currentTarget.className += " active";
}
function openFilterSettings(chkbx)
{
var i, content;
content = document.getElementsByClassName("filtercontent");
for (i = 0; i < content.length; i++)
{
if (content[i].id == chkbx.id)
{
if(chkbx.checked == "1")
content[i].style.display = "block";
else
content[i].style.display = "none";
}
}
// chkbx.value = chkbx.checked ?
sendFilterState(chkbx.name, chkbx.checked);
}
function setFormValues(form, cfg)
{
var name, field;
for (name in cfg)
{
if (form[name])
{
field = form[name];
if (field[1] && field[1].type === 'checkbox')
{
field = field[1];
}
if (field.type === 'checkbox')
{
field.checked = cfg[name] === '1' ? true : false;
openFilterSettings(field);
}
else
{
field.value = cfg[name];
}
}
}
}
function sendFilterState(filtName, en)
{
var xhr = new XMLHttpRequest();
var send = en === true ? '1' : '0';
var params = filtName + '=' + encodeURIComponent(send);
xhr.open("POST", '/index.html', true);
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xhr.onreadystatechange = function ()
{
//if(xhr.readyState === XMLHttpRequest.DONE && xhr.status === 200)
//console.log(xhr.responseText);
};
xhr.send(params);
}
function sendFilterParam(filtParam, val)
{
var xhr = new XMLHttpRequest();
var params = filtParam + '=' + encodeURIComponent(val);
xhr.open("POST", '/index.html', true);
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xhr.onreadystatechange = function ()
{
};
xhr.send(params);
}