"use strict";
FW_version["zwave_neighborlist.js"] = "$Id$";
var zw_visible;
var svgns = 'xmlns="http://www.w3.org/2000/svg"';
function
zw_nl(fhemFn)
{
log("ZWNL called with "+fhemFn);
zw_visible = !zw_visible;
var txt = (zw_visible ? 'Hide' : 'Show');
var width=$("#content").width()-20,
height=$("#content").height()-20;
$('#ZWDongleNr a#zw_snm').html(txt+' neighbor map');
if(!zw_visible) {
$('#ZWDongleNr span').remove();
$("#ZWDongleNrSVG")
.css({width:0, height:0})
.html('');
return;
}
$('#ZWDongleNr').append(''+
' Start auto layout'+
' Send layout to FHEM');
FW_cmd(FW_root+"?cmd={"+fhemFn+"}&XHR=1", function(r){
var xpos=20, ypos=20, fnRet = JSON.parse(r);
$("#zw_save").toggle(fnRet.saveFn ? true : false);
var cnt=0;
for(var elName in fnRet.el) {
var el = fnRet.el[elName];
el.lines = [];
el.name = elName;
el.elHash = fnRet.el;
if(el.img) {
el.width = 64; el.height = 64+20;
} else {
el.width = el.height = 30;
}
if(!el.pos.length) {
el.pos = [xpos, ypos];
xpos += 150;
if(xpos+150 >= width)
xpos = 20, ypos += 50;
}
el.x = el.pos[0]; el.y = el.pos[1];
cnt++;
}
zw_draw(fnRet, width, height);
$('#ZWDongleNr a#zw_al').click(function(){ zw_al(fnRet, width, height); });
$('#ZWDongleNr a#zw_save').click(function(){
for(var eName in fnRet.el) {
var el = fnRet.el[eName];
if(el.pos[0] != el.x || el.pos[1] != el.y) {
log("SavePos:"+eName);
el.x = Math.round(el.x*100)/100;
el.y = Math.round(el.y*100)/100;
el.pos[0] = el.x; el.pos[1] = el.y;
var cmd = sprintf(fnRet.saveFn, eName, el.x+","+el.y);
FW_cmd(FW_root+"?cmd="+cmd+"&XHR=1");
}
}
});
});
}
function
zw_draw(fnRet, width, height)
{
var h = fnRet.el;
var svg = '