From: Anton Khorev Date: Wed, 9 Aug 2023 17:42:34 +0000 (+0300) Subject: Add user home location change listeners and buttons X-Git-Tag: live~1095^2~9 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/a2ff9b38f8b0c9c24ea692eaf7e1b4c21caf18b5 Add user home location change listeners and buttons --- diff --git a/app/assets/javascripts/user.js b/app/assets/javascripts/user.js index 964f187f9..197433a13 100644 --- a/app/assets/javascripts/user.js +++ b/app/assets/javascripts/user.js @@ -1,8 +1,10 @@ //= require leaflet.locatecontrol/src/L.Control.Locate $(document).ready(function () { + var map, marker, deleted_lat, deleted_lon; + if ($("#map").length) { - var map = L.map("map", { + map = L.map("map", { attributionControl: false, zoomControl: false }).addLayer(new L.OSM.Mapnik()); @@ -41,7 +43,7 @@ $(document).ready(function () { } if ($("#map").hasClass("set_location")) { - var marker = L.marker([0, 0], { icon: OSM.getUserIcon() }); + marker = L.marker([0, 0], { icon: OSM.getUserIcon() }); if (OSM.home) { marker.setLatLng([OSM.home.lat, OSM.home.lon]); @@ -54,14 +56,14 @@ $(document).ready(function () { precision = OSM.zoomPrecision(zoom), location = e.latlng.wrap(); - $("#home_message").hide(); $("#home_lat").val(location.lat.toFixed(precision)); $("#home_lon").val(location.lng.toFixed(precision)); - marker.setLatLng(e.latlng); - marker.addTo(map); + respondToHomeUpdate(); } }); + + $("#home_lat, #home_lon").on("input", respondToHomeUpdate); } else { $("[data-user]").each(function () { var user = $(this).data("user"); @@ -73,6 +75,24 @@ $(document).ready(function () { } } + function respondToHomeUpdate() { + var lat = $("#home_lat").val(), + lon = $("#home_lon").val(), + has_home = !!(lat && lon); + + $("#home_message").toggleClass("invisible", has_home); + $("#home_show").prop("hidden", !has_home); + $("#home_delete").prop("hidden", !has_home); + $("#home_undelete").prop("hidden", !(!has_home && deleted_lat && deleted_lon)); + if (has_home) { + marker.setLatLng([lat, lon]); + marker.addTo(map); + map.panTo([lat, lon]); + } else { + marker.removeFrom(map); + } + } + function updateAuthUID() { var provider = $("select#user_auth_provider").val(); diff --git a/app/views/profiles/edit.html.erb b/app/views/profiles/edit.html.erb index a50d4b5db..ff55a0665 100644 --- a/app/views/profiles/edit.html.erb +++ b/app/views/profiles/edit.html.erb @@ -42,13 +42,18 @@
<%= t ".home location" -%> -

hidden<% end %>><%= t ".no home location" %>

+

<%= t ".no home location" %>

<%= f.text_field :home_lat, :wrapper_class => "col-sm-4", :id => "home_lat" %> <%= f.text_field :home_lon, :wrapper_class => "col-sm-4", :id => "home_lon" %> +
+ + + +
- checked="checked" <% end %> id="updatehome" /> + checked <% end %> id="updatehome" />
<%= tag.div "", :id => "map", :class => "content_map set_location border border-grey rounded" %> diff --git a/config/locales/en.yml b/config/locales/en.yml index c05b92d44..e14c5806c 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1754,6 +1754,9 @@ en: home location: "Home Location" no home location: "You have not entered your home location." update home location on click: "Update home location when I click on the map?" + show: "Show" + delete: "Delete" + undelete: "Undo delete" update: success: Profile updated. failure: Couldn't update profile.