X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/73b59c5859ab128f61a456699f3c809bbb15558a..e6c400bd147335aad7d346beb0d3277a092e6511:/app/assets/javascripts/index/notes.js.erb diff --git a/app/assets/javascripts/index/notes.js.erb b/app/assets/javascripts/index/notes.js.erb index 0161301e9..8b440910c 100644 --- a/app/assets/javascripts/index/notes.js.erb +++ b/app/assets/javascripts/index/notes.js.erb @@ -17,6 +17,46 @@ $(document).ready(function () { newNotes = undefined; } + function createNote(feature, form) { + var location = unproj(feature.geometry.getBounds().getCenterLonLat()); + + $.ajax($("#createnoteanchor").attr("href"), { + type: "POST", + data: { + lon: location.lon, + lat: location.lat, + text: $(form.text).val() + }, + success: function (data) { + map.noteSelector.unselect(feature); + + feature.attributes = data.properties; + + map.noteLayer.drawFeature(feature); + + map.noteMover.deactivate(); + } + }); + } + + function updateNote(feature, form, close) { + var url = close ? feature.attributes.close_url : feature.attributes.comment_url; + + $.ajax(url, { + type: "POST", + data: { + text: $(form.text).val() + }, + success: function (data) { + map.noteSelector.unselect(feature) + + feature.attributes = data.properties; + + map.noteSelector.select(feature) + } + }); + } + function noteSelected(o) { var feature = o.feature; var location = feature.geometry.getBounds().getCenterLonLat(); @@ -53,32 +93,32 @@ $(document).ready(function () { $(feature.popup.contentDiv).find("textarea").autoGrow(); - $(feature.popup.contentDiv).find("input#note-add").click(function (e) { - var location = unproj(feature.geometry.getBounds().getCenterLonLat()); + $(feature.popup.contentDiv).find("textarea").on("input", function (e) { var form = e.target.form; - e.preventDefault(); + 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")); + } + }); - $.ajax($("#createnoteanchor").attr("href"), { - type: "POST", - data: { - lon: location.lon, - lat: location.lat, - text: $(form.comment).val() - }, - success: function (data) { - map.noteSelector.unselect(feature); + $(feature.popup.contentDiv).find("input#note-add").click(function (e) { + e.preventDefault(); - feature.attributes.status = "open"; - feature.attributes.id = data; + createNote(feature, e.target.form); + }); - map.noteLayer.drawFeature(feature); + $(feature.popup.contentDiv).find("input#note-comment").click(function (e) { + e.preventDefault(); - map.noteMover.deactivate(); - } - }); + updateNote(feature, e.target.form, false); + }); + $(feature.popup.contentDiv).find("input#note-close").click(function (e) { e.preventDefault(); + + updateNote(feature, e.target.form, true); }); feature.popup.updateSize();