diff --git a/www/assets/images/weather-clear.svg b/www/assets/images/weather-clear.svg new file mode 100644 index 0000000..d7448af --- /dev/null +++ b/www/assets/images/weather-clear.svg @@ -0,0 +1,68 @@ + + + + diff --git a/www/assets/images/weather-rain.svg b/www/assets/images/weather-rain.svg new file mode 100644 index 0000000..5288541 --- /dev/null +++ b/www/assets/images/weather-rain.svg @@ -0,0 +1,68 @@ + + + + diff --git a/www/assets/images/weather-snow.svg b/www/assets/images/weather-snow.svg new file mode 100644 index 0000000..53f6d5a --- /dev/null +++ b/www/assets/images/weather-snow.svg @@ -0,0 +1,81 @@ + + + + diff --git a/www/assets/images/weather-windy.svg b/www/assets/images/weather-windy.svg new file mode 100644 index 0000000..578c430 --- /dev/null +++ b/www/assets/images/weather-windy.svg @@ -0,0 +1,68 @@ + + + + diff --git a/www/assets/js/toolbox_track.js b/www/assets/js/toolbox_track.js index 9d13aa8..ccdc5dd 100644 --- a/www/assets/js/toolbox_track.js +++ b/www/assets/js/toolbox_track.js @@ -100,7 +100,7 @@ function openTrackingHistory(trackingcode) { error: function (jqXHR, status, errorThrown) { if (trackingdialogopen) { app.dialog.close(); - searchingdialogopen = false; + trackingdialogopen = false; } requestfinished = true; playSound("error"); diff --git a/www/assets/js/toolbox_weather.js b/www/assets/js/toolbox_weather.js new file mode 100644 index 0000000..4eb59c7 --- /dev/null +++ b/www/assets/js/toolbox_weather.js @@ -0,0 +1,63 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + + +function ftoc(f) { + return (f - 32) * 5 / 9; +} + +function loadWeather() { + + if (userPosition.coords.accuracy > 99999) { + app.dialog.alert("Couldn't find your location. Wait for a GPS signal and try again.", "Error"); + return; + } + + var requestfinished = false; + var weatherdialogopen = false; + $.ajax({ + url: SETTINGS.weatherapi, + dataType: 'json', + data: { + latitude: userPosition.coords.latitude, + longitude: userPosition.coords.longitude + }, + timeout: 15 * 1000, + success: function (resp) { + if (weatherdialogopen) { + app.dialog.close(); + weatherdialogopen = false; + } + requestfinished = true; + if (resp.status == "OK") { + var mintemp = (localStorage.getItem("units") == "metric" ? Math.round(ftoc(resp.temp.min)) + " °C" : Math.round(resp.temp.min) + " °F"); + var maxtemp = (localStorage.getItem("units") == "metric" ? Math.round(ftoc(resp.temp.max)) + " °C" : Math.round(resp.temp.max) + " °F"); + $("#lowtemp").html(mintemp); + $("#hightemp").html(maxtemp); + $("#precipchance").text(Math.round(resp.precipitation.chance * 100.0) + "% chance"); + $("#weathericon").attr("src", "assets/images/weather-" + resp.icon + ".svg"); + } else { + app.dialog.alert(resp.message, "Error"); + } + }, + error: function (jqXHR, status, errorThrown) { + if (weatherdialogopen) { + app.dialog.close(); + weatherdialogopen = false; + } + requestfinished = true; + app.dialog.alert("There was a network issue while checking the weather. Please try again.", "Error"); + } + }); + + // Open a loading message if there's a delay + setTimeout(function () { + if (!requestfinished) { + app.dialog.preloader("Checking Weather..."); + weatherdialogopen = true; + } + }, 1000); +} \ No newline at end of file diff --git a/www/pages/toolbox.html b/www/pages/toolbox.html index b140372..14155c6 100644 --- a/www/pages/toolbox.html +++ b/www/pages/toolbox.html @@ -27,6 +27,14 @@ +