1
|
|
|
define(['helper'], function (helper) { |
2
|
|
|
'use strict'; |
3
|
|
|
|
4
|
|
|
return function (el, d) { |
5
|
|
|
var sidebarTitle = document.createElement('h2'); |
6
|
|
|
sidebarTitle.textContent = _.t('location.location'); |
7
|
|
|
el.appendChild(sidebarTitle); |
8
|
|
|
|
9
|
|
|
helper.getJSON(config.reverseGeocodingApi + '?format=json&lat=' + d.lat + '&lon=' + d.lng + '&zoom=18&addressdetails=0&accept-language=' + _.locale()) |
10
|
|
|
.then(function (result) { |
11
|
|
|
if (result.display_name) { |
12
|
|
|
sidebarTitle.outerHTML += '<p>' + result.display_name + '</p>'; |
13
|
|
|
} |
14
|
|
|
}); |
15
|
|
|
|
16
|
|
|
var editLat = document.createElement('input'); |
17
|
|
|
editLat.setAttribute('aria-label', _.t('location.latitude')); |
18
|
|
|
editLat.type = 'text'; |
19
|
|
|
editLat.value = d.lat.toFixed(9); |
20
|
|
|
el.appendChild(createBox('lat', _.t('location.latitude'), editLat)); |
21
|
|
|
|
22
|
|
|
var editLng = document.createElement('input'); |
23
|
|
|
editLng.setAttribute('aria-label', _.t('location.longitude')); |
24
|
|
|
editLng.type = 'text'; |
25
|
|
|
editLng.value = d.lng.toFixed(9); |
26
|
|
|
el.appendChild(createBox('lng', _.t('location.longitude'), editLng)); |
27
|
|
|
|
28
|
|
|
var editUci = document.createElement('textarea'); |
29
|
|
|
editUci.setAttribute('aria-label', 'Uci'); |
30
|
|
|
editUci.value = |
31
|
|
|
"uci set gluon-node-info.@location[0]='location'; " + |
32
|
|
|
"uci set gluon-node-info.@location[0].share_location='1';" + |
33
|
|
|
"uci set gluon-node-info.@location[0].latitude='" + d.lat.toFixed(9) + "';" + |
34
|
|
|
"uci set gluon-node-info.@location[0].longitude='" + d.lng.toFixed(9) + "';" + |
35
|
|
|
'uci commit gluon-node-info'; |
36
|
|
|
|
37
|
|
|
el.appendChild(createBox('uci', 'Uci', editUci)); |
38
|
|
|
|
39
|
|
|
function createBox(name, title, inputElem) { |
40
|
|
|
var box = document.createElement('div'); |
41
|
|
|
var heading = document.createElement('h3'); |
42
|
|
|
heading.textContent = title; |
43
|
|
|
box.appendChild(heading); |
44
|
|
|
var btn = document.createElement('button'); |
45
|
|
|
btn.classList.add('ion-clipboard'); |
46
|
|
|
btn.title = _.t('location.copy'); |
47
|
|
|
btn.setAttribute('aria-label', _.t('location.copy')); |
48
|
|
|
btn.onclick = function onclick() { |
49
|
|
|
copy2clip(inputElem.id); |
50
|
|
|
}; |
51
|
|
|
inputElem.id = 'location-' + name; |
52
|
|
|
inputElem.readOnly = true; |
53
|
|
|
var line = document.createElement('p'); |
54
|
|
|
line.appendChild(inputElem); |
55
|
|
|
line.appendChild(btn); |
56
|
|
|
box.appendChild(line); |
57
|
|
|
box.id = 'box-' + name; |
58
|
|
|
return box; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
function copy2clip(id) { |
62
|
|
|
var copyField = document.querySelector('#' + id); |
63
|
|
|
copyField.select(); |
64
|
|
|
try { |
65
|
|
|
document.execCommand('copy'); |
66
|
|
|
} catch (err) { |
67
|
|
|
console.warn(err); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
}; |
71
|
|
|
}); |
72
|
|
|
|