]> git.openstreetmap.org Git - rails.git/blobdiff - app/assets/javascripts/notes.js.erb
Generate proper descriptions for notes
[rails.git] / app / assets / javascripts / notes.js.erb
index 4df32264c35068d1d855a39ce4a206f4883d2cff..c55c11ec958d7315a9c32f080aa120e1e1d91f52 100644 (file)
@@ -1,12 +1,6 @@
 function addNoteLayer(map, notesUrl, newNoteControls, newNoteForm, minZoom) {
   var newNotes;
 
-  var noteCallback = function (scope, response) {
-    for (var f = 0; f < response.features.length; f++) {
-      var feature = response.features[f];
-    }
-  };
-
   var saveNewNotes = function (o) {
     var layer = o.object;
     newNotes = layer.getFeaturesByAttribute("status", "new")
@@ -19,6 +13,17 @@ function addNoteLayer(map, notesUrl, newNoteControls, newNoteForm, minZoom) {
     newNotes = undefined;
   };
 
+  var describeNote = function (n) {
+    var description = "<h2>Note " + n.id + "</h2>";
+
+    n.comments.forEach(function (c) {
+      description += "<p><small class='deemphasize'>" + c.action + " by ";
+      description += c.user + " at " + c.date + "</small><br/>" + c.text + "</p>";
+    });
+
+    return description;
+  }
+
   var noteSelected = function (o) {
     var feature = o.feature;
     var location = feature.geometry.getBounds().getCenterLonLat();
@@ -31,7 +36,7 @@ function addNoteLayer(map, notesUrl, newNoteControls, newNoteForm, minZoom) {
       content = form.html();
       close = false;
     } else {
-      content = "<p>" + feature.attributes.id + "</p>";
+      content = describeNote(feature.attributes);
       close = true;
     };
 
@@ -167,8 +172,7 @@ function addNoteLayer(map, notesUrl, newNoteControls, newNoteForm, minZoom) {
     ],
     protocol: new OpenLayers.Protocol.HTTP({
       url: notesUrl,
-      format: new OpenLayers.Format.GeoJSON(),
-      callback: noteCallback
+      format: new OpenLayers.Format.GeoJSON()
     })
   });