2017-01-29 23:51:08 +00:00
|
|
|
define(['helper'], function (helper) {
|
|
|
|
'use strict';
|
2016-05-27 21:59:01 +00:00
|
|
|
|
2016-02-25 14:47:07 +00:00
|
|
|
return function (config, el, router, d) {
|
2017-01-29 23:51:08 +00:00
|
|
|
var sidebarTitle = document.createElement('h2');
|
2017-01-28 14:33:13 +00:00
|
|
|
sidebarTitle.textContent = _.t('location.location') + ': ' + d.toString();
|
2016-05-22 11:23:43 +00:00
|
|
|
el.appendChild(sidebarTitle);
|
2016-02-25 14:47:07 +00:00
|
|
|
|
2017-01-28 14:33:13 +00:00
|
|
|
helper.getJSON(config.reverseGeocodingApi + '?format=json&lat=' + d.lat + '&lon=' + d.lng + '&zoom=18&addressdetails=0&accept-language=' + _.locale())
|
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
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
var editLat = document.createElement('input');
|
|
|
|
editLat.type = 'text';
|
2016-05-22 11:23:43 +00:00
|
|
|
editLat.value = d.lat.toFixed(9);
|
2017-01-28 14:33:13 +00:00
|
|
|
el.appendChild(createBox('lat', _.t('location.latitude'), editLat));
|
2016-02-25 14:47:07 +00:00
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
var editLng = document.createElement('input');
|
|
|
|
editLng.type = 'text';
|
2016-05-22 11:23:43 +00:00
|
|
|
editLng.value = d.lng.toFixed(9);
|
2017-01-28 14:33:13 +00:00
|
|
|
el.appendChild(createBox('lng', _.t('location.longitude'), editLng));
|
2016-02-25 14:47:07 +00:00
|
|
|
|
2017-01-29 23:51:08 +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) + "';" +
|
2017-01-29 23:51:08 +00:00
|
|
|
'uci commit gluon-node-info';
|
2016-04-02 20:47:57 +00:00
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
el.appendChild(createBox('uci', 'Uci', editUci));
|
2016-04-02 20:47:57 +00:00
|
|
|
|
2016-05-26 23:34:42 +00:00
|
|
|
function createBox(name, title, inputElem) {
|
2017-01-29 23:51:08 +00:00
|
|
|
var box = document.createElement('div');
|
|
|
|
var heading = document.createElement('h3');
|
2016-05-22 11:23:43 +00:00
|
|
|
heading.textContent = title;
|
|
|
|
box.appendChild(heading);
|
2017-01-29 23:51:08 +00:00
|
|
|
var btn = document.createElement('button');
|
2017-02-04 19:01:49 +00:00
|
|
|
btn.classList.add('ion-clipboard');
|
2017-01-28 14:33:13 +00:00
|
|
|
btn.title = _.t('location.copy');
|
2017-01-29 23:51:08 +00:00
|
|
|
btn.onclick = function onclick() {
|
2016-05-22 12:51:30 +00:00
|
|
|
copy2clip(inputElem.id);
|
|
|
|
};
|
2017-01-29 23:51:08 +00:00
|
|
|
inputElem.id = 'location-' + name;
|
2016-05-22 11:23:43 +00:00
|
|
|
inputElem.readOnly = true;
|
2017-01-29 23:51:08 +00:00
|
|
|
var line = document.createElement('p');
|
2016-05-22 11:23:43 +00:00
|
|
|
line.appendChild(inputElem);
|
|
|
|
line.appendChild(btn);
|
|
|
|
box.appendChild(line);
|
2017-01-29 23:51:08 +00:00
|
|
|
box.id = 'box-' + name;
|
2016-05-22 11:23:43 +00:00
|
|
|
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) {
|
2017-01-29 23:51:08 +00:00
|
|
|
var copyField = document.querySelector('#' + id);
|
2016-05-22 11:23:43 +00:00
|
|
|
copyField.select();
|
2016-02-25 20:03:33 +00:00
|
|
|
try {
|
2017-01-29 23:51:08 +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-05-22 11:23:43 +00:00
|
|
|
};
|
|
|
|
});
|