From 81efc301785bf67c1cc6b4a97ec2a62ad842c5de Mon Sep 17 00:00:00 2001 From: andrew nimmo Date: Wed, 31 Jul 2024 15:44:18 -0700 Subject: [PATCH 1/4] hidden fields partial --- .../controllers/locations/form/_bounds_hidden_fields.erb | 8 ++++++++ app/views/controllers/observations/form/_details.html.erb | 8 ++------ 2 files changed, 10 insertions(+), 6 deletions(-) create mode 100644 app/views/controllers/locations/form/_bounds_hidden_fields.erb diff --git a/app/views/controllers/locations/form/_bounds_hidden_fields.erb b/app/views/controllers/locations/form/_bounds_hidden_fields.erb new file mode 100644 index 0000000000..a29a49b2d2 --- /dev/null +++ b/app/views/controllers/locations/form/_bounds_hidden_fields.erb @@ -0,0 +1,8 @@ +<%# locals: (location: nil, target_type: :geocode_target) -%> + +<%= fields_for(:location) do |f_l| %> + <% %w[north south east west low high].each do |key| %> + <%= f_l.hidden_field(:"#{key}", value: location&.send(key) || nil, + data: { target_type.to_sym => "#{key}Input" }) %> + <% end %> +<% end %> diff --git a/app/views/controllers/observations/form/_details.html.erb b/app/views/controllers/observations/form/_details.html.erb index c58c4b5b70..564cf32b76 100644 --- a/app/views/controllers/observations/form/_details.html.erb +++ b/app/views/controllers/observations/form/_details.html.erb @@ -86,12 +86,8 @@ t_s = { } ) %> - <%= fields_for(:location) do |f_l| %> - <% %w[north south east west low high].each do |key| %> - <%= f_l.hidden_field(:"#{key}", value: @location&.send(key) || nil, - data: { map_target: "#{key}Input" }) %> - <% end %> - <% end %> + <%= render(partial: "locations/form/bounds_hidden_fields", + locals: { location: @location, target_type: :map_target }) %> From 7cc2e7678795ba523afca88925e732c977e179aa Mon Sep 17 00:00:00 2001 From: andrew nimmo Date: Wed, 31 Jul 2024 18:18:29 -0700 Subject: [PATCH 2/4] bounds_fields partial --- ...th_south_east_west_alt_fields.erb => _bounds_fields.erb} | 0 .../controllers/locations/form/_bounds_hidden_fields.erb | 6 ++++-- app/views/controllers/locations/form/_fields.erb | 2 +- app/views/controllers/observations/form/_details.html.erb | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-) rename app/views/controllers/locations/form/{_north_south_east_west_alt_fields.erb => _bounds_fields.erb} (100%) diff --git a/app/views/controllers/locations/form/_north_south_east_west_alt_fields.erb b/app/views/controllers/locations/form/_bounds_fields.erb similarity index 100% rename from app/views/controllers/locations/form/_north_south_east_west_alt_fields.erb rename to app/views/controllers/locations/form/_bounds_fields.erb diff --git a/app/views/controllers/locations/form/_bounds_hidden_fields.erb b/app/views/controllers/locations/form/_bounds_hidden_fields.erb index a29a49b2d2..79a26adf3e 100644 --- a/app/views/controllers/locations/form/_bounds_hidden_fields.erb +++ b/app/views/controllers/locations/form/_bounds_hidden_fields.erb @@ -2,7 +2,9 @@ <%= fields_for(:location) do |f_l| %> <% %w[north south east west low high].each do |key| %> - <%= f_l.hidden_field(:"#{key}", value: location&.send(key) || nil, - data: { target_type.to_sym => "#{key}Input" }) %> + <%= f_l.hidden_field( + :"#{key}", value: location&.send(key) || nil, + data: { "#{target_type}_target".to_sym => "#{key}Input" } + ) %> <% end %> <% end %> diff --git a/app/views/controllers/locations/form/_fields.erb b/app/views/controllers/locations/form/_fields.erb index fb0901a06a..ad535a11e0 100644 --- a/app/views/controllers/locations/form/_fields.erb +++ b/app/views/controllers/locations/form/_fields.erb @@ -8,7 +8,7 @@ button_data: { map_target: "showBoxBtn", action: "map#showBox" } ) %> -<%= render(partial: "locations/form/north_south_east_west_alt_fields", +<%= render(partial: "locations/form/bounds_fields", locals: { f: f }) %> <% if in_admin_mode? %> diff --git a/app/views/controllers/observations/form/_details.html.erb b/app/views/controllers/observations/form/_details.html.erb index 564cf32b76..348ba95272 100644 --- a/app/views/controllers/observations/form/_details.html.erb +++ b/app/views/controllers/observations/form/_details.html.erb @@ -87,7 +87,7 @@ t_s = { ) %> <%= render(partial: "locations/form/bounds_hidden_fields", - locals: { location: @location, target_type: :map_target }) %> + locals: { location: @location, target_type: :map }) %> From 7b0833c4579e265a660e6bd927711ea882403b00 Mon Sep 17 00:00:00 2001 From: andrew nimmo Date: Wed, 31 Jul 2024 18:26:06 -0700 Subject: [PATCH 3/4] Show "has-id" when new Location has bounds (id = -1) --- app/javascript/controllers/autocompleter_controller.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/javascript/controllers/autocompleter_controller.js b/app/javascript/controllers/autocompleter_controller.js index ee5da7b10d..fdf36438d6 100644 --- a/app/javascript/controllers/autocompleter_controller.js +++ b/app/javascript/controllers/autocompleter_controller.js @@ -330,7 +330,7 @@ export default class extends Controller { const hiddenId = parseInt(this.hiddenTarget.value); - if (hiddenId !== NaN && hiddenId > 0) { + if (hiddenId !== NaN && hiddenId != 0) { this.wrapTarget.classList.add('has-id'); } else { this.wrapTarget.classList.remove('has-id'); From e9bba6eff0f3d3d25102f93c184be0a016155f1e Mon Sep 17 00:00:00 2001 From: andrew nimmo Date: Wed, 31 Jul 2024 18:48:37 -0700 Subject: [PATCH 4/4] Update _fields.erb --- app/views/controllers/locations/form/_fields.erb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/views/controllers/locations/form/_fields.erb b/app/views/controllers/locations/form/_fields.erb index ad535a11e0..92bb8ffbc9 100644 --- a/app/views/controllers/locations/form/_fields.erb +++ b/app/views/controllers/locations/form/_fields.erb @@ -8,8 +8,7 @@ button_data: { map_target: "showBoxBtn", action: "map#showBox" } ) %> -<%= render(partial: "locations/form/bounds_fields", - locals: { f: f }) %> +<%= render(partial: "locations/form/bounds_fields", locals: { f: f }) %> <% if in_admin_mode? %> <%= check_box_with_label(form: f, field: :locked, class: "mt-3",