]> git.openstreetmap.org Git - rails.git/commitdiff
Allow commenting on, and closing of, notes from the web site
authorTom Hughes <tom@compton.nu>
Sun, 14 Oct 2012 12:26:42 +0000 (13:26 +0100)
committerTom Hughes <tom@compton.nu>
Sun, 14 Oct 2012 15:01:35 +0000 (16:01 +0100)
app/assets/javascripts/index/notes.js.erb
app/assets/javascripts/templates/notes/show.jst.ejs
config/locales/en.yml

index 0161301e9e3521218f926acaf30c47ba3ac0d18f..3df948e6ba1d4af5c0d1a5d67f9db66ba0430771 100644 (file)
@@ -53,6 +53,16 @@ $(document).ready(function () {
 
     $(feature.popup.contentDiv).find("textarea").autoGrow();
 
+    $(feature.popup.contentDiv).find("textarea").on("input", function (e) {
+      var form = e.target.form;
+
+      if ($(e.target).val() == "") {
+        $(form.close).val(I18n.t("javascripts.notes.show.close"));
+      } else {
+        $(form.close).val(I18n.t("javascripts.notes.show.comment_and_close"));
+      }
+    });
+
     $(feature.popup.contentDiv).find("input#note-add").click(function (e) {
       var location = unproj(feature.geometry.getBounds().getCenterLonLat());
       var form = e.target.form;
@@ -77,8 +87,46 @@ $(document).ready(function () {
           map.noteMover.deactivate();
         }
       });
+    });
+
+    $(feature.popup.contentDiv).find("input#note-comment").click(function (e) {
+      var form = e.target.form;
 
       e.preventDefault();
+
+      $.ajax(feature.attributes.comment_url, {
+        type: "POST",
+        data: {
+          text: $(form.text).val()
+        },
+        success: function (data) {
+          map.noteSelector.unselect(feature)
+
+          feature.attributes = data.properties;
+
+          map.noteSelector.select(feature)
+        }
+      });
+    });
+
+    $(feature.popup.contentDiv).find("input#note-close").click(function (e) {
+      var form = e.target.form;
+
+      e.preventDefault();
+
+      $.ajax(feature.attributes.close_url, {
+        type: "POST",
+        data: {
+          text: $(form.text).val()
+        },
+        success: function (data) {
+          map.noteSelector.unselect(feature)
+
+          feature.attributes = data.properties;
+
+          map.noteSelector.select(feature)
+        }
+      });
     });
 
     feature.popup.updateSize();
index 038ff5ebde705976c875a018f93f63dfb2e8f56e..2ae846b194244f9856fe995d4f1ae5f601597cbf 100644 (file)
@@ -2,7 +2,7 @@
 <% note.comments.forEach(function (comment) { %>
 <p>
   <small class="deemphasize">
-    <%- I18n.t('javascripts.notes.show.comment', {
+    <%- I18n.t('javascripts.notes.show.event', {
        action: comment.action, user: comment.user, time: comment.date
     }) %>
   </small>
   <%- comment.text %>
 </p>
 <% }) %>
+<% if (note.status == "open") { %>
+<form action="#">
+  <textarea name="text" cols="40" rows="5"></textarea>
+  <br/>
+  <input type="submit" name="close" value="<%- I18n.t('javascripts.notes.show.close') %>" id="note-close">
+  <input type="submit" name="comment" value="<%- I18n.t('javascripts.notes.show.comment') %>" id="note-comment">
+</form>
+<% } %>
index 37d5c395a9d333b5ac7db428fdc3ba2405dff697..9bd8c937a7a2f2b862606648a38832e3c51c909c 100644 (file)
@@ -2047,7 +2047,10 @@ en:
         add: Add Note
       show:
         title: Note %{id}
-        comment: "%{action} by %{user} at %{time}"
+        event: "%{action} by %{user} at %{time}"
+        close: Close
+        comment_and_close: Comment & Close
+        comment: Comment
   redaction:
     edit:
       description: "Description"