2012-04-16 13:41:00 +00:00
|
|
|
/*************** LONGPOLL START **************/
|
|
|
|
var FW_pollConn;
|
2013-02-22 17:41:29 +00:00
|
|
|
var FW_curLine; // Number of the next line in FW_pollConn.responseText to parse
|
2013-07-15 19:34:35 +00:00
|
|
|
var FW_widgets = new Object(); // to be filled by fhemweb_*.js
|
2013-07-19 15:42:28 +00:00
|
|
|
var FW_leaving;
|
2012-04-16 13:41:00 +00:00
|
|
|
|
|
|
|
function
|
|
|
|
FW_cmd(arg) /* see also FW_devState */
|
|
|
|
{
|
|
|
|
var req = new XMLHttpRequest();
|
|
|
|
req.open("GET", arg, true);
|
|
|
|
req.send(null);
|
|
|
|
}
|
|
|
|
|
|
|
|
function
|
|
|
|
FW_doUpdate()
|
|
|
|
{
|
2013-07-19 15:42:28 +00:00
|
|
|
if(FW_pollConn.readyState == 4 && !FW_leaving) {
|
2012-11-26 17:21:24 +00:00
|
|
|
var errdiv = document.createElement('div');
|
|
|
|
errdiv.innerHTML = "Connection lost, reconnecting in 5 seconds...";
|
|
|
|
errdiv.setAttribute("id","connect_err");
|
|
|
|
document.body.appendChild(errdiv);
|
|
|
|
setTimeout("FW_longpoll()", 5000);
|
|
|
|
return; // some problem connecting
|
|
|
|
}
|
|
|
|
|
|
|
|
if(FW_pollConn.readyState != 3)
|
2012-04-16 13:41:00 +00:00
|
|
|
return;
|
|
|
|
var lines = FW_pollConn.responseText.split("\n");
|
2012-11-26 17:21:24 +00:00
|
|
|
//Pop the last (maybe empty) line after the last "\n"
|
|
|
|
//We wait until it is complete, i.e. terminated by "\n"
|
|
|
|
lines.pop();
|
2013-06-19 16:17:13 +00:00
|
|
|
var devs = new Array();
|
2012-11-26 17:21:24 +00:00
|
|
|
for(var i=FW_curLine; i < lines.length; i++) {
|
2013-01-11 09:33:46 +00:00
|
|
|
var d = lines[i].split("<<", 3); // Complete arg
|
2013-08-23 13:29:58 +00:00
|
|
|
console.log("Got "+lines[i]);
|
2012-04-16 13:41:00 +00:00
|
|
|
if(d.length != 3)
|
|
|
|
continue;
|
2013-07-19 11:08:42 +00:00
|
|
|
var elArr = document.querySelectorAll("[informId='"+d[0]+"']");
|
2013-07-15 19:34:35 +00:00
|
|
|
for(var k=0; k<elArr.length; k++){
|
2013-07-15 09:04:36 +00:00
|
|
|
el = elArr[k];
|
2013-01-21 20:22:39 +00:00
|
|
|
if(el.nodeName.toLowerCase() == "select") {
|
|
|
|
// dropdown: set the selected index to the current value
|
|
|
|
for(var j=0;j<el.options.length;j++)
|
|
|
|
if(el.options[j].value == d[2]) {
|
|
|
|
el.selectedIndex = j;
|
|
|
|
}
|
|
|
|
|
2013-01-22 16:22:27 +00:00
|
|
|
} else {
|
2013-01-21 20:22:39 +00:00
|
|
|
el.innerHTML=d[2];
|
2013-08-23 13:29:58 +00:00
|
|
|
if(d[0].match(/-ts$/)) // timestamps
|
2013-01-22 16:22:27 +00:00
|
|
|
el.setAttribute('class', 'changed');
|
|
|
|
|
2013-01-21 20:22:39 +00:00
|
|
|
}
|
|
|
|
}
|
2013-02-24 16:47:03 +00:00
|
|
|
|
2013-07-15 19:34:35 +00:00
|
|
|
for(var w in FW_widgets) {
|
|
|
|
if(FW_widgets[w].updateLine) {
|
|
|
|
FW_widgets[w].updateLine(d);
|
2013-02-24 16:47:03 +00:00
|
|
|
}
|
2013-02-22 17:41:29 +00:00
|
|
|
}
|
2013-06-19 16:17:13 +00:00
|
|
|
|
|
|
|
if(d[0].indexOf("-") == -1) // Wont contain -
|
|
|
|
devs.push(d[0]);
|
2012-04-16 13:41:00 +00:00
|
|
|
}
|
2012-11-26 17:21:24 +00:00
|
|
|
//Next time, we continue at the next line
|
|
|
|
FW_curLine = lines.length;
|
2013-06-19 16:17:13 +00:00
|
|
|
|
2013-07-15 19:34:35 +00:00
|
|
|
for(var w in FW_widgets) {
|
|
|
|
if(FW_widgets[w].updateDevs) {
|
|
|
|
FW_widgets[w].updateDevs(devs);
|
2013-06-19 16:17:13 +00:00
|
|
|
}
|
|
|
|
}
|
2012-04-16 13:41:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function
|
|
|
|
FW_longpoll()
|
|
|
|
{
|
2012-11-26 17:21:24 +00:00
|
|
|
var errdiv = document.getElementById("connect_err");
|
|
|
|
if(errdiv)
|
|
|
|
document.body.removeChild(errdiv);
|
|
|
|
|
|
|
|
FW_curLine = 0;
|
|
|
|
|
2012-04-16 13:41:00 +00:00
|
|
|
FW_pollConn = new XMLHttpRequest();
|
2013-12-29 09:58:38 +00:00
|
|
|
|
2014-01-05 22:19:11 +00:00
|
|
|
var filter="", embArr = document.getElementsByTagName("embed");
|
2013-12-29 09:58:38 +00:00
|
|
|
for(var i = 0; i < embArr.length; i++) {
|
|
|
|
var svg = embArr[i].getSVGDocument();
|
2014-01-10 14:33:50 +00:00
|
|
|
if(svg &&
|
|
|
|
svg.firstChild &&
|
|
|
|
svg.firstChild.nextSibling &&
|
|
|
|
svg.firstChild.nextSibling.getAttribute("flog"))
|
2014-01-05 22:19:11 +00:00
|
|
|
filter=".*";
|
2013-12-29 09:58:38 +00:00
|
|
|
}
|
2014-01-05 22:19:11 +00:00
|
|
|
if(filter == "") {
|
2013-06-19 16:17:13 +00:00
|
|
|
var sa = document.location.search.substring(1).split("&");
|
|
|
|
for(var i = 0; i < sa.length; i++) {
|
|
|
|
if(sa[i].substring(0,5) == "room=")
|
2014-01-05 22:19:11 +00:00
|
|
|
filter=sa[i];
|
|
|
|
if(sa[i].substring(0,7) == "detail=")
|
|
|
|
filter=sa[i].substring(7);
|
2013-06-19 16:17:13 +00:00
|
|
|
}
|
2012-04-16 13:41:00 +00:00
|
|
|
}
|
2014-01-07 11:41:18 +00:00
|
|
|
if(filter == "" && document.getElementById("floorplan")) { //floorplan special
|
|
|
|
var name = document.getElementsByTagName("body")[0].getAttribute("id");
|
|
|
|
name = name.substring(0,name.length-5);
|
|
|
|
filter=".*;iconPath="+name;
|
|
|
|
}
|
2013-12-29 09:58:38 +00:00
|
|
|
|
2014-01-05 22:19:11 +00:00
|
|
|
var query = document.location.pathname+"?XHR=1"+
|
|
|
|
"&inform=type=status;filter="+filter+
|
|
|
|
"×tamp="+new Date().getTime();
|
2012-04-16 13:41:00 +00:00
|
|
|
FW_pollConn.open("GET", query, true);
|
|
|
|
FW_pollConn.onreadystatechange = FW_doUpdate;
|
|
|
|
FW_pollConn.send(null);
|
|
|
|
}
|
|
|
|
|
|
|
|
function
|
|
|
|
FW_delayedStart()
|
|
|
|
{
|
2013-01-11 09:33:46 +00:00
|
|
|
setTimeout("FW_longpoll()", 100);
|
2012-04-16 13:41:00 +00:00
|
|
|
}
|
2012-04-22 10:26:04 +00:00
|
|
|
/*************** LONGPOLL END **************/
|
2012-04-16 13:41:00 +00:00
|
|
|
|
2012-04-22 10:26:04 +00:00
|
|
|
/*************** Select **************/
|
|
|
|
/** Change attr/set argument type to input:text or select **/
|
2012-04-16 13:41:00 +00:00
|
|
|
function
|
|
|
|
FW_selChange(sel, list, elName)
|
|
|
|
{
|
|
|
|
var value;
|
|
|
|
var l = list.split(" ");
|
|
|
|
for(var i=0; i < l.length; i++) {
|
2013-04-28 12:40:28 +00:00
|
|
|
cmd = l[i];
|
|
|
|
var off = l[i].indexOf(":");
|
|
|
|
if(off >= 0)
|
|
|
|
cmd = l[i].substring(0, off);
|
|
|
|
if(cmd == sel) {
|
|
|
|
if(off >= 0)
|
|
|
|
value = l[i].substring(off+1);
|
2012-04-16 13:41:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
var el = document.getElementsByName(elName)[0];
|
2012-04-22 10:26:04 +00:00
|
|
|
|
2013-02-22 17:41:29 +00:00
|
|
|
var qFn, qArg;
|
|
|
|
var devName="";
|
|
|
|
if(elName.indexOf("val.attr")==0) devName = elName.substring(8);
|
2013-07-15 19:34:35 +00:00
|
|
|
if(elName.indexOf("val.set") ==0) devName = elName.substring(7);
|
2013-02-22 17:41:29 +00:00
|
|
|
|
2013-07-15 19:34:35 +00:00
|
|
|
var o;
|
2012-04-16 13:41:00 +00:00
|
|
|
if(value==undefined) {
|
2013-07-15 19:34:35 +00:00
|
|
|
o = new Object();
|
|
|
|
o.newEl = document.createElement('input');
|
|
|
|
o.newEl.type='text';
|
|
|
|
o.newEl.size=30;
|
|
|
|
o.qFn = 'qArg.setAttribute("value", "%")';
|
|
|
|
o.qArg = o.newEl;
|
2012-04-22 10:26:04 +00:00
|
|
|
|
2012-04-16 13:41:00 +00:00
|
|
|
} else {
|
2012-04-22 10:26:04 +00:00
|
|
|
var vArr = value.split(",");
|
|
|
|
|
2013-07-15 19:34:35 +00:00
|
|
|
for(var w in FW_widgets) {
|
|
|
|
if(FW_widgets[w].selChange) {
|
|
|
|
o = FW_widgets[w].selChange(elName, devName, vArr);
|
|
|
|
if(o)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-10-09 07:05:32 +00:00
|
|
|
|
2013-07-15 19:34:35 +00:00
|
|
|
if(!o) {
|
|
|
|
o = new Object();
|
|
|
|
o.newEl = document.createElement('select');
|
2012-04-22 10:26:04 +00:00
|
|
|
for(var j=0; j < vArr.length; j++) {
|
2013-07-15 19:34:35 +00:00
|
|
|
o.newEl.options[j] = new Option(vArr[j], vArr[j]);
|
2012-04-22 10:26:04 +00:00
|
|
|
}
|
2013-07-15 19:34:35 +00:00
|
|
|
o.qFn = 'FW_querySetSelected(qArg, "%")';
|
|
|
|
o.qArg = o.newEl;
|
2012-04-16 13:41:00 +00:00
|
|
|
}
|
2013-02-22 17:41:29 +00:00
|
|
|
|
|
|
|
|
2012-04-16 13:41:00 +00:00
|
|
|
}
|
2012-04-22 10:26:04 +00:00
|
|
|
|
2013-07-15 19:34:35 +00:00
|
|
|
o.newEl.setAttribute('class', el.getAttribute('class'));
|
|
|
|
o.newEl.setAttribute('name', elName);
|
|
|
|
el.parentNode.replaceChild(o.newEl, el);
|
2012-04-22 10:26:04 +00:00
|
|
|
|
2013-07-15 19:34:35 +00:00
|
|
|
if((typeof o.qFn == "string")) {
|
2013-02-22 17:41:29 +00:00
|
|
|
if(elName.indexOf("val.attr")==0)
|
2013-07-15 19:34:35 +00:00
|
|
|
FW_queryValue('{AttrVal("'+devName+'","'+sel+'","")}', o.qFn, o.qArg);
|
2013-07-20 13:54:02 +00:00
|
|
|
if(elName.indexOf("val.set")==0) {
|
|
|
|
qArg = o.qArg;
|
|
|
|
eval(o.qFn.replace("%", ""));
|
2013-10-06 16:23:55 +00:00
|
|
|
FW_queryValue('{ReadingsVal("'+devName+'","'+sel+'","")}', o.qFn, o.qArg);
|
2013-07-20 13:54:02 +00:00
|
|
|
}
|
2013-02-22 17:41:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*************** Fill attribute **************/
|
|
|
|
function
|
|
|
|
FW_queryValue(cmd, qFn, qArg)
|
|
|
|
{
|
|
|
|
var qConn = new XMLHttpRequest();
|
|
|
|
qConn.onreadystatechange = function() {
|
|
|
|
if(qConn.readyState != 3)
|
|
|
|
return;
|
2013-02-25 12:41:54 +00:00
|
|
|
var qResp = qConn.responseText.replace(/[\r\n]/g, "")
|
|
|
|
.replace(/"/g, "\\\"");
|
|
|
|
eval(qFn.replace("%", qResp));
|
2013-02-24 17:11:40 +00:00
|
|
|
delete qConn;
|
2013-02-22 17:41:29 +00:00
|
|
|
}
|
|
|
|
qConn.open("GET", document.location.pathname+"?cmd="+cmd+"&XHR=1", true);
|
|
|
|
qConn.send(null);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function
|
|
|
|
FW_querySetSelected(el, val)
|
|
|
|
{
|
2013-07-24 06:31:41 +00:00
|
|
|
if(typeof el == 'string')
|
|
|
|
el = document.getElementById(el);
|
2013-02-22 17:41:29 +00:00
|
|
|
for(var j=0;j<el.options.length;j++)
|
2013-07-24 06:31:41 +00:00
|
|
|
if(el.options[j].value == val) {
|
2013-02-22 17:41:29 +00:00
|
|
|
el.selectedIndex = j;
|
2013-07-24 06:31:41 +00:00
|
|
|
if(el.onchange)
|
|
|
|
el.onchange();
|
|
|
|
return;
|
|
|
|
}
|
2013-02-22 17:41:29 +00:00
|
|
|
}
|
2013-07-19 15:42:28 +00:00
|
|
|
|
|
|
|
window.onbeforeunload = function(e)
|
|
|
|
{
|
|
|
|
FW_leaving = 1;
|
|
|
|
return undefined;
|
|
|
|
}
|