2016-05-26 16:37:24 +00:00
|
|
|
define(["helper"], function (helper) {
|
2016-05-27 21:59:01 +00:00
|
|
|
"use strict";
|
|
|
|
|
2016-02-25 14:47:07 +00:00
|
|
|
return function (config, el, router, d) {
|
2016-05-22 11:23:43 +00:00
|
|
|
var sidebarTitle = document.createElement("h2");
|
|
|
|
sidebarTitle.textContent = "Location: " + d.toString();
|
|
|
|
el.appendChild(sidebarTitle);
|
2016-02-25 14:47:07 +00:00
|
|
|
|
2016-05-26 16:37:24 +00:00
|
|
|
helper.getJSON("https://nominatim.openstreetmap.org/reverse?format=json&lat=" + d.lat + "&lon=" + d.lng + "&zoom=18&addressdetails=0")
|
2016-05-22 12:51:30 +00:00
|
|
|
.then(function (result) {
|
|
|
|
if (result.display_name) {
|
|
|
|
sidebarTitle.textContent = result.display_name;
|
|
|
|
}
|
|
|
|
});
|
2016-02-25 14:47:07 +00:00
|
|
|
|
2016-05-22 11:23:43 +00:00
|
|
|
var editLat = document.createElement("input");
|
|
|
|
editLat.type = "text";
|
|
|
|
editLat.value = d.lat.toFixed(9);
|
|
|
|
el.appendChild(createBox("lat", "Breitengrad", editLat));
|
2016-02-25 14:47:07 +00:00
|
|
|
|
2016-05-22 11:23:43 +00:00
|
|
|
var editLng = document.createElement("input");
|
|
|
|
editLng.type = "text";
|
|
|
|
editLng.value = d.lng.toFixed(9);
|
|
|
|
el.appendChild(createBox("lng", "Längengrad", editLng));
|
2016-02-25 14:47:07 +00:00
|
|
|
|
2016-05-22 11:23:43 +00:00
|
|
|
var editUci = document.createElement("textarea");
|
2016-04-02 20:47:57 +00:00
|
|
|
editUci.value =
|
|
|
|
"uci set gluon-node-info.@location[0]='location'; " +
|
|
|
|
"uci set gluon-node-info.@location[0].share_location='1';" +
|
|
|
|
"uci set gluon-node-info.@location[0].latitude='" + d.lat.toFixed(9) + "';" +
|
|
|
|
"uci set gluon-node-info.@location[0].longitude='" + d.lng.toFixed(9) + "';" +
|
2016-05-22 11:23:43 +00:00
|
|
|
"uci commit gluon-node-info";
|
2016-04-02 20:47:57 +00:00
|
|
|
|
2016-05-26 23:34:42 +00:00
|
|
|
el.appendChild(createBox("uci", "Uci", editUci));
|
2016-04-02 20:47:57 +00:00
|
|
|
|
2016-05-22 11:23:43 +00:00
|
|
|
var linkPlain = document.createElement("a");
|
|
|
|
linkPlain.textContent = "plain";
|
2016-05-22 12:51:30 +00:00
|
|
|
linkPlain.onclick = function () {
|
2016-05-22 11:23:43 +00:00
|
|
|
switch2plain();
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
linkPlain.href = "#";
|
2016-04-02 20:47:57 +00:00
|
|
|
|
2016-05-22 11:23:43 +00:00
|
|
|
var linkUci = document.createElement("a");
|
|
|
|
linkUci.textContent = "uci";
|
2016-05-22 12:51:30 +00:00
|
|
|
linkUci.onclick = function () {
|
2016-05-22 11:23:43 +00:00
|
|
|
switch2uci();
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
linkUci.href = "#";
|
2016-02-25 14:47:07 +00:00
|
|
|
|
2016-05-26 23:34:42 +00:00
|
|
|
function createBox(name, title, inputElem) {
|
2016-05-22 11:23:43 +00:00
|
|
|
var box = document.createElement("div");
|
|
|
|
var heading = document.createElement("h3");
|
|
|
|
heading.textContent = title;
|
|
|
|
box.appendChild(heading);
|
|
|
|
var btn = document.createElement("button");
|
2016-05-26 23:34:42 +00:00
|
|
|
btn.classList.add("ion-ios-copy");
|
2016-05-22 11:23:43 +00:00
|
|
|
btn.title = "Kopieren";
|
2016-05-22 12:51:30 +00:00
|
|
|
btn.onclick = function () {
|
|
|
|
copy2clip(inputElem.id);
|
|
|
|
};
|
2016-05-22 11:23:43 +00:00
|
|
|
inputElem.id = "location-" + name;
|
|
|
|
inputElem.readOnly = true;
|
|
|
|
var line = document.createElement("p");
|
|
|
|
line.appendChild(inputElem);
|
|
|
|
line.appendChild(btn);
|
|
|
|
box.appendChild(line);
|
|
|
|
box.id = "box-" + name;
|
|
|
|
return box;
|
2016-02-25 14:47:07 +00:00
|
|
|
}
|
2016-02-25 20:03:33 +00:00
|
|
|
|
2016-02-25 14:47:07 +00:00
|
|
|
function copy2clip(id) {
|
2016-05-22 11:23:43 +00:00
|
|
|
var copyField = document.querySelector("#" + id);
|
|
|
|
copyField.select();
|
2016-02-25 20:03:33 +00:00
|
|
|
try {
|
2016-05-22 11:23:43 +00:00
|
|
|
document.execCommand("copy");
|
2016-02-25 20:03:33 +00:00
|
|
|
} catch (err) {
|
2016-05-26 16:37:24 +00:00
|
|
|
console.warn(err);
|
2016-02-25 20:03:33 +00:00
|
|
|
}
|
2016-02-25 14:47:07 +00:00
|
|
|
}
|
2016-02-25 20:03:33 +00:00
|
|
|
|
2016-05-22 11:23:43 +00:00
|
|
|
};
|
|
|
|
});
|