diff --git a/app/components/budgets/investments/form_component.html.erb b/app/components/budgets/investments/form_component.html.erb
index 3705bc10e..e065b95cf 100644
--- a/app/components/budgets/investments/form_component.html.erb
+++ b/app/components/budgets/investments/form_component.html.erb
@@ -56,7 +56,6 @@
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",
i18n_namespace: "budgets.investments" %>
<% end %>
diff --git a/app/components/budgets/map_component.html.erb b/app/components/budgets/map_component.html.erb
index f6f595b3b..fa2284472 100644
--- a/app/components/budgets/map_component.html.erb
+++ b/app/components/budgets/map_component.html.erb
@@ -1,4 +1,4 @@
<%= t("budgets.index.map") %>
- <%= render_map(nil, "budgets", investments_coordinates: coordinates) %>
+ <%= render_map(nil, investments_coordinates: coordinates) %>
diff --git a/app/components/proposals/form_component.html.erb b/app/components/proposals/form_component.html.erb
index 566391e58..ace70b75f 100644
--- a/app/components/proposals/form_component.html.erb
+++ b/app/components/proposals/form_component.html.erb
@@ -62,7 +62,6 @@
label: t("proposals.form.map_location"),
help: t("proposals.form.map_location_instructions"),
remove_marker_label: t("proposals.form.map_remove_marker"),
- parent_class: "proposal",
i18n_namespace: "proposals" %>
<% end %>
diff --git a/app/components/shared/map_location_component.rb b/app/components/shared/map_location_component.rb
index c0f88831d..aafdcfd01 100644
--- a/app/components/shared/map_location_component.rb
+++ b/app/components/shared/map_location_component.rb
@@ -1,12 +1,11 @@
class Shared::MapLocationComponent < ApplicationComponent
- attr_reader :parent_class, :remove_marker_label, :investments_coordinates
- delegate :map_location_input_id, to: :helpers
+ attr_reader :remove_marker_label, :investments_coordinates, :form
- def initialize(map_location, parent_class, remove_marker_label: nil, investments_coordinates: nil)
+ def initialize(map_location, remove_marker_label: nil, investments_coordinates: nil, form: nil)
@map_location = map_location
- @parent_class = parent_class
@remove_marker_label = remove_marker_label
@investments_coordinates = investments_coordinates
+ @form = form
end
def map_location
@@ -16,7 +15,7 @@ class Shared::MapLocationComponent < ApplicationComponent
private
def editable?
- remove_marker_label.present?
+ form.present?
end
def latitude
@@ -53,12 +52,25 @@ class Shared::MapLocationComponent < ApplicationComponent
map_tiles_provider_attribution: Rails.application.secrets.map_tiles_provider_attribution,
marker_editable: editable?,
marker_remove_selector: "##{remove_marker_link_id}",
- 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")}",
marker_investments_coordinates: investments_coordinates,
marker_latitude: map_location.latitude.presence,
marker_longitude: map_location.longitude.presence
- }
+ }.merge(input_selectors)
+ end
+
+ def input_selectors
+ if form
+ {
+ latitude_input_selector: "##{input_id(:latitude)}",
+ longitude_input_selector: "##{input_id(:longitude)}",
+ zoom_input_selector: "##{input_id(:zoom)}"
+ }
+ else
+ {}
+ end
+ end
+
+ def input_id(attribute)
+ form.hidden_field(attribute).match(/ id="([^"]+)"/)[1]
end
end
diff --git a/app/helpers/map_locations_helper.rb b/app/helpers/map_locations_helper.rb
index 1e6111b02..3b56ace3d 100644
--- a/app/helpers/map_locations_helper.rb
+++ b/app/helpers/map_locations_helper.rb
@@ -3,10 +3,6 @@ module MapLocationsHelper
map_location.present? && map_location.available?
end
- def map_location_input_id(prefix, attribute)
- "#{prefix}_map_location_attributes_#{attribute}"
- end
-
def render_map(...)
render Shared::MapLocationComponent.new(...)
end
diff --git a/app/views/budgets/investments/_investment_detail.html.erb b/app/views/budgets/investments/_investment_detail.html.erb
index 7c758dcc3..c7d23dae7 100644
--- a/app/views/budgets/investments/_investment_detail.html.erb
+++ b/app/views/budgets/investments/_investment_detail.html.erb
@@ -28,7 +28,7 @@
<% if feature?(:map) && map_location_available?(@investment.map_location) %>
- <%= render_map(investment.map_location, "budget_investment") %>
+ <%= render_map(investment.map_location) %>
<% end %>
diff --git a/app/views/budgets/investments/_map.html.erb b/app/views/budgets/investments/_map.html.erb
index cc549a90e..be68bcdbe 100644
--- a/app/views/budgets/investments/_map.html.erb
+++ b/app/views/budgets/investments/_map.html.erb
@@ -1,3 +1,3 @@
- <%= render_map(@map_location, "budgets", investments_coordinates: @investments_map_coordinates) %>
+ <%= render_map(@map_location, investments_coordinates: @investments_map_coordinates) %>
diff --git a/app/views/map_locations/_form_fields.html.erb b/app/views/map_locations/_form_fields.html.erb
index 4a26a5758..3f8233f43 100644
--- a/app/views/map_locations/_form_fields.html.erb
+++ b/app/views/map_locations/_form_fields.html.erb
@@ -1,16 +1,10 @@
<%= form.label :map_location, label %>
<%= help %>
-<%= render_map(map_location, parent_class, remove_marker_label: remove_marker_label) %>
-
<%= form.fields_for :map_location, map_location do |m_l_fields| %>
- <%= m_l_fields.hidden_field :latitude,
- value: map_location.latitude,
- id: map_location_input_id(parent_class, "latitude") %>
- <%= m_l_fields.hidden_field :longitude,
- value: map_location.longitude,
- id: map_location_input_id(parent_class, "longitude") %>
- <%= m_l_fields.hidden_field :zoom,
- value: map_location.zoom,
- id: map_location_input_id(parent_class, "zoom") %>
+ <%= render_map(map_location, remove_marker_label: remove_marker_label, form: m_l_fields) %>
+
+ <%= m_l_fields.hidden_field :latitude, value: map_location.latitude %>
+ <%= m_l_fields.hidden_field :longitude, value: map_location.longitude %>
+ <%= m_l_fields.hidden_field :zoom, value: map_location.zoom %>
<% end %>
diff --git a/app/views/proposals/_info.html.erb b/app/views/proposals/_info.html.erb
index b5a5ebe79..71060a514 100644
--- a/app/views/proposals/_info.html.erb
+++ b/app/views/proposals/_info.html.erb
@@ -42,7 +42,7 @@
<% if feature?(:map) && map_location_available?(@proposal.map_location) %>
- <%= render_map(@proposal.map_location, "proposal") %>
+ <%= render_map(@proposal.map_location) %>
<% end %>