2017-06-24 18:20:35 +02:00
|
|
|
(function(window, $) {
|
|
|
|
$(function() {
|
|
|
|
function success(position) {
|
|
|
|
var latitude = position.coords.latitude
|
|
|
|
var longitude = position.coords.longitude
|
|
|
|
|
|
|
|
output.html(latitude + '°N, ' + longitude + '°E')
|
|
|
|
|
|
|
|
send({
|
|
|
|
location : latitude + ',' + longitude
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function error() {
|
2017-06-24 23:24:10 +02:00
|
|
|
$('.geolocation').hide()
|
2017-06-24 18:20:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$('.geolocation').hide()
|
|
|
|
|
|
|
|
if (!navigator.geolocation || !navigator.geolocation.getCurrentPosition) {
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
var output = $('#geolocation')
|
|
|
|
|
|
|
|
$.getJSON('../rest/services/org.eclipse.smarthome.core.i18nprovider/config', function(response) {
|
|
|
|
if (!response.location) {
|
|
|
|
$('.geolocation').show()
|
2017-06-24 23:24:10 +02:00
|
|
|
output.html("<div class=\"spinner spinner--steps\"><img src=\"img/spinner.svg\"></div>")
|
2017-06-24 18:20:35 +02:00
|
|
|
navigator.geolocation.getCurrentPosition(success, error)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
function send(configuration) {
|
|
|
|
$.ajax({
|
|
|
|
url : '../rest/services/org.eclipse.smarthome.core.i18nprovider/config',
|
|
|
|
data : JSON.stringify(configuration),
|
|
|
|
type : 'PUT',
|
|
|
|
dataType : 'json',
|
|
|
|
contentType : 'application/json'
|
|
|
|
}).done(function(response) {
|
|
|
|
console.log('configuration send: ' + response);
|
|
|
|
}).fail(function(xhr, status, errorThrown) {
|
|
|
|
console.log('Request failed. Returned status of ' + status)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})(window, $)
|