Skip to content

Commit

Permalink
revert html format
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul-Bob committed Sep 27, 2024
1 parent 057c26e commit b38cd3b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 18 deletions.
2 changes: 1 addition & 1 deletion app/components/avo/views/resource_index_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def attach_path
paths: [*current_path, "new"],
query: {
view: @parent_resource&.view&.to_s,
for_turbo_frame: field&.try(:turbo_frame),
turbo_frame: params[:turbo_frame],
for_attribute: field&.try(:for_attribute)
}.compact
)
Expand Down
42 changes: 26 additions & 16 deletions app/controllers/avo/associations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,22 @@ def create
respond_to do |format|
if create_association
flash[:notice] = t("avo.attachment_class_attached", attachment_class: @related_resource.name)
format.turbo_stream {
actions = [
turbo_stream.turbo_frame_reload(params[:turbo_frame]),
turbo_stream.flash_alerts
]

# We want to close the modal if the user wants to add just one record
actions << turbo_stream.close_modal if params[:button] != "attach_another"

render turbo_stream: actions
}
if params[:turbo_frame].present?
format.turbo_stream {
actions = [
turbo_stream.turbo_frame_reload(params[:turbo_frame]),
turbo_stream.flash_alerts
]

# We want to close the modal if the user wants to add just one record
actions << turbo_stream.close_modal if params[:button] != "attach_another"

render turbo_stream: actions
}
else
format.html { redirect_back fallback_location: resource_view_response_path }
end
else
flash[:error] = t("avo.attachment_failed", attachment_class: @related_resource.name)
format.turbo_stream {
Expand Down Expand Up @@ -110,13 +115,18 @@ def destroy
@record.send(:"#{association_name}=", nil)
end

flash[:notice] = t("avo.attachment_class_detached", attachment_class: @attachment_class)

respond_to do |format|
flash[:notice] = t("avo.attachment_class_detached", attachment_class: @attachment_class)
format.turbo_stream do
render turbo_stream: [
turbo_stream.turbo_frame_reload(params[:turbo_frame]),
turbo_stream.flash_alerts
]
if params[:turbo_frame].present?
format.turbo_stream do
render turbo_stream: [
turbo_stream.turbo_frame_reload(params[:turbo_frame]),
turbo_stream.flash_alerts
]
end
else
format.html { redirect_to params[:referrer] || resource_view_response_path}
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/views/avo/associations/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
stacked: true,
classes: 'w-full'
%>
<%= hidden_field_tag :turbo_frame, params[:for_turbo_frame] %>
<%= hidden_field_tag :turbo_frame, params[:turbo_frame] %>
<% end %>
<% @attach_fields&.each_with_index do |field, index| %>
<%= render(Avo::Items::SwitcherComponent.new(
Expand Down

0 comments on commit b38cd3b

Please sign in to comment.