+ links on history list
authortgambet
Fri, 26 Aug 2011 15:49:32 -0400
changeset 120 41c2ee29ab55
parent 119 fcb3b039cf94
child 121 1f8c4d9b2f51
+ links on history list
~ moved graph initialization to init()
src/main/resources/scripts/map.js
src/main/resources/templates/app.ssp
--- a/src/main/resources/scripts/map.js	Fri Aug 26 14:16:11 2011 -0400
+++ b/src/main/resources/scripts/map.js	Fri Aug 26 15:49:32 2011 -0400
@@ -70,8 +70,11 @@
 	
 }
 
+var workouts, graph;
+
 function getWorkouts() {
-	return Util.requestJSON('http://localhost:2719/user/[email protected]/workouts');
+	workouts = Util.requestJSON('http://localhost:2719/user/[email protected]/workouts');
+	return workouts;
 	//return Util.requestJSON('http://localhost:2719/user/jdoe/workouts');
 	//return [ { "activity": "http://dbpedia.org/resource/Running", "date": 1312971214000, "duration": 6652, "distance": 12.000000, "json": "http://localhost:2719/user/[email protected]/workout/4e56a110ccf2406c3515bccb.json", "gpx": "http://localhost:2719/user/[email protected]/workout/4e56a110ccf2406c3515bccb.gpx" }, { "activity": "http://dbpedia.org/resource/Running", "date": 1309083594000, "duration": 14703, "distance": 12.000000, "json": "http://localhost:2719/user/[email protected]/workout/4e56a250ccf23d3128a27d0f.json", "gpx": "http://localhost:2719/user/[email protected]/workout/4e56a250ccf23d3128a27d0f.gpx" } ];
 }
@@ -90,9 +93,14 @@
 	var list = parent.getElementsByTagName('ul')[0];
 	var newList = document.createElement('ul');
 	for (var i=0; i < workouts.length; i++) {
-	  var workout = document.createElement('li');
-	  workout.innerHTML = workouts[i].activity + " " + workouts[i].json; 
-	  newList.appendChild(workout);
+	  var li = document.createElement('li');
+	  //li.className = "workout_" + i;
+	  var link = document.createElement('a');
+	  link.setAttribute('onclick', 'javascript:showResult(workouts[' + i + '])');
+	  link.href = "#workout_" + i;
+	  link.innerHTML = getActivity(workouts[i].activity) + " " + Util.formatDate(workouts[i].date);
+	  li.appendChild(link); 
+	  newList.appendChild(li);
 	};
 	parent.replaceChild(newList, list);
 }
@@ -108,6 +116,11 @@
 	list.getElementsByClassName('climb')[0].getElementsByTagName('span')[0].innerHTML = getAscent(workout.events) + ' meters';
 }
 
+// TODO
+function getActivity(type) {
+	return type.replace('http://dbpedia.org/resource/','');
+}
+
 function getAscent(events) {
 	var first, last;
 	first = (function() {
@@ -156,8 +169,7 @@
 	updateStats(workout);
 	
 	// draw the speed graph
-	var graph = new Graph();
-	graph.init();
+	
 	graph.drawSpeedGraph(workout);
 	
 }
--- a/src/main/resources/templates/app.ssp	Fri Aug 26 14:16:11 2011 -0400
+++ b/src/main/resources/templates/app.ssp	Fri Aug 26 15:49:32 2011 -0400
@@ -24,8 +24,13 @@
 			updateHistory(workouts);
 			// create map
 			OLMap.createMap();
+			
+			graph = new Graph();
+			graph.init();
+			
 			// show results for last workout
 			showResult(workouts[0]);
+			
 		}
 	</script>