From: Aaron Lidman Date: Mon, 11 Nov 2013 22:28:54 +0000 (-0800) Subject: Add notes sidebar interaction X-Git-Tag: live~4625^2~125 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/e4504399ae55525f22a7fb47e0c47434cef8cf0a?ds=sidebyside Add notes sidebar interaction --- diff --git a/app/assets/javascripts/index.js b/app/assets/javascripts/index.js index 7d2e954ad..057fa1314 100644 --- a/app/assets/javascripts/index.js +++ b/app/assets/javascripts/index.js @@ -10,6 +10,7 @@ //= require index/export //= require index/notes //= require index/history +//= require index/note //= require router $(document).ready(function () { @@ -279,7 +280,8 @@ $(document).ready(function () { return page; }; - var history = OSM.History(map); + var history = OSM.History(map), + note = OSM.Note(map); OSM.route = OSM.Router({ "/": OSM.Index(map), @@ -289,6 +291,7 @@ $(document).ready(function () { "/user/:display_name/edits": history, "/browse/friends": history, "/browse/nearby": history, + "/browse/note/:id": note, "/browse/:type/:id(/history)": OSM.Browse(map) }); diff --git a/app/assets/javascripts/index/note.js.erb b/app/assets/javascripts/index/note.js.erb new file mode 100644 index 000000000..74b8e85d0 --- /dev/null +++ b/app/assets/javascripts/index/note.js.erb @@ -0,0 +1,83 @@ +//= require templates/notes/show +//= require templates/notes/new + +OSM.Note = function(map) { + var noteLayer = map.noteLayer, + content = $('#sidebar_content'), + page = {}; + + var noteIcons = { + "new": L.icon({ + iconUrl: "<%= image_path('new_note_marker.png') %>", + iconSize: [25, 40], + iconAnchor: [12, 40] + }), + "open": L.icon({ + iconUrl: "<%= image_path('open_note_marker.png') %>", + iconSize: [25, 40], + iconAnchor: [12, 40] + }), + "closed": L.icon({ + iconUrl: "<%= image_path('closed_note_marker.png') %>", + iconSize: [25, 40], + iconAnchor: [12, 40] + }) + }; + + function updateNote(marker, form, method, url) { + $(form).find("input[type=submit]").prop("disabled", true); + + $.ajax({ + url: url, + type: method, + oauth: true, + data: {text: $(form.text).val()}, + success: function (feature) { + marker = noteLayer.getLayer(marker); + if (feature.properties.status == "hidden") { + noteLayer.removeLayer(marker); + } else { + marker.setIcon(noteIcons[feature.properties.status]); + page.load(); + } + } + }); + } + + function bind() { + content.find("input[type=submit]").on("click", function (e) { + e.preventDefault(); + var data = $(e.target).data(); + updateNote(data.noteId, e.target.form, data.method, data.url); + }); + + content.find("textarea").on("input", function (e) { + var form = e.target.form; + + if ($(e.target).val() == "") { + $(form.close).val(I18n.t("javascripts.notes.show.resolve")); + $(form.comment).prop("disabled", true); + } else { + $(form.close).val(I18n.t("javascripts.notes.show.comment_and_resolve")); + $(form.comment).prop("disabled", false); + } + }); + + content.find("textarea").val('').trigger("input"); + } + + page.pushstate = page.popstate = function(path) { + page.load(); + }; + + page.load = function() { + $('#sidebar_content').load(window.location.pathname + "?xhr=1", function(a, b, xhr) { + if (xhr.getResponseHeader('X-Page-Title')) { + document.title = xhr.getResponseHeader('X-Page-Title'); + } + bind(); + }); + }; + + return page; +}; diff --git a/app/assets/javascripts/index/notes.js.erb b/app/assets/javascripts/index/notes.js.erb index 4538e9968..75ca5ad50 100644 --- a/app/assets/javascripts/index/notes.js.erb +++ b/app/assets/javascripts/index/notes.js.erb @@ -72,6 +72,7 @@ function initializeNotes(map) { icon: noteIcons[feature.properties.status], opacity: 0.9 }); + marker.id = feature.properties.id; marker.addTo(noteLayer).bindPopup( createPopupContent(marker, feature.properties), popupOptions() @@ -80,6 +81,10 @@ function initializeNotes(map) { return marker; } + noteLayer.getLayerId = function(marker) { + return marker.id; + }; + var noteLoader; function loadNotes() { diff --git a/app/assets/stylesheets/common.css.scss b/app/assets/stylesheets/common.css.scss index 86b5a6a75..24172416f 100644 --- a/app/assets/stylesheets/common.css.scss +++ b/app/assets/stylesheets/common.css.scss @@ -1992,7 +1992,7 @@ a.button { float: left; border-radius: 0; margin:0; - min-width: 100px; + min-width: 75px; max-width: 180px; border-right:1px solid white; text-overflow: ellipsis; diff --git a/app/views/browse/note.html.erb b/app/views/browse/note.html.erb index 5c364e815..12842f87c 100644 --- a/app/views/browse/note.html.erb +++ b/app/views/browse/note.html.erb @@ -44,3 +44,23 @@ <% end %> +
+ <% if @note.status == "open" %> +
+ +
+ + + +
+
+ <% else %> +
+ +
+ + +
+
+ <% end %> +