Skip to content

Commit

Permalink
Fixup UI forms, moving default_feed fields to be in an actual sub-form
Browse files Browse the repository at this point in the history
  • Loading branch information
cavis committed Aug 9, 2023
1 parent 18a25d5 commit a703cd7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 22 deletions.
9 changes: 4 additions & 5 deletions app/controllers/podcasts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ def show
# GET /podcasts/new
def new
@podcast = Podcast.new(podcast_params)
@podcast.set_default_feed

# TODO: get the default account from ID somehow
@podcast.prx_account_uri = helpers.podcast_account_name_options(@podcast).first.last
Expand Down Expand Up @@ -126,12 +125,8 @@ def podcast_params
nilify params.fetch(:podcast, {}).permit(
:title,
:prx_account_uri,
:subtitle,
:description,
:link,
:explicit,
:itunes_category,
:itunes_subcategory,
:serial_order,
:language,
:owner_name,
Expand All @@ -144,6 +139,10 @@ def podcast_params
:complete,
default_feed_attributes: [
:id,
:subtitle,
:description,
:itunes_category,
:itunes_subcategory,
feed_images_attributes: %i[id original_url size alt_text caption credit _destroy _retry],
itunes_images_attributes: %i[id original_url size alt_text caption credit _destroy _retry]
]
Expand Down
41 changes: 24 additions & 17 deletions app/views/podcasts/_form_main.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@

<div class="col-12 mb-4">
<div class="form-floating input-group">
<%= form.text_field :subtitle %>
<%= form.label :subtitle %>
<%= field_help_text t(".help.subtitle") %>
<%= form.fields_for :default_feed do |fields| %>
<%= fields.text_field :subtitle %>
<%= fields.label :subtitle %>
<%= field_help_text t(".help.subtitle") %>
<% end %>
</div>
</div>

Expand All @@ -21,7 +23,9 @@
<%= help_text t(".help.description") %>
</div>
<div class="card-body">
<%= form.trix_editor :description %>
<%= form.fields_for :default_feed do |fields| %>
<%= fields.trix_editor :description %>
<% end %>
</div>
</div>
</div>
Expand All @@ -43,26 +47,29 @@
</div>

<div class="col-6 mb-4">
<%# HACK: display nested validation errors %>
<% nested_errors = podcast.errors.full_messages_for("itunes_categories.name").join(", ") %>
<% klass = nested_errors.present? ? "is-invalid form-select" : "form-select" %>

<div class="form-floating input-group" data-controller="dynamic-form">
<%= form.select :itunes_category, itunes_category_options, {include_blank: true}, class: klass, data: {action: "dynamic-form#change"} %>
<% if nested_errors.present? %><div class="invalid-feedback"><%= nested_errors %></div><% end %>
<%= form.label :itunes_category %>
<%= field_help_text t(".help.itunes_category") %>
<%# update subcategory turbo-frame when category changes %>
<a hidden href="<%= new_podcast_path %>" data-dynamic-form-target="link" data-turbo-frame="itunes-subcategory"></a>
<%= form.fields_for :default_feed do |fields| %>
<%# HACK: display nested validation errors %>
<% nested_errors = fields.object.errors.full_messages_for("itunes_categories.name").join(", ") %>
<% klass = nested_errors.present? ? "is-invalid form-select" : "form-select" %>
<%= fields.select :itunes_category, itunes_category_options, {include_blank: true}, class: klass, data: {action: "dynamic-form#change"} %>
<% if nested_errors.present? %><div class="invalid-feedback"><%= nested_errors %></div><% end %>
<%= fields.label :itunes_category %>
<%= field_help_text t(".help.itunes_category") %>
<%# update subcategory turbo-frame when category changes %>
<a hidden href="<%= new_podcast_path %>" data-dynamic-form-target="link" data-turbo-frame="itunes-subcategory"></a>
<% end %>
</div>
</div>

<div class="col-6 mb-4">
<%= turbo_frame_tag "itunes-subcategory" do %>
<div class="form-floating">
<% opts = itunes_subcategory_options(podcast.itunes_category) %>
<%= form.select :itunes_subcategory, opts, {include_blank: true}, disabled: opts.blank? %>
<%= form.label :itunes_subcategory %>
<%= form.fields_for :default_feed do |fields| %>
<% opts = itunes_subcategory_options(podcast.itunes_category) %>
<%= fields.select :itunes_subcategory, opts, {include_blank: true}, disabled: opts.blank? %>
<%= fields.label :itunes_subcategory %>
<% end %>
</div>
<% end %>
</div>
Expand Down

0 comments on commit a703cd7

Please sign in to comment.