freifunkmanager/js/controller/sidebar.js

161 lines
5.2 KiB
JavaScript
Raw Normal View History

2016-07-01 08:25:32 +02:00
define(["helper/lib"],function(){
2016-07-01 16:01:28 +02:00
var data,
nodeid,
cleanFunction,
marker;
2016-07-01 08:25:32 +02:00
return function(el,config){
2016-07-01 16:01:28 +02:00
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');
2016-07-02 02:11:17 +02:00
iconClose.textContent = "\uf00d";
2016-07-01 16:01:28 +02:00
controll.appendChild(iconClose);
2016-07-02 02:11:17 +02:00
iconClose.onclick = close;
2016-07-01 16:01:28 +02:00
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 = "<tr><th></th><th>Cl</th><th>Ch</th><th>Tx</th></tr>";
var row24 = document.createElement("tr");
row24.innerHTML = "<td class=\"text\">2.4 Ghz</td>";
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 = "<td class=\"text\">5 Ghz</td>";
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");
2016-07-02 02:11:17 +02:00
saveIcon.textContent = "\uf0c7";
2016-07-01 16:01:28 +02:00
btnSave.appendChild(saveIcon);
2016-07-02 02:11:17 +02:00
btnSave.appendChild(document.createTextNode(" Save"));
2016-07-01 16:01:28 +02:00
content.appendChild(btnSave);
if (navigator.geolocation) {
var btnGps = document.createElement("button");
var gpsIcon = document.createElement('i');
gpsIcon.classList.add("icon");
2016-07-02 02:11:17 +02:00
gpsIcon.textContent = "\uf124";
2016-07-01 16:01:28 +02:00
btnGps.appendChild(gpsIcon);
content.appendChild(btnGps);
var setToGps = function(position){
var pos = [position.coords.latitude,position.coords.longitude];
2016-07-04 18:03:22 +02:00
if(marker){
marker.setLatLng(pos);
marker._map.setView(pos);
}
2016-07-02 02:11:17 +02:00
if(data.aliases[nodeid] === undefined)
data.aliases[nodeid] = {};
alias = data.aliases[nodeid];
if(alias.location === undefined){
alias.location = {};
}
2016-07-04 18:03:22 +02:00
alias.hostname = inHostname.value;
alias.location.latitude = position.coords.latitude;
alias.location.longitude = position.coords.longitude;
2016-07-02 02:11:17 +02:00
send('POST',config.api+'/aliases/alias/'+nodeid,alias).then(function(){
close();
});
2016-07-01 16:01:28 +02:00
};
2016-07-02 02:11:17 +02:00
btnGps.onclick = function() {
2016-07-01 16:01:28 +02:00
navigator.geolocation.getCurrentPosition(setToGps);
2016-07-02 02:11:17 +02:00
};
2016-07-01 16:01:28 +02:00
}
2016-07-02 02:11:17 +02:00
btnSave.onclick = function() {
2016-07-01 16:01:28 +02:00
if(data.aliases[nodeid] === undefined)
data.aliases[nodeid] = {};
alias = data.aliases[nodeid];
2016-07-04 18:03:22 +02:00
if(marker){
if(alias.location === undefined){
alias.location = {};
}
pos = marker.getLatLng();
alias.location.latitude = pos.lat;
alias.location.longitude = pos.lng;
2016-07-01 16:01:28 +02:00
}
alias.hostname = inHostname.value;
send('POST',config.api+'/aliases/alias/'+nodeid,alias).then(function(){
close();
});
2016-07-02 02:11:17 +02:00
};
2016-07-01 08:25:32 +02:00
var render = function(){
if(nodeid !== undefined){
2016-07-01 16:01:28 +02:00
var node = data.nodes[nodeid];
var alias = data.aliases[nodeid];
sidebar.classList.remove("hidden");
2016-07-02 02:11:17 +02:00
lblNodeid.textContent = "Nodeid:"+nodeid;
2016-07-01 16:01:28 +02:00
inHostname.value = ((alias && alias.hostname)?alias.hostname:node.nodeinfo.hostname);
2016-07-02 02:11:17 +02:00
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:'-');
2016-07-01 08:25:32 +02:00
}else{
2016-07-01 16:01:28 +02:00
sidebar.classList.add("hidden");
if(cleanFunction !== undefined){
cleanFunction();
cleanFunction = undefined;
}
//marker.options.icon.options
2016-07-01 08:25:32 +02:00
}
2016-07-01 16:01:28 +02:00
};
2016-07-01 08:25:32 +02:00
return {
storageNotify: function(d){
2016-07-01 16:01:28 +02:00
data = d;
render();
2016-07-01 08:25:32 +02:00
},
2016-07-01 16:01:28 +02:00
setSelected: function(id,m,c){
nodeid = id;
marker = m;
cleanFunction = c;
render();
2016-07-01 08:25:32 +02:00
}
2016-07-01 16:01:28 +02:00
};
};
});