2016-02-25 14:47:07 +00:00
|
|
|
define(function () {
|
|
|
|
return function (config, el, router, d) {
|
2016-04-02 20:47:57 +00:00
|
|
|
var sidebarTitle = document.createElement("h2")
|
|
|
|
sidebarTitle.textContent = "Location: " + d.toString()
|
|
|
|
el.appendChild(sidebarTitle)
|
2016-02-25 14:47:07 +00:00
|
|
|
|
2016-04-02 20:47:57 +00:00
|
|
|
getJSON("https://nominatim.openstreetmap.org/reverse?format=json&lat=" + d.lat + "&lon=" + d.lng + "&zoom=18&addressdetails=0")
|
2016-02-25 14:47:07 +00:00
|
|
|
.then(function(result) {
|
2016-04-02 20:47:57 +00:00
|
|
|
if(result.display_name)
|
|
|
|
sidebarTitle.textContent = result.display_name
|
2016-02-25 14:47:07 +00:00
|
|
|
})
|
|
|
|
|
2016-04-02 20:47:57 +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-04-02 20:47:57 +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-04-02 20:47:57 +00:00
|
|
|
var editUci = document.createElement("textarea")
|
|
|
|
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) + "';" +
|
|
|
|
"uci commit gluon-node-info"
|
|
|
|
|
|
|
|
el.appendChild(createBox("uci", "Befehl", editUci, false))
|
|
|
|
|
|
|
|
var linkPlain = document.createElement("a")
|
|
|
|
linkPlain.textContent = "plain"
|
|
|
|
linkPlain.onclick = function() {
|
2016-02-25 20:03:33 +00:00
|
|
|
switch2plain()
|
|
|
|
return false
|
2016-02-25 14:47:07 +00:00
|
|
|
}
|
2016-04-02 20:47:57 +00:00
|
|
|
linkPlain.href = "#"
|
|
|
|
|
|
|
|
var linkUci = document.createElement("a")
|
|
|
|
linkUci.textContent = "uci"
|
|
|
|
linkUci.onclick = function() {
|
2016-02-25 20:03:33 +00:00
|
|
|
switch2uci()
|
|
|
|
return false
|
2016-02-25 14:47:07 +00:00
|
|
|
}
|
2016-04-02 20:47:57 +00:00
|
|
|
linkUci.href = "#"
|
2016-02-25 14:47:07 +00:00
|
|
|
|
2016-04-02 20:47:57 +00:00
|
|
|
var hintText = document.createElement("p")
|
|
|
|
hintText.appendChild(document.createTextNode("Du kannst zwischen "))
|
|
|
|
hintText.appendChild(linkPlain)
|
|
|
|
hintText.appendChild(document.createTextNode(" und "))
|
|
|
|
hintText.appendChild(linkUci)
|
|
|
|
hintText.appendChild(document.createTextNode(" wechseln."))
|
|
|
|
el.appendChild(hintText)
|
2016-02-25 14:47:07 +00:00
|
|
|
|
2016-04-02 20:47:57 +00:00
|
|
|
function createBox(name, title, inputElem, isVisible) {
|
|
|
|
var visible = typeof isVisible !== "undefined" ? isVisible : true
|
|
|
|
var box = document.createElement("div")
|
|
|
|
var heading = document.createElement("h3")
|
|
|
|
heading.textContent = title
|
|
|
|
box.appendChild(heading)
|
2016-02-25 20:03:33 +00:00
|
|
|
var btn = document.createElement("button")
|
|
|
|
btn.className = "ion-ios-copy"
|
|
|
|
btn.title = "Kopieren"
|
2016-04-02 20:47:57 +00:00
|
|
|
btn.onclick = function() { copy2clip(inputElem.id) }
|
|
|
|
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
|
|
|
|
box.style.display = visible ? "block" : "none"
|
|
|
|
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-04-02 20:47:57 +00:00
|
|
|
var copyField = document.querySelector("#" + id)
|
|
|
|
copyField.select()
|
2016-02-25 20:03:33 +00:00
|
|
|
try {
|
|
|
|
document.execCommand("copy")
|
|
|
|
} catch (err) {
|
|
|
|
console.log(err)
|
|
|
|
}
|
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 switch2plain() {
|
2016-04-02 20:47:57 +00:00
|
|
|
document.getElementById("box-uci").style.display = "none"
|
|
|
|
document.getElementById("box-lat").style.display = "block"
|
|
|
|
document.getElementById("box-lng").style.display = "block"
|
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 switch2uci() {
|
2016-04-02 20:47:57 +00:00
|
|
|
document.getElementById("box-uci").style.display = "block"
|
|
|
|
document.getElementById("box-lat").style.display = "none"
|
|
|
|
document.getElementById("box-lng").style.display = "none"
|
2016-02-25 14:47:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|