Allow to render map without marker on new forms.
This commit is contained in:
@@ -8,24 +8,47 @@ App.Map =
|
|||||||
App.Map.initializeMap map
|
App.Map.initializeMap map
|
||||||
|
|
||||||
initializeMap: (element) ->
|
initializeMap: (element) ->
|
||||||
latitude = $(element).data('marker-latitude')
|
|
||||||
longitude = $(element).data('marker-longitude')
|
mapCenterLatitude = $(element).data('map-center-latitude')
|
||||||
zoom = $(element).data('map-zoom')
|
mapCenterLongitude = $(element).data('map-center-longitude')
|
||||||
mapTilesProvider = $(element).data('map-tiles-provider')
|
markerLatitude = $(element).data('marker-latitude')
|
||||||
mapAttributionSelector = $(element).data('map-tiles-attribution-selector')
|
markerLongitude = $(element).data('marker-longitude')
|
||||||
latitudeInputSelector = $(element).data('latitude-input-selector')
|
zoom = $(element).data('map-zoom')
|
||||||
longitudeInputSelector = $(element).data('longitude-input-selector')
|
mapTilesProvider = $(element).data('map-tiles-provider')
|
||||||
zoomInputSelector = $(element).data('zoom-input-selector')
|
mapAttributionSelector = $(element).data('map-tiles-attribution-selector')
|
||||||
removeMarkerSelector = $(element).data('marker-remove-selector')
|
latitudeInputSelector = $(element).data('latitude-input-selector')
|
||||||
attribution = $(mapAttributionSelector)
|
longitudeInputSelector = $(element).data('longitude-input-selector')
|
||||||
editable = $(element).data('marker-editable')
|
zoomInputSelector = $(element).data('zoom-input-selector')
|
||||||
marker_icon = L.divIcon(
|
removeMarkerSelector = $(element).data('marker-remove-selector')
|
||||||
|
attribution = $(mapAttributionSelector)
|
||||||
|
editable = $(element).data('marker-editable')
|
||||||
|
marker = null;
|
||||||
|
markerIcon = L.divIcon(
|
||||||
iconSize: null
|
iconSize: null
|
||||||
html: '<div class="map-marker"></div>')
|
html: '<div class="map-marker"></div>')
|
||||||
|
|
||||||
placeMarker = (e) ->
|
createMarker = (latitude, longitude) ->
|
||||||
marker.setLatLng(e.latlng)
|
markerLatLng = new (L.LatLng)(latitude, longitude)
|
||||||
|
marker = L.marker(markerLatLng, { icon: markerIcon, draggable: editable })
|
||||||
|
if editable
|
||||||
|
marker.on 'dragend', updateFormfields
|
||||||
marker.addTo(map)
|
marker.addTo(map)
|
||||||
|
return marker
|
||||||
|
|
||||||
|
removeMarker = (e) ->
|
||||||
|
e.preventDefault()
|
||||||
|
if marker
|
||||||
|
map.removeLayer(marker)
|
||||||
|
marker = null;
|
||||||
|
clearFormfields()
|
||||||
|
return
|
||||||
|
|
||||||
|
moveOrPlaceMarker = (e) ->
|
||||||
|
if marker
|
||||||
|
marker.setLatLng(e.latlng)
|
||||||
|
else
|
||||||
|
marker = createMarker(e.latlng.lat, e.latlng.lng)
|
||||||
|
|
||||||
updateFormfields()
|
updateFormfields()
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -41,20 +64,14 @@ App.Map =
|
|||||||
$(zoomInputSelector).val ''
|
$(zoomInputSelector).val ''
|
||||||
return
|
return
|
||||||
|
|
||||||
removeMarker = (e) ->
|
mapCenterLatLng = new (L.LatLng)(mapCenterLatitude, mapCenterLongitude)
|
||||||
e.preventDefault()
|
map = L.map(element.id).setView(mapCenterLatLng, zoom)
|
||||||
map.removeLayer(marker)
|
|
||||||
clearFormfields()
|
|
||||||
return
|
|
||||||
|
|
||||||
latLng = new (L.LatLng)(latitude, longitude)
|
|
||||||
map = L.map(element.id).setView(latLng, zoom)
|
|
||||||
marker = L.marker(latLng, { icon: marker_icon, draggable: editable })
|
|
||||||
L.tileLayer(mapTilesProvider, attribution: attribution.html()).addTo map
|
L.tileLayer(mapTilesProvider, attribution: attribution.html()).addTo map
|
||||||
marker.addTo(map)
|
|
||||||
|
if markerLatitude && markerLongitude
|
||||||
|
marker = createMarker(markerLatitude, markerLongitude)
|
||||||
|
|
||||||
if editable
|
if editable
|
||||||
$(removeMarkerSelector).on 'click', removeMarker
|
$(removeMarkerSelector).on 'click', removeMarker
|
||||||
marker.on 'dragend', updateFormfields
|
|
||||||
map.on 'zoomend', updateFormfields
|
map.on 'zoomend', updateFormfields
|
||||||
map.on 'click', placeMarker
|
map.on 'click', moveOrPlaceMarker
|
||||||
@@ -1,5 +1,9 @@
|
|||||||
module MapLocationsHelper
|
module MapLocationsHelper
|
||||||
|
|
||||||
|
def map_location_available?(map_location)
|
||||||
|
map_location.present? && map_location.filled?
|
||||||
|
end
|
||||||
|
|
||||||
def map_location_latitude(map_location)
|
def map_location_latitude(map_location)
|
||||||
map_location.present? && map_location.latitude.present? ? map_location.latitude : Setting["map.latitude"]
|
map_location.present? && map_location.latitude.present? ? map_location.latitude : Setting["map.latitude"]
|
||||||
end
|
end
|
||||||
@@ -30,12 +34,14 @@ module MapLocationsHelper
|
|||||||
class: "map",
|
class: "map",
|
||||||
data:{
|
data:{
|
||||||
map: "",
|
map: "",
|
||||||
|
map_center_latitude: map_location_latitude(map_location),
|
||||||
|
map_center_longitude: map_location_longitude(map_location),
|
||||||
map_zoom: map_location_zoom(map_location),
|
map_zoom: map_location_zoom(map_location),
|
||||||
map_tiles_attribution_selector: map_location_attribution_id(map_location),
|
map_tiles_attribution_selector: map_location_attribution_id(map_location),
|
||||||
map_tiles_provider: "//{s}.tile.osm.org/{z}/{x}/{y}.png",
|
map_tiles_provider: "//{s}.tile.osm.org/{z}/{x}/{y}.png",
|
||||||
marker_editable: editable,
|
marker_editable: editable,
|
||||||
marker_latitude: map_location_latitude(map_location),
|
marker_latitude: map_location.latitude,
|
||||||
marker_longitude: map_location_longitude(map_location),
|
marker_longitude: map_location.longitude,
|
||||||
marker_remove_selector: "##{map_location_remove_marker_link_id(map_location)}",
|
marker_remove_selector: "##{map_location_remove_marker_link_id(map_location)}",
|
||||||
latitude_input_selector: "##{map_location_input_id(parent_class, 'latitude')}",
|
latitude_input_selector: "##{map_location_input_id(parent_class, 'latitude')}",
|
||||||
longitude_input_selector: "##{map_location_input_id(parent_class, 'longitude')}",
|
longitude_input_selector: "##{map_location_input_id(parent_class, 'longitude')}",
|
||||||
@@ -43,6 +49,7 @@ module MapLocationsHelper
|
|||||||
}
|
}
|
||||||
map += map_attributtion(map_location)
|
map += map_attributtion(map_location)
|
||||||
map += map_location_remove_marker(map_location, remove_marker_label) if editable
|
map += map_location_remove_marker(map_location, remove_marker_label) if editable
|
||||||
|
map
|
||||||
end
|
end
|
||||||
|
|
||||||
def map_attributtion(map_location, klass = nil)
|
def map_attributtion(map_location, klass = nil)
|
||||||
|
|||||||
@@ -27,8 +27,8 @@ class Budget
|
|||||||
has_many :valuators, through: :valuator_assignments
|
has_many :valuators, through: :valuator_assignments
|
||||||
has_many :comments, as: :commentable
|
has_many :comments, as: :commentable
|
||||||
has_many :milestones
|
has_many :milestones
|
||||||
has_one :map_location
|
has_one :map_location, dependent: :destroy
|
||||||
accepts_nested_attributes_for :map_location
|
accepts_nested_attributes_for :map_location, allow_destroy: true
|
||||||
|
|
||||||
validates :title, presence: true
|
validates :title, presence: true
|
||||||
validates :author, presence: true
|
validates :author, presence: true
|
||||||
|
|||||||
@@ -3,4 +3,8 @@ class MapLocation < ActiveRecord::Base
|
|||||||
belongs_to :proposal
|
belongs_to :proposal
|
||||||
belongs_to :investment
|
belongs_to :investment
|
||||||
|
|
||||||
|
def filled?
|
||||||
|
latitude.present? && longitude.present? && zoom.present?
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -25,8 +25,8 @@ class Proposal < ActiveRecord::Base
|
|||||||
|
|
||||||
belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id'
|
belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id'
|
||||||
belongs_to :geozone
|
belongs_to :geozone
|
||||||
has_one :map_location
|
has_one :map_location, dependent: :destroy
|
||||||
accepts_nested_attributes_for :map_location
|
accepts_nested_attributes_for :map_location, allow_destroy: true
|
||||||
has_many :comments, as: :commentable
|
has_many :comments, as: :commentable
|
||||||
has_many :proposal_notifications
|
has_many :proposal_notifications
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
<div class="small-12 column">
|
<div class="small-12 column">
|
||||||
<div id="admin-map" class="map"
|
<div id="admin-map" class="map"
|
||||||
data-map
|
data-map
|
||||||
|
data-map-center-latitude="<%= Setting["map.latitude"] %>"
|
||||||
|
data-map-center-longitude="<%= Setting["map.longitude"] %>"
|
||||||
data-map-zoom="<%= Setting["map.zoom"] %>"
|
data-map-zoom="<%= Setting["map.zoom"] %>"
|
||||||
data-map-tiles-attribution-selector="#admin-map-attribution"
|
data-map-tiles-attribution-selector="#admin-map-attribution"
|
||||||
data-map-tiles-provider="//{s}.tile.osm.org/{z}/{x}/{y}.png"
|
data-map-tiles-provider="//{s}.tile.osm.org/{z}/{x}/{y}.png"
|
||||||
|
|||||||
@@ -45,6 +45,10 @@
|
|||||||
|
|
||||||
<%= safe_html_with_links investment.description.html_safe %>
|
<%= safe_html_with_links investment.description.html_safe %>
|
||||||
|
|
||||||
|
<% if feature?(:map) && map_location_available?(@investment.map_location) %>
|
||||||
|
<%= render_map(@investment.map_location, "budget_investment", false, nil) %>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
<% if investment.external_url.present? %>
|
<% if investment.external_url.present? %>
|
||||||
<div class="document-link">
|
<div class="document-link">
|
||||||
<%= text_with_links investment.external_url %>
|
<%= text_with_links investment.external_url %>
|
||||||
|
|||||||
@@ -68,6 +68,10 @@
|
|||||||
|
|
||||||
<%= safe_html_with_links @proposal.description %>
|
<%= safe_html_with_links @proposal.description %>
|
||||||
|
|
||||||
|
<% if feature?(:map) && map_location_available?(@proposal.map_location) %>
|
||||||
|
<%= render_map(@proposal.map_location, "proposal", false, nil) %>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
<% if @proposal.external_url.present? %>
|
<% if @proposal.external_url.present? %>
|
||||||
<div class="document-link">
|
<div class="document-link">
|
||||||
<p>
|
<p>
|
||||||
|
|||||||
9
spec/models/map_location_spec.rb
Normal file
9
spec/models/map_location_spec.rb
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
describe MapLocation do
|
||||||
|
|
||||||
|
context "#filled?" do
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user