diff --git a/app/assets/javascripts/map.js.coffee b/app/assets/javascripts/map.js.coffee index 8aca94bc7..fb82d0800 100644 --- a/app/assets/javascripts/map.js.coffee +++ b/app/assets/javascripts/map.js.coffee @@ -8,16 +8,17 @@ App.Map = App.Map.initializeMap map initializeMap: (element) -> - latitude = $(element).data('latitude') - longitude = $(element).data('longitude') - zoom = $(element).data('zoom') - mapTilesProvider = $(element).data('tiles-provider') - mapAttributionSelector = $(element).data('tiles-attribution-selector') + latitude = $(element).data('marker-latitude') + longitude = $(element).data('marker-longitude') + zoom = $(element).data('map-zoom') + mapTilesProvider = $(element).data('map-tiles-provider') + mapAttributionSelector = $(element).data('map-tiles-attribution-selector') latitudeInputSelector = $(element).data('latitude-input-selector') longitudeInputSelector = $(element).data('longitude-input-selector') zoomInputSelector = $(element).data('zoom-input-selector') - removeMarkerSelector = $(element).data('remove-marker-selector') + removeMarkerSelector = $(element).data('marker-remove-selector') attribution = $(mapAttributionSelector) + editable = $(element).data('marker-editable') marker_icon = L.divIcon( iconSize: null html: '
') @@ -48,11 +49,12 @@ App.Map = latLng = new (L.LatLng)(latitude, longitude) map = L.map(element.id).setView(latLng, zoom) - marker = L.marker(latLng, { icon: marker_icon, draggable: 'true' }) + marker = L.marker(latLng, { icon: marker_icon, draggable: editable }) L.tileLayer(mapTilesProvider, attribution: attribution.html()).addTo map marker.addTo(map) - $(removeMarkerSelector).on 'click', removeMarker - marker.on 'dragend', updateFormfields - map.on 'zoomend', updateFormfields - map.on 'click', placeMarker \ No newline at end of file + if editable + $(removeMarkerSelector).on 'click', removeMarker + marker.on 'dragend', updateFormfields + map.on 'zoomend', updateFormfields + map.on 'click', placeMarker \ No newline at end of file diff --git a/app/helpers/map_locations_helper.rb b/app/helpers/map_locations_helper.rb new file mode 100644 index 000000000..08d16391f --- /dev/null +++ b/app/helpers/map_locations_helper.rb @@ -0,0 +1,19 @@ +module MapLocationsHelper + + def map_location_latitude(map_location) + map_location.present? && map_location.latitude.present? ? map_location.latitude : Setting["map.latitude"] + end + + def map_location_longitude(map_location) + map_location.present? && map_location.longitude.present? ? map_location.longitude : Setting["map.longitude"] + end + + def map_location_zoom(map_location) + map_location.present? && map_location.zoom.present? ? map_location.zoom : Setting["map.zoom"] + end + + def map_location_input_id(prefix, attribute) + "#{prefix}_map_location_attributes_#{attribute}" + end + +end \ No newline at end of file diff --git a/app/views/budgets/investments/_form.html.erb b/app/views/budgets/investments/_form.html.erb index 789d0f8a9..8a19c188a 100644 --- a/app/views/budgets/investments/_form.html.erb +++ b/app/views/budgets/investments/_form.html.erb @@ -35,8 +35,9 @@ <%= render 'map_locations/form_fields', form: f, map_location: @investment.map_location || MapLocation.new, - label: t("proposals.form.map_location"), - help: t("proposals.form.map_location_instructions"), + label: t("budgets.investments.form.map_location"), + help: t("budgets.investments.form.map_location_instructions"), + remove_marker_label: t("budgets.investments.form.map_remove_marker"), parent_class: "budget_investment" %> diff --git a/app/views/map_locations/_form_fields.html.erb b/app/views/map_locations/_form_fields.html.erb index 7c4a1785e..4fcefa2fa 100644 --- a/app/views/map_locations/_form_fields.html.erb +++ b/app/views/map_locations/_form_fields.html.erb @@ -1,25 +1,34 @@ <%= form.label :map_location, label %><%= help %>
-