//= 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());
}
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]);
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");
}
}
+ 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();
<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" %>