From d57755b737cbb38a590b0e017a4b5c6c661aea62 Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Sun, 14 Oct 2012 13:26:42 +0100 Subject: [PATCH] Allow commenting on, and closing of, notes from the web site --- app/assets/javascripts/index/notes.js.erb | 48 +++++++++++++++++++ .../javascripts/templates/notes/show.jst.ejs | 10 +++- config/locales/en.yml | 5 +- 3 files changed, 61 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/index/notes.js.erb b/app/assets/javascripts/index/notes.js.erb index 0161301e9..3df948e6b 100644 --- a/app/assets/javascripts/index/notes.js.erb +++ b/app/assets/javascripts/index/notes.js.erb @@ -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(); diff --git a/app/assets/javascripts/templates/notes/show.jst.ejs b/app/assets/javascripts/templates/notes/show.jst.ejs index 038ff5ebd..2ae846b19 100644 --- a/app/assets/javascripts/templates/notes/show.jst.ejs +++ b/app/assets/javascripts/templates/notes/show.jst.ejs @@ -2,7 +2,7 @@ <% note.comments.forEach(function (comment) { %>

- <%- I18n.t('javascripts.notes.show.comment', { + <%- I18n.t('javascripts.notes.show.event', { action: comment.action, user: comment.user, time: comment.date }) %> @@ -10,3 +10,11 @@ <%- comment.text %>

<% }) %> +<% if (note.status == "open") { %> +
+ +
+ + +
+<% } %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 37d5c395a..9bd8c937a 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -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" -- 2.39.5