Retrieve location on first openHAB setup (#158)
Signed-off-by: Henning Treu <henning.treu@telekom.de>pull/159/head
parent
a1676fdd96
commit
82d7afc397
|
@ -10,6 +10,9 @@
|
|||
<link type="text/css" href="bootstrap.min.css" rel="stylesheet"></link>
|
||||
<link type="text/css" href="main.css" rel="stylesheet"></link>
|
||||
<link rel="icon" href="favicon.ico" type="image/vnd.microsoft.icon"><link>
|
||||
|
||||
<script type="text/javascript" src="js/jquery.min.js"></script>
|
||||
<script type="text/javascript" src="js/geolocation.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
@ -21,6 +24,12 @@
|
|||
<section class="container">
|
||||
<h1>Welcome to openHAB 2 - Initial Setup</h1>
|
||||
<div class="line">
|
||||
<div class="geolocation">
|
||||
<div class="decorator"></div>
|
||||
<hr />
|
||||
<p>In order to setup the location of your openHAB instance please accept the request from your browser. The location will be used for weather and date/time information.</p>
|
||||
<p><span>Location: </span><span id="geolocation"></span></p>
|
||||
</div>
|
||||
<div class="decorator"></div>
|
||||
<div>
|
||||
<p><br/>openHAB comes with many different add-ons. To allow an easy start, there are four pre-defined packages available that are a good starting point.
|
||||
|
@ -80,7 +89,6 @@
|
|||
</div>
|
||||
</div>
|
||||
<a href="#" onclick="location.href = 'index?type=minimal'">Skip the package selection...</a>.
|
||||
|
||||
<div class="line">
|
||||
<div class="decorator"></div>
|
||||
<hr />
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
(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() {
|
||||
output.html("Unable to retrieve your location.")
|
||||
}
|
||||
|
||||
$('.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()
|
||||
output.html("Retrieving your location…")
|
||||
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, $)
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue