diff options
Diffstat (limited to 'public/static/js/geostop.js')
-rw-r--r-- | public/static/js/geostop.js | 48 |
1 files changed, 29 insertions, 19 deletions
diff --git a/public/static/js/geostop.js b/public/static/js/geostop.js index 34ba58e..fa2d6f1 100644 --- a/public/static/js/geostop.js +++ b/public/static/js/geostop.js @@ -1,24 +1,24 @@ /* - * Copyright (C) 2020 Daniel Friesel + * Copyright (C) 2020 Birte Kristina Friesel * * SPDX-License-Identifier: AGPL-3.0-or-later */ $(function() { - var removeStatus = function() { + const removeStatus = function() { $('div.candidatestatus').remove(); }; - var showError = function(header, message, code) { - 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')); + const headnode = $(document.createElement('strong')); headnode.text(header); errnode.prepend(headnode); if (code) { - var shortnode = $(document.createElement('div')); + const shortnode = $(document.createElement('div')); shortnode.attr('class', 'errcode'); shortnode.text(code); errnode.append(shortnode); @@ -27,43 +27,53 @@ $(function() { $('div.candidatelist').append(errnode); }; - var processResult = function(data) { + const processResult = function(data) { removeStatus(); if (data.error) { showError('Backend-Fehler:', data.error, null); } else if (data.candidates.length == 0) { - showError('Keine Bahnhöfe in 70km Umkreis gefunden', '', null); + showError('Keine Stationen in 70km Umkreis gefunden', '', null); } else { $.each(data.candidates, function(i, candidate) { - var ds100 = candidate.ds100, + const eva = candidate.eva, name = candidate.name, - distance = candidate.distance; - distance = distance.toFixed(1); + distance = candidate.distance.toFixed(1), + hafas = candidate.hafas; - var stationlink = $(document.createElement('a')); - stationlink.attr('href', ds100); - stationlink.text(name); + const stationlink = $(document.createElement('a')); + if (hafas) { + stationlink.attr('href', eva + '?hafas=' + hafas); + } else { + stationlink.attr('href', eva); + } + stationlink.text(name + ' '); - var distancenode = $(document.createElement('div')); + const distancenode = $(document.createElement('div')); distancenode.attr('class', 'distance'); distancenode.text(distance); + const icon = $(document.createElement('i')); + icon.attr('class', 'material-icons'); + icon.text(hafas ? 'directions' : 'train'); + + stationlink.append(icon); stationlink.append(distancenode); $('div.candidatelist').append(stationlink); }); } }; - var processLocation = function(loc) { - $.post('/_geolocation', {lon: loc.coords.longitude, lat: loc.coords.latitude}, processResult).fail(function(jqXHR, textStatus, errorThrown) { + const processLocation = function(loc) { + const param = new URLSearchParams(window.location.search); + $.post('/_geolocation', {lon: loc.coords.longitude, lat: loc.coords.latitude, hafas: param.get('hafas')}, processResult).fail(function(jqXHR, textStatus, errorThrown) { removeStatus(); showError("Netzwerkfehler: ", textStatus, errorThrown); }); - $('div.candidatestatus').text('Suche Bahnhöfe…'); + $('div.candidatestatus').text('Suche Stationen…'); }; - var processError = function(error) { + const processError = function(error) { removeStatus(); 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'); |