Add user home location change listeners and buttons
This commit is contained in:
parent
033c032ed6
commit
a2ff9b38f8
3 changed files with 35 additions and 7 deletions
|
@ -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();
|
||||
|
||||
|
|
|
@ -42,13 +42,18 @@
|
|||
|
||||
<fieldset>
|
||||
<legend><%= t ".home location" -%></legend>
|
||||
<p id="home_message" class="text-muted"<% if current_user.has_home? %> hidden<% end %>><%= t ".no home location" %></p>
|
||||
<p id="home_message" class="text-muted m-0<% if current_user.has_home? %> invisible<% end %>"><%= t ".no home location" %></p>
|
||||
<div class="row">
|
||||
<%= 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" %>
|
||||
<div class="col-sm-4 pt-2 align-self-end">
|
||||
<button type="button" id="home_show" class="btn btn-outline-primary"<% unless current_user.has_home? %> hidden<% end %>><%= t ".show" %></button>
|
||||
<button type="button" id="home_delete" class="btn btn-outline-primary"<% unless current_user.has_home? %> hidden<% end %>><%= t ".delete" %></button>
|
||||
<button type="button" id="home_undelete" class="btn btn-outline-primary" hidden><%= t ".undelete" %></button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" type="checkbox" name="updatehome" value="1" <% unless current_user.has_home? %> checked="checked" <% end %> id="updatehome" />
|
||||
<input class="form-check-input" type="checkbox" name="updatehome" value="1" <% unless current_user.has_home? %> checked <% end %> id="updatehome" />
|
||||
<label class="form-check-label" for="updatehome"><%= t ".update home location on click" %></label>
|
||||
</div>
|
||||
<%= tag.div "", :id => "map", :class => "content_map set_location border border-grey rounded" %>
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue