Add methods to map locations helper.

This commit is contained in:
Senén Rodero Rodríguez
2017-08-07 18:08:20 +02:00
parent a14bb77f49
commit dd7afd3593
4 changed files with 61 additions and 26 deletions

View File

@@ -16,4 +16,50 @@ module MapLocationsHelper
"#{prefix}_map_location_attributes_#{attribute}"
end
def map_location_attribution_id(map_location)
"attribution-#{dom_id(map_location)}"
end
def map_location_remove_marker_link_id(map_location)
"remove-marker-link-#{dom_id(map_location)}"
end
def render_map(map_location, parent_class, editable, remove_marker_label)
map = content_tag_for :div,
map_location,
class: "map",
data:{
map: "",
map_zoom: map_location_zoom(map_location),
map_tiles_attribution_selector: map_location_attribution_id(map_location),
map_tiles_provider: "//{s}.tile.osm.org/{z}/{x}/{y}.png",
marker_editable: editable,
marker_latitude: map_location_latitude(map_location),
marker_longitude: map_location_longitude(map_location),
marker_remove_selector: "##{map_location_remove_marker_link_id(map_location)}",
latitude_input_selector: "##{map_location_input_id(parent_class, 'latitude')}",
longitude_input_selector: "##{map_location_input_id(parent_class, 'longitude')}",
zoom_input_selector: "##{map_location_input_id(parent_class, 'zoom')}"
}
map += map_attributtion(map_location)
map += map_location_remove_marker(map_location, remove_marker_label) if editable
end
def map_attributtion(map_location, klass = nil)
content = "©#{link_to("OpenStreetMap", "http://osm.org/copyright")} contributors".html_safe
content_tag :div, id: map_location_attribution_id(map_location), class: "map-attributtion #{klass}" do
content
end
end
def map_location_remove_marker(map_location, text)
content_tag :div, class: "small-12 column text-right" do
content_tag :a,
id: map_location_remove_marker_link_id(map_location),
class: "location-map-remove-marker-button delete" do
text
end
end
end
end