From dbb3be0a748de0be8075d78de42199d80aaf3a47 Mon Sep 17 00:00:00 2001 From: Anton Khorev Date: Wed, 9 Aug 2023 20:57:43 +0300 Subject: [PATCH 1/1] Add delete home location button listener --- app/assets/javascripts/user.js | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/app/assets/javascripts/user.js b/app/assets/javascripts/user.js index 88999f45a..24506b4b4 100644 --- a/app/assets/javascripts/user.js +++ b/app/assets/javascripts/user.js @@ -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"); -- 2.39.5