Skip to content

Commit

Permalink
menus work fully, additional info shown
Browse files Browse the repository at this point in the history
Please upgrade!
  • Loading branch information
mapfde committed Jul 6, 2015
1 parent bf5ba37 commit eb15ef2
Showing 1 changed file with 96 additions and 11 deletions.
107 changes: 96 additions & 11 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 class=\"okmsg\">(.+?)<\/span>/i.test(info)) {
var re2 = /<span class=\"okmsg\">(.+?)<\/span>/i;
var arr2 = re2.exec(info);
var arr2 = /<span class=\"okmsg\">(.+?)<\/span>/i.exec(info);
info = arr2[1];
}
else if (/<span class=\"red\">(.+?)<\/span>/i.test(info)) {
var re2 = /<span class=\"red\">(.+?)<\/span>/i;
var arr2 = re2.exec(info);
var arr2 = /<span class=\"red\">(.+?)<\/span>/i.exec(info);
info = arr2[1];
}
else if (/&nbsp;<br \/>&nbsp;/i.test(info)) {
info = "no info";
}
else {
info = "E!";
}
Expand All @@ -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(/&amp;/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 = /<div class=\"red bold haupt\" >([\s\S]*?)<\/div>/i;

if (re.test(data)){
myArray = re.exec(data);
warnInfo = myArray[1];
}


var re2 = /<span class=\"querysummary2\" id=\"dtlOpen_2\">([\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 class=\"okmsg\">(.+?)<\/span>/i.test(info)) {
myArray = /<span class=\"okmsg\">(.+?)<\/span>/i.exec(info);
info = myArray[1];
}
else if (/<span class=\"red\">(.+?)<\/span>/i.test(info)) {
myArray = /<span class=\"red\">(.+?)<\/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!");
}
);
});
Expand Down

0 comments on commit eb15ef2

Please sign in to comment.