1 OSM.Note = function (map) {
2 var noteLayer = map.noteLayer,
3 content = $('#sidebar_content'),
5 noteState = map.hasLayer(noteLayer),
10 iconUrl: "<%= image_path('new_note_marker.png') %>",
15 iconUrl: "<%= image_path('open_note_marker.png') %>",
20 iconUrl: "<%= image_path('closed_note_marker.png') %>",
26 function updateNote(marker, form, method, url) {
27 $(form).find("input[type=submit]").prop("disabled", true);
33 data: {text: $(form.text).val()},
34 success: function (feature) {
35 marker = noteLayer.getLayer(marker);
36 if (feature.properties.status == "hidden") {
37 noteLayer.removeLayer(marker);
39 marker.setIcon(noteIcons[feature.properties.status]);
46 page.pushstate = page.popstate = function (path) {
47 OSM.loadSidebarContent(path, page.load);
50 page.load = function () {
51 content.find("input[type=submit]").on("click", function (e) {
53 var data = $(e.target).data();
54 updateNote(data.noteId, e.target.form, data.method, data.url);
57 content.find("textarea").on("input", function (e) {
58 var form = e.target.form;
60 if ($(e.target).val() == "") {
61 $(form.close).val(I18n.t("javascripts.notes.show.resolve"));
62 $(form.comment).prop("disabled", true);
64 $(form.close).val(I18n.t("javascripts.notes.show.comment_and_resolve"));
65 $(form.comment).prop("disabled", false);
69 content.find("textarea").val('').trigger("input");
71 var data = $('.details').data();
72 if (!noteState) map.addLayer(noteLayer);
73 if (window.location.hash == "") {
74 var coords = data.coordinates.split(',');
75 map.getZoom() > 15 ? map.panTo(coords) : map.setView(coords, 16);
78 if (!map.hasLayer(halo)) {
79 halo = L.circleMarker(data.coordinates.split(','), {
87 page.unload = function () {
88 if (map.hasLayer(halo)) map.removeLayer(halo);
89 if (!noteState) map.removeLayer(noteLayer);