Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add turbo frame support to dialog #2958

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions app/controllers/alchemy/admin/base_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,12 @@ def render_errors_or_redirect(object, redirect_url, flash_notice)
#
def do_redirect_to(url_or_path)
respond_to do |format|
format.js {
format.js do
@redirect_url = url_or_path
render :redirect
}
format.html { redirect_to url_or_path }
end
format.turbo_stream { redirect_to(url_or_path) }
format.html { redirect_to(url_or_path) }
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/helpers/alchemy/admin/form_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module FormHelper
def alchemy_form_for(object, *args, &block)
options = args.extract_options!
options[:builder] = Alchemy::Forms::Builder
options[:remote] = request.xhr?
options[:remote] = options.key?(:remote) ? options[:remote] : request.xhr?
options[:html] = {
id: options.delete(:id),
class: ["alchemy", options.delete(:class)].compact.join(" ")
Expand Down
46 changes: 24 additions & 22 deletions app/views/alchemy/admin/resources/_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
<%= alchemy_form_for resource_instance_variable, url: resource_path(resource_instance_variable, search_filter_params) do |f| %>
<% resource_handler.editable_attributes.each do |attribute| %>
<% if relation = attribute[:relation] %>
<%= f.association relation[:name].to_sym,
collection: relation[:collection],
label_method: relation[:attr_method],
include_blank: Alchemy.t(:blank, scope: 'resources.relation_select'),
input_html: {is: 'alchemy-select'} %>
<% elsif attribute[:type].in? %i[date time datetime] %>
<%= f.datepicker attribute[:name], resource_attribute_field_options(attribute) %>
<% elsif attribute[:enum].present? %>
<%= f.input attribute[:name],
collection: attribute[:enum],
include_blank: Alchemy.t(:blank, scope: 'resources.relation_select'),
input_html: {is: 'alchemy-select'} %>
<% else %>
<%= f.input attribute[:name], resource_attribute_field_options(attribute) %>
<%= turbo_frame_tag resource_instance_variable, target: "_top" do %>
<%= alchemy_form_for resource_instance_variable, url: resource_path(resource_instance_variable, search_filter_params), remote: false do |f| %>
<% resource_handler.editable_attributes.each do |attribute| %>
<% if relation = attribute[:relation] %>
<%= f.association relation[:name].to_sym,
collection: relation[:collection],
label_method: relation[:attr_method],
include_blank: Alchemy.t(:blank, scope: 'resources.relation_select'),
input_html: {is: 'alchemy-select'} %>
<% elsif attribute[:type].in? %i[date time datetime] %>
<%= f.datepicker attribute[:name], resource_attribute_field_options(attribute) %>
<% elsif attribute[:enum].present? %>
<%= f.input attribute[:name],
collection: attribute[:enum],
include_blank: Alchemy.t(:blank, scope: 'resources.relation_select'),
input_html: {is: 'alchemy-select'} %>
<% else %>
<%= f.input attribute[:name], resource_attribute_field_options(attribute) %>
<% end %>
<% end %>
<% end %>
<% if f.object.respond_to?(:tag_list) %>
<%= render Alchemy::Admin::TagsAutocomplete.new do %>
<%= f.input :tag_list, input_html: { value: f.object.tag_list.join(",") } %>
<% if f.object.respond_to?(:tag_list) %>
<%= render Alchemy::Admin::TagsAutocomplete.new do %>
<%= f.input :tag_list, input_html: { value: f.object.tag_list.join(",") } %>
<% end %>
<% end %>
<%= f.submit Alchemy.t(:save) %>
<% end %>
<%= f.submit Alchemy.t(:save) %>
<% end %>
2 changes: 2 additions & 0 deletions spec/dummy/app/models/series.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@

class Series < ActiveRecord::Base
extend Alchemy::SearchableResource

validates :name, presence: true
end