diff --git a/app/helpers/panel_helper.rb b/app/helpers/panel_helper.rb index 878eb85be5..1279184a6f 100644 --- a/app/helpers/panel_helper.rb +++ b/app/helpers/panel_helper.rb @@ -18,8 +18,8 @@ def panel_block(**args, &block) concat(heading) if args[:panel_bodies].present? concat(panel_bodies(args)) - elsif args[:content].present? - concat(args[:content]) + elsif args[:formatted_content].present? + concat(content) elsif args[:collapse].present? concat(panel_collapse_body(args, content)) else diff --git a/app/views/controllers/observations/_form.html.erb b/app/views/controllers/observations/_form.html.erb index 0c4667eef6..ff938ab77e 100644 --- a/app/views/controllers/observations/_form.html.erb +++ b/app/views/controllers/observations/_form.html.erb @@ -3,9 +3,19 @@ create = (action == :create) method = create ? :post : :patch button_name = create ? :CREATE.l : :SAVE_EDITS.l -include_naming = create ? true : false has_specimen = create ? false : @observation.herbarium_records.length > 0 logging_optional = create ? false : true +naming_locals = { + create:, + button_name:, + show_reasons: false, + unfocused: true, + name_help: :form_naming_name_help_leave_blank.t +} +naming_locals = {} unless create +show_projects = @projects.any? || @error_checked_projects.any? || + @suspect_checked_projects.any? +show_lists = @lists.any? # Data for the form-images Stimulus controller. # Controller element is the form, so image dropzone can cover the whole form. @@ -20,7 +30,7 @@ image_upload_localization = { something_went_wrong: :form_observations_upload_error.t }.to_json # Outlets are how the stimulus controllers call each others' methods. -data = { +form_element_data = { controller: "form-images form-exif map", map_autocompleter_outlet: "#observation_location_autocompleter", map_open: false, @@ -32,9 +42,6 @@ data = { form_images_target: "form", exif_used: create ? false : true } -show_projects = @projects.any? || @error_checked_projects.any? || - @suspect_checked_projects.any? -show_lists = @lists.any? %> <%= form_with( @@ -45,7 +52,7 @@ show_lists = @lists.any? method:, multipart: true, id: "observation_form", - data: + data: form_element_data ) do |f| %> <% if @field_code %> @@ -53,19 +60,34 @@ show_lists = @lists.any? <%= hidden_field_tag(:field_code, @field_code) %> <% end %> - <% content = [ - render(partial: "observations/form/images", locals: { f: }), - render(partial: "observations/form/details", - locals: { f:, button_name:, location: @location, logging_optional:, - action:, include_naming: }), - ].safe_join %> <%= panel_block( heading: "#{:IMAGES.l} + #{:show_observation_details.l}", - id: "observation_images_details", content: - ) %> + id: "observation_images_details", formatted_content: true + ) do + concat(render(partial: "observations/form/images", locals: { f: })) + concat(render(partial: "observations/form/details", + locals: { f:, action:, button_name:, location: @location, + logging_optional: })) + end %> + + <%= panel_block( + id: "observation_identification", + heading: "#{:IDENTIFICATION.l} + #{:SPECIMEN.l}", + collapse: "observation_specimen_inner", + open: true # @given_name.present? + ) do + tag.div(class: "row mt-3") do + concat(tag.div(class: "col-xs-12 col-md-6") do + render(partial: "observations/namings/fields", locals: naming_locals) + end) + concat(tag.div(class: "col-xs-12 col-md-6") do + render(partial: "observations/form/specimen_section", + locals: { f:, action: }) + end) + end + end %> - <%= render(partial: "observations/form/identify_specimen", - locals: { f:, action:, button_name:, include_naming: }) %> + <%= submit_button(form: f, button: button_name, center: true) %> <%= panel_block( heading: :NOTES.l, @@ -77,8 +99,6 @@ show_lists = @lists.any? locals: { form: f, fields: @observation.form_notes_parts(@user) }) end %> - <%= submit_button(form: f, button: button_name, center: true) %> - <% if show_projects %> <%= panel_block( heading: :PROJECTS.l, diff --git a/app/views/controllers/observations/form/_add_to_step.erb b/app/views/controllers/observations/form/_add_to_step.erb deleted file mode 100644 index 47f2d195d8..0000000000 --- a/app/views/controllers/observations/form/_add_to_step.erb +++ /dev/null @@ -1,30 +0,0 @@ -<%# locals: (f:, button_name:) -%> -<%# Add to Project and List section of create_observation form %> - -<%= tab_panel(id: "add_to") do %> - <%= panel_block(id: "observation_projects_and_lists", - heading: "#{:PROJECTS.l} + #{:SPECIES_LISTS.l}") do %> - - <%= tag.div(class: "row mt-3") do %> - <% if @projects.any? %> - <%= tag.div(class: "col-xs-12 col-sm-6") do - render(partial: "observations/form/projects", - locals: { button_name: }) - end %> - <% end %> - <% if @lists.any? %> - <%= tag.div(class: "col-xs-12 col-sm-6") do - render(partial: "observations/form/species_lists") - end %> - <% end %> - <% end %> - - <%= tag.div(class: "row mt-5 text-center", id: "step-nav-3") do - [ - tab_link(:BACK.l, id: "identify", button: true), - submit_button(form: f, button: button_name) - ].safe_join(" ") - end %> - <% end %> -<% end %> - diff --git a/app/views/controllers/observations/form/_details.html.erb b/app/views/controllers/observations/form/_details.html.erb index 37d1201fc6..40876c228f 100644 --- a/app/views/controllers/observations/form/_details.html.erb +++ b/app/views/controllers/observations/form/_details.html.erb @@ -8,18 +8,6 @@ t_s = { lng: { abbr: :LNG.l, full: :LONGITUDE.l, addon: "ยบ" }, alt: { abbr: :ALT.l, full: :ALTITUDE.l, addon: "m" } } -naming_locals = if include_naming - { - f: f, - action: action, - button_name: button_name, - show_reasons: false, - unfocused: true, - name_help: :form_naming_name_help_leave_blank.t - } - else - {} - end %> <%= tag.div(class: "panel-body border-top", id: "observation_details") do %> diff --git a/app/views/controllers/observations/form/_identify_specimen.erb b/app/views/controllers/observations/form/_identify_specimen.erb deleted file mode 100644 index 5f85f69bb7..0000000000 --- a/app/views/controllers/observations/form/_identify_specimen.erb +++ /dev/null @@ -1,29 +0,0 @@ -<%# locals: (f:, action:, button_name:, include_naming:) -%> - -<%= panel_block( - id: "observation_identification", - heading: "#{:IDENTIFICATION.l} + #{:SPECIMEN.l}", - collapse: "observation_specimen_inner", - open: @given_name.present? -) do %> - <%= tag.div(class: "row mt-3") do %> - <%= tag.div(class: "col-xs-12 col-md-6") do %> - <% if include_naming - naming_locals = { - f: f, - action: action, - button_name: button_name, - show_reasons: false, - unfocused: true, - name_help: :form_naming_name_help_leave_blank.t - } %> - <%= render(partial: "observations/namings/fields", - locals: naming_locals) %> - <% end %> - <% end %> - <%= tag.div(class: "col-xs-12 col-md-6") do %> - <%= render(partial: "observations/form/specimen_section", - locals: { f:, action: }) %> - <% end %> - <% end %> -<% end %> diff --git a/app/views/controllers/observations/form/_record_step.erb b/app/views/controllers/observations/form/_record_step.erb deleted file mode 100644 index a49bdf2488..0000000000 --- a/app/views/controllers/observations/form/_record_step.erb +++ /dev/null @@ -1,26 +0,0 @@ -<%# locals: (f:, button_name:, location:, logging_optional:) -%> -<%# NOTE: not using panel_block helper, because it has three panel-body divs %> - -<%= tab_panel(id: "record", active: true) do %> - <%= tag.div( - id: "observation_images_details", class: "panel panel-default" - ) do %> - - <%= tag.div(class: "panel-heading") do - tag.h4("#{:IMAGES.l} + #{:show_observation_details.l}", - class: "panel-title") - end %> - - <%= render(partial: "observations/form/images", locals: { f: f }) %> - - <%= render(partial: "observations/form/details", - locals: { f:, button_name:, location:, logging_optional: }) %> - - <%= tag.div(class: "panel-body mt-4") do - tag.div(class: "text-center", id: "step-nav-1") do - tab_link(:NEXT.l, id: "identify", button: true) - end - end %> - - <% end %> -<% end %> diff --git a/app/views/controllers/observations/form/_specimen_section.html.erb b/app/views/controllers/observations/form/_specimen_section.html.erb index 4fae2a6b43..4ef974a6e9 100644 --- a/app/views/controllers/observations/form/_specimen_section.html.erb +++ b/app/views/controllers/observations/form/_specimen_section.html.erb @@ -29,8 +29,8 @@ herbarium_record. Fields hidden unless box checked. %> <%= tag.div(id: "specimen_fields", class: ("hidden" if !@observation.specimen), data: { specimen_target: "fields" }) do %> - <%= render(partial: "observations/form/collection_number") %> - <%= render(partial: "observations/form/herbarium_record") %> + <%= render(partial: "observations/form/specimen/collection_number") %> + <%= render(partial: "observations/form/specimen/herbarium_record") %> <% end %> <% end %> diff --git a/app/views/controllers/observations/form/_collection_number.html.erb b/app/views/controllers/observations/form/specimen/_collection_number.html.erb similarity index 100% rename from app/views/controllers/observations/form/_collection_number.html.erb rename to app/views/controllers/observations/form/specimen/_collection_number.html.erb diff --git a/app/views/controllers/observations/form/_herbarium_record.html.erb b/app/views/controllers/observations/form/specimen/_herbarium_record.html.erb similarity index 100% rename from app/views/controllers/observations/form/_herbarium_record.html.erb rename to app/views/controllers/observations/form/specimen/_herbarium_record.html.erb diff --git a/app/views/controllers/observations/namings/_fields.erb b/app/views/controllers/observations/namings/_fields.erb index 86a4aa711b..1bb677d2a5 100644 --- a/app/views/controllers/observations/namings/_fields.erb +++ b/app/views/controllers/observations/namings/_fields.erb @@ -1,18 +1,17 @@ +<%# locals: (create:, button_name:, show_reasons:, unfocused: false, name_help: :form_naming_name_help.t, context: "blank" ) -%> + <% # This is included by obs form, naming new/edit form + lightbox identifier - -unfocused ||= false -focus_on_name = !unfocused && (button_name != :CREATE.l || @given_name.empty?) -focus_on_vote = !unfocused && (button_name == :CREATE.l && @given_name.present?) +focus_on_name = !unfocused && (!create || @given_name.empty?) +focus_on_vote = !unfocused && (create && @given_name.present?) feedback_locals = { - f: f, button_name: button_name, given_name: @given_name, + names: @names, valid_names: @valid_names, suggest_corrections: @suggest_corrections, - parent_deprecated: @parent_deprecated, - names: @names + parent_deprecated: @parent_deprecated } menu = unless @vote&.value&.nonzero? Vote.opinion_menu @@ -20,9 +19,7 @@ menu = unless @vote&.value&.nonzero? Vote.confidence_menu end confidences = options_for_select(menu, @vote&.value) -select_opts = { include_blank: ["new", "create"].include?(action_name) } -context ||= "blank" -name_help ||= :form_naming_name_help.t +select_opts = { include_blank: create } feedback = if @given_name.present? tag.div do render(partial: "shared/form_name_feedback", diff --git a/app/views/controllers/observations/namings/_form.erb b/app/views/controllers/observations/namings/_form.erb index 05a89d8eb0..9e4ce63469 100644 --- a/app/views/controllers/observations/namings/_form.erb +++ b/app/views/controllers/observations/namings/_form.erb @@ -1,9 +1,12 @@ +<%# locals: (local:, show_reasons: true, form_locals: {}) -%> + <% # Fields must be separate because they're included in the obs form too. # HTML ID's may seem overly precise, but there may be more than one of # these forms open on a page if modal. IDs must be unique. case action_name when "new", "create" + create = true button_name = :CREATE.l method = :post id = "obs_#{@observation.id}_naming_form" @@ -11,6 +14,7 @@ when "new", "create" approved_name: @given_name, q: get_query_param) when "edit", "update" + create = false button_name = :SAVE_EDITS.l method = :patch id = "obs_#{@observation.id}_naming_#{@naming.id}_form" @@ -20,6 +24,7 @@ when "edit", "update" q: get_query_param) end +# `local` true means do not send via Turbo. form_args = { model: @naming, url: url, method: method, id: id } if local_assigns[:local] == true form_args = form_args.merge({ local: true }) @@ -27,16 +32,15 @@ else form_args = form_args.deep_merge({ data: { turbo: true } }) end -# Note: the form needs local_assigns[:form_locals]. -# I can't find where show_reasons is ever false - AN 20230801 -form_locals = local_assigns[:form_locals] || {} +# `naming_locals`: modal forms can accept a `form_locals` local. The controller +# may send `context` (i.e. where the form appears), which defaults to "blank". +# `show_reasons` is false on the obs form, true on the naming form. +naming_locals = { create:, button_name:, show_reasons: }.merge(form_locals) %> <%= form_with(**form_args) do |f| %> + <%= render(partial: "observations/namings/fields", locals: naming_locals) %> <%= submit_button(form: f, button: button_name, center: true) %> - <%= render(partial: "observations/namings/fields", - locals: { f: f, button_name: button_name }.merge(form_locals)) %> - <% end # form %> diff --git a/app/views/controllers/observations/namings/edit.html.erb b/app/views/controllers/observations/namings/edit.html.erb index 715ab3e8c9..e8a752b14c 100644 --- a/app/views/controllers/observations/namings/edit.html.erb +++ b/app/views/controllers/observations/namings/edit.html.erb @@ -13,8 +13,7 @@ add_tab_set(naming_form_edit_tabs(obs: @observation))