define(["helper/lib"],function(){ var data, nodeid, cleanFunction, marker; return function(el,config){ var close = function(){ window.location.href = "#map"; nodeid = undefined; render(); }; var sidebar = document.createElement("div"); sidebar.classList.add("sidebar"); sidebar.classList.add("hidden"); el.appendChild(sidebar); var controll = document.createElement("div"); controll.classList.add("icon"); sidebar.appendChild(controll); var iconClose = document.createElement('i'); iconClose.textContent = "\uf00d"; controll.appendChild(iconClose); iconClose.onclick = close; var content = document.createElement("div"); content.classList.add("content"); sidebar.appendChild(content); var lblNodeid = document.createElement("h4"); content.appendChild(lblNodeid); var inHostname = document.createElement("input"); content.appendChild(inHostname); var table = document.createElement("table"); table.classList.add("table"); table.innerHTML = "ClChTx"; var row24 = document.createElement("tr"); row24.innerHTML = "2.4 Ghz"; var cellClient24 = document.createElement("td"); row24.appendChild(cellClient24); var cellCh24 = document.createElement("td"); row24.appendChild(cellCh24); var cellTx24 = document.createElement("td"); row24.appendChild(cellTx24); table.appendChild(row24); var row5 = document.createElement("tr"); row5.innerHTML = "5 Ghz"; var cellClient5 = document.createElement("td"); row5.appendChild(cellClient5); var cellCh5 = document.createElement("td"); row5.appendChild(cellCh5); var cellTx5 = document.createElement("td"); row5.appendChild(cellTx5); table.appendChild(row5); content.appendChild(table); var btnSave = document.createElement("button"); var saveIcon = document.createElement('i'); saveIcon.classList.add("icon"); saveIcon.textContent = "\uf0c7"; btnSave.appendChild(saveIcon); btnSave.appendChild(document.createTextNode(" Save")); content.appendChild(btnSave); if (navigator.geolocation) { var btnGps = document.createElement("button"); var gpsIcon = document.createElement('i'); gpsIcon.classList.add("icon"); gpsIcon.textContent = "\uf124"; btnGps.appendChild(gpsIcon); content.appendChild(btnGps); var setToGps = function(position){ var pos = [position.coords.latitude,position.coords.longitude]; if(marker){ marker.setLatLng(pos); marker._map.setView(pos); } if(data.aliases[nodeid] === undefined) data.aliases[nodeid] = {}; alias = data.aliases[nodeid]; if(alias.location === undefined){ alias.location = {}; } alias.hostname = inHostname.value; alias.location.latitude = position.coords.latitude; alias.location.longitude = position.coords.longitude; send('POST',config.api+'/aliases/alias/'+nodeid,alias).then(function(){ close(); }); }; btnGps.onclick = function() { navigator.geolocation.getCurrentPosition(setToGps); }; } btnSave.onclick = function() { if(data.aliases[nodeid] === undefined) data.aliases[nodeid] = {}; alias = data.aliases[nodeid]; if(marker){ if(alias.location === undefined){ alias.location = {}; } pos = marker.getLatLng(); alias.location.latitude = pos.lat; alias.location.longitude = pos.lng; } alias.hostname = inHostname.value; send('POST',config.api+'/aliases/alias/'+nodeid,alias).then(function(){ close(); }); }; var render = function(){ if(nodeid !== undefined){ var node = data.nodes[nodeid]; var alias = data.aliases[nodeid]; sidebar.classList.remove("hidden"); lblNodeid.textContent = "Nodeid:"+nodeid; inHostname.value = ((alias && alias.hostname)?alias.hostname:node.nodeinfo.hostname); cellClient24.textContent = (node.statistics !== undefined && node.statistics.clients !== undefined)?node.statistics.clients.wifi24:'-'; cellClient5.textContent = (node.statistics !== undefined && node.statistics.clients !== undefined)?node.statistics.clients.wifi5:'-'; cellCh24.textContent = (alias && alias.wireless && alias.wireless.channel24)?alias.wireless.channel24:((node.nodeinfo.wireless && node.nodeinfo.wireless.channel24)?node.nodeinfo.wireless.channel24:'-'); cellCh5.textContent = (alias && alias.wireless && alias.wireless.channel5)?alias.wireless.channel5:((node.nodeinfo.wireless && node.nodeinfo.wireless.channel5)?node.nodeinfo.wireless.channel5:'-'); cellTx24.textContent = (alias && alias.wireless && alias.wireless.txpower24)?alias.wireless.txpower24:((node.nodeinfo.wireless && node.nodeinfo.wireless.txpower24)?node.nodeinfo.wireless.txpower24:'-'); cellTx5.textContent = (alias && alias.wireless && alias.wireless.txpower5)?alias.wireless.txpower5:((node.nodeinfo.wireless && node.nodeinfo.wireless.txpower5)?node.nodeinfo.wireless.txpower5:'-'); }else{ sidebar.classList.add("hidden"); if(cleanFunction !== undefined){ cleanFunction(); cleanFunction = undefined; } //marker.options.icon.options } }; return { storageNotify: function(d){ data = d; render(); }, setSelected: function(id,m,c){ nodeid = id; marker = m; cleanFunction = c; render(); } }; }; });