summaryrefslogtreecommitdiff
path: root/public/static/js/geolocation.js
diff options
context:
space:
mode:
Diffstat (limited to 'public/static/js/geolocation.js')
-rw-r--r--public/static/js/geolocation.js98
1 files changed, 75 insertions, 23 deletions
diff --git a/public/static/js/geolocation.js b/public/static/js/geolocation.js
index cb16e72..2082e44 100644
--- a/public/static/js/geolocation.js
+++ b/public/static/js/geolocation.js
@@ -1,50 +1,101 @@
+/*
+ * Copyright (C) 2020 Birte Kristina Friesel
+ *
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
$(document).ready(function() {
- function getPlaceholder() {
+ const getPlaceholder = function() {
return $('div.geolocation div.progress');
}
- var showError = function(header, message, code) {
- getPlaceholder().remove();
- var errnode = $(document.createElement('div'));
+ const showError = function(header, message, code) {
+ const errnode = $(document.createElement('div'));
errnode.attr('class', 'error');
errnode.text(message);
- var headnode = $(document.createElement('strong'));
- headnode.text(header);
+ const headnode = $(document.createElement('strong'));
+ headnode.text(header + ' ');
errnode.prepend(headnode);
$('div.geolocation').append(errnode);
+
+ const recent = $('div.geolocation').data('recent');
+ if (recent) {
+ const stops = recent.split('|');
+ const res = $(document.createElement('p'));
+ $.each(stops, function(i, stop) {
+ const parts = stop.split(';');
+ const [ eva, name, dbris, efa, hafas, motis ] = parts;
+
+ const node = $('<a class="tablerow" href="/s/' + eva + '?dbris=' + (dbris||0) + '&amp;efa=' + (efa||0) + '&amp;hafas=' + (hafas||0) + '&amp;motis=' + (motis||0) + '"><span><i class="material-icons" aria-hidden="true">' + (!(dbris||efa||hafas||motis) ? 'train' : 'directions') + '</i>' + name + '</span></a>');
+ node.click(function() {
+ $('nav .preloader-wrapper').addClass('active');
+ });
+ res.append(node);
+ });
+ $('p.geolocationhint').text('Letzte Ziele:');
+ getPlaceholder().replaceWith(res);
+ } else {
+ getPlaceholder().remove();
+ }
};
- var processResult = function(data) {
+ const processResult = function(data) {
if (data.error) {
showError('Backend-Fehler:', data.error, null);
} else if (data.candidates.length == 0) {
showError('Keine Bahnhöfe in 70km Umkreis gefunden', '', null);
} else {
- resultTable = $('<table><tbody></tbody></table>')
- resultBody = resultTable.children();
+ const res = $(document.createElement('p'));
$.each(data.candidates, function(i, candidate) {
+ let node;
+
+ if (candidate.dbris) {
+ const eva = candidate.eva,
+ name = candidate.name,
+ dbris = candidate.dbris,
+ distance = candidate.distance.toFixed(1);
+ node = $('<a class="tablerow" href="/s/' + eva + '?dbris=' + dbris + '"><span><i class="material-icons" aria-hidden="true">directions</i>' + name + '</span></a>');
+ } else if (candidate.efa) {
+ const eva = candidate.eva,
+ name = candidate.name,
+ efa = candidate.efa,
+ distance = candidate.distance.toFixed(1);
+
+ node = $('<a class="tablerow" href="/s/' + eva + '?efa=' + efa + '"><span><i class="material-icons" aria-hidden="true">directions</i>' + name + '</span></a>');
+ } else if (candidate.hafas) {
+ const eva = candidate.eva,
+ name = candidate.name,
+ hafas = candidate.hafas,
+ distance = candidate.distance.toFixed(1);
- var ds100 = candidate.ds100,
- name = candidate.name,
- distance = candidate.distance;
- distance = distance.toFixed(1);
+ node = $('<a class="tablerow" href="/s/' + eva + '?hafas=' + hafas + '"><span><i class="material-icons" aria-hidden="true">directions</i>' + name + '</span></a>');
+ } else if (candidate.motis) {
+ const { id, name, motis } = candidate;
- var stationlink = $(document.createElement('a'));
- stationlink.attr('href', ds100);
- stationlink.text(name);
+ node = $('<a class="tablerow" href="/s/' + id + '?motis=' + motis + '"><span><i class="material-icons" aria-hidden="true">directions</i>' + name + '</span></a>');
+ } else {
+ const eva = candidate.eva,
+ name = candidate.name,
+ distance = candidate.distance.toFixed(1);
- resultBody.append('<tr><td><a href="/s/' + ds100 + '">' + name + '</a></td></tr>');
+ node = $('<a class="tablerow" href="/s/' + eva + '"><span><i class="material-icons" aria-hidden="true">train</i>' + name + '</span></a>');
+ }
+
+ node.click(function() {
+ $('nav .preloader-wrapper').addClass('active');
+ });
+ res.append(node);
});
- getPlaceholder().replaceWith(resultTable);
+ getPlaceholder().replaceWith(res);
}
};
- var processLocation = function(loc) {
- $.post('/geolocation', {lon: loc.coords.longitude, lat: loc.coords.latitude}, processResult);
+ const processLocation = function(loc) {
+ const backend = $('div.geolocation').data('backend');
+ $.post('/geolocation', {lon: loc.coords.longitude, lat: loc.coords.latitude, backend: backend}, processResult);
};
- var processError = function(error) {
+ const processError = function(error) {
if (error.code == error.PERMISSION_DENIED) {
showError('Standortanfrage nicht möglich.', 'Vermutlich fehlen die Rechte im Browser oder der Android Location Service ist deaktiviert.', 'geolocation.error.PERMISSION_DENIED');
} else if (error.code == error.POSITION_UNAVAILABLE) {
@@ -56,8 +107,9 @@ $(document).ready(function() {
}
};
- var geoLocationButton = $('div.geolocation > button');
- var getGeoLocation = function() {
+ const geoLocationButton = $('div.geolocation > .request');
+ const recentStops = geoLocationButton.data('recent');
+ const getGeoLocation = function() {
geoLocationButton.replaceWith($('<p class="geolocationhint">Stationen in der Umgebung:</p><div class="progress"><div class="indeterminate"></div></div>'));
navigator.geolocation.getCurrentPosition(processLocation, processError);
}