diff --git a/src/app.js b/src/app.js index 2ba956c..d0a488f 100644 --- a/src/app.js +++ b/src/app.js @@ -96,7 +96,7 @@ geolocation.location(function () { var URL = 'http://mobile.bahn.de/bin/mobil/query.exe/dox?S='+ cityStart + '&Z=' +cityGoal + '&start=1'; //console.log(URL); -//var URL = 'http://mobile.bahn.de/bin/mobil/query.exe/dox?S=mannheim&Z=stuttgart&start=1'; + //var URL = 'http://mobile.bahn.de/bin/mobil/query.exe/dox?S=mannheim&Z=stuttgart&start=1'; // Make the request @@ -124,21 +124,22 @@ ajax( coll.push(detailUrl); if (/faellt.aus/i.test(info)) { - info = "X!"; + info = "cancelled"; } else if (/achtung/i.test(info)) { - info = "W!"; + info = "warning"; } else if (/(.+?)<\/span>/i.test(info)) { - var re2 = /(.+?)<\/span>/i; - var arr2 = re2.exec(info); + var arr2 = /(.+?)<\/span>/i.exec(info); info = arr2[1]; } else if (/(.+?)<\/span>/i.test(info)) { - var re2 = /(.+?)<\/span>/i; - var arr2 = re2.exec(info); + var arr2 = /(.+?)<\/span>/i.exec(info); info = arr2[1]; } + else if (/ 
 /i.test(info)) { + info = "no info"; + } else { info = "E!"; } @@ -163,15 +164,99 @@ ajax( // Add an action for SELECT resultsMenu.on('select', function(e) { - console.log('Item number ' + coll[1] + ' was pressed!'); -}); + console.log('Item number ' + e.itemIndex + ' was pressed!'); + + var newUrl = coll[e.itemIndex].replace(/&/g, '&'); + + + //// NEW REQUEST START + + ajax( + { + url: newUrl}, + function(data) { + // Success! + console.log("Successfully fetched detailed DB data!\n" + newUrl); + + // Extract data + + var myArray; + var warnInfo = ""; + var info; + + var re = /
([\s\S]*?)<\/div>/i; + + if (re.test(data)){ + myArray = re.exec(data); + warnInfo = myArray[1]; + } + + + var re2 = /([\s\S]*?<\/span>)/i; + + if (re2.test(data)){ + myArray = re2.exec(data); + info = myArray[1]; + } + + if (/faellt.aus/i.test(info)) { + info = "cancelled"; + } + else if (/(.+?)<\/span>/i.test(info)) { + myArray = /(.+?)<\/span>/i.exec(info); + info = myArray[1]; + } + else if (/(.+?)<\/span>/i.test(info)) { + myArray = /(.+?)<\/span>/i.exec(info); + info = myArray[1]; + } + else { + info = "no info"; + } + + + + var newcard = new UI.Card({ + title: info, + body: warnInfo, + scrollable: true + }); + + newcard.show(); + }, + function(error) { + // Failure! + console.log('Failed fetching DB data: ' + error); + var infoWindow = new UI.Window(); + // Text element to inform user + var text = new UI.Text({ + position: new Vector2(0, 0), + size: new Vector2(144, 168), + text:'Error fetching detail URL' + error, + font:'GOTHIC_18_BOLD', + color:'black', + textOverflow:'wrap', + textAlign:'center', + backgroundColor:'white' + }); + + // Add to splashWindow and show + infoWindow.add(text); + infoWindow.show(); + } + ); //end ajax call + + + + + }); //End action SELECT }, function(error) { // Failure! console.log('Failed fetching DB data: ' + error); - card.subtitle(cityStart + "->" + cityGoal); - card.body("Error!"); + //card.subtitle(cityStart + "->" + cityGoal); + //card.body("Error!"); } ); });