]> git.openstreetmap.org Git - rails.git/commitdiff
Add delete home location button listener
authorAnton Khorev <tony29@yandex.ru>
Wed, 9 Aug 2023 17:57:43 +0000 (20:57 +0300)
committerAnton Khorev <tony29@yandex.ru>
Fri, 11 Aug 2023 18:44:16 +0000 (21:44 +0300)
app/assets/javascripts/user.js

index 88999f45a8a1ea028238c8abcf9d3d88b15de00c..24506b4b4e945b467fb006f3d5215e54d88bae17 100644 (file)
@@ -51,19 +51,25 @@ $(document).ready(function () {
       }
 
       map.on("click", function (e) {
-        if ($("#updatehome").is(":checked")) {
-          var zoom = map.getZoom(),
-              precision = OSM.zoomPrecision(zoom),
-              location = e.latlng.wrap();
+        if (!$("#updatehome").is(":checked")) return;
 
-          $("#home_lat").val(location.lat.toFixed(precision));
-          $("#home_lon").val(location.lng.toFixed(precision));
+        var zoom = map.getZoom(),
+            precision = OSM.zoomPrecision(zoom),
+            location = e.latlng.wrap();
 
-          respondToHomeUpdate();
-        }
+        $("#home_lat").val(location.lat.toFixed(precision));
+        $("#home_lon").val(location.lng.toFixed(precision));
+
+        deleted_lat = null;
+        deleted_lon = null;
+        respondToHomeUpdate();
       });
 
-      $("#home_lat, #home_lon").on("input", respondToHomeUpdate);
+      $("#home_lat, #home_lon").on("input", function () {
+        deleted_lat = null;
+        deleted_lon = null;
+        respondToHomeUpdate();
+      });
 
       $("#home_show").click(function () {
         var lat = $("#home_lat").val(),
@@ -71,6 +77,16 @@ $(document).ready(function () {
 
         map.panTo([lat, lon]);
       });
+
+      $("#home_delete").click(function () {
+        var lat = $("#home_lat").val(),
+            lon = $("#home_lon").val();
+
+        $("#home_lat, #home_lon").val("");
+        deleted_lat = lat;
+        deleted_lon = lon;
+        respondToHomeUpdate();
+      });
     } else {
       $("[data-user]").each(function () {
         var user = $(this).data("user");