From 954eafd424eaae962f09ff687c6abaaf71eb9cc0 Mon Sep 17 00:00:00 2001 From: Anton Khorev Date: Tue, 31 Dec 2024 23:37:34 +0300 Subject: [PATCH] Move create note callback to button click handler --- app/assets/javascripts/index/new_note.js | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/app/assets/javascripts/index/new_note.js b/app/assets/javascripts/index/new_note.js index 6504bae9e..f50357158 100644 --- a/app/assets/javascripts/index/new_note.js +++ b/app/assets/javascripts/index/new_note.js @@ -35,7 +35,7 @@ OSM.NewNote = function (map) { OSM.router.route("/note/new"); }); - function createNote(marker, text) { + function createNote(marker, text, callback) { var location = marker.getLatLng().wrap(); marker.options.draggable = false; @@ -50,19 +50,8 @@ OSM.NewNote = function (map) { lon: location.lng, text }, - success: function (feature) { - noteCreated(feature, marker); - } + success: callback }); - - function noteCreated(feature, marker) { - content.find("textarea").val(""); - updateMarker(feature); - newNoteMarker = null; - noteLayer.removeLayer(marker); - addNoteButton.removeClass("active"); - OSM.router.route("/note/" + feature.properties.id); - } } function updateMarker(feature) { @@ -154,7 +143,14 @@ OSM.NewNote = function (map) { e.preventDefault(); $(this).prop("disabled", true); - createNote(newNoteMarker, text); + createNote(newNoteMarker, text, (feature) => { + content.find("textarea").val(""); + updateMarker(feature); + noteLayer.removeLayer(newNoteMarker); + newNoteMarker = null; + addNoteButton.removeClass("active"); + OSM.router.route("/note/" + feature.properties.id); + }); }); return map.getState(); -- 2.39.5