Class: ActiveAdmin::FormBuilder
- Inherits:
-
Formtastic::FormBuilder
- Object
- Formtastic::FormBuilder
- ActiveAdmin::FormBuilder
- Includes:
- MethodOrProcHelper
- Defined in:
- lib/active_admin/form_builder.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#already_in_an_inputs_block ⇒ Object
Returns the value of attribute already_in_an_inputs_block.
Instance Method Summary collapse
- #assoc_heading(assoc) ⇒ Object
- #cancel_link(url = {action: "index"}, html_options = {}, li_attrs = {}) ⇒ Object
- #has_many(assoc, options = {}, &block) ⇒ Object
- #has_many_actions(has_many_form, builder_options, contents) ⇒ Object protected
- #sorted_children(assoc, column) ⇒ Object protected
Methods included from MethodOrProcHelper
#call_method_or_exec_proc, #call_method_or_proc_on, #render_in_context, #render_or_call_method_or_proc_on
Instance Attribute Details
#already_in_an_inputs_block ⇒ Object
Returns the value of attribute already_in_an_inputs_block.
30 31 32 |
# File 'lib/active_admin/form_builder.rb', line 30 def already_in_an_inputs_block @already_in_an_inputs_block end |
Instance Method Details
#assoc_heading(assoc) ⇒ Object
32 33 34 35 |
# File 'lib/active_admin/form_builder.rb', line 32 def assoc_heading(assoc) object.class.reflect_on_association(assoc).klass.model_name. human(count: ::ActiveAdmin::Helpers::I18n::PLURAL_MANY_COUNT) end |
#cancel_link(url = {action: "index"}, html_options = {}, li_attrs = {}) ⇒ Object
24 25 26 27 28 |
# File 'lib/active_admin/form_builder.rb', line 24 def cancel_link(url = {action: "index"}, = {}, li_attrs = {}) li_attrs[:class] ||= "cancel" li_content = template.link_to I18n.t('active_admin.cancel'), url, template.content_tag(:li, li_content, li_attrs) end |
#has_many(assoc, options = {}, &block) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/active_admin/form_builder.rb', line 37 def has_many(assoc, = {}, &block) # remove options that should not render as attributes custom_settings = :new_record, :allow_destroy, :heading, :sortable, :sortable_start = {new_record: true}.merge! .slice *custom_settings = {for: assoc }.merge! .except *custom_settings [:class] = [[:class], "inputs has_many_fields"].compact.join(' ') sortable_column = [:sortable] sortable_start = .fetch(:sortable_start, 0) if sortable_column [:for] = [assoc, sorted_children(assoc, sortable_column)] end html = "".html_safe unless .key?(:heading) && ![:heading] html << template.content_tag(:h3) do [:heading] || assoc_heading(assoc) end end html << template.capture do contents = "".html_safe form_block = proc do |has_many_form| index = parent_child_index [:parent] if [:parent] block.call has_many_form, index template.concat has_many_actions(has_many_form, , "".html_safe) end template.assign(has_many_block: true) contents = without_wrapper { inputs(, &form_block) } || "".html_safe if [:new_record] contents << js_for_has_many(assoc, form_block, template, [:new_record], [:class]) else contents end end tag = @already_in_an_inputs_block ? :li : :div html = template.content_tag(tag, html, class: "has_many_container #{assoc}", 'data-sortable' => sortable_column, 'data-sortable-start' => sortable_start) template.concat(html) if template.output_buffer html end |
#has_many_actions(has_many_form, builder_options, contents) ⇒ Object (protected)
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/active_admin/form_builder.rb', line 83 def has_many_actions(has_many_form, , contents) if has_many_form.object.new_record? contents << template.content_tag(:li) do template.link_to I18n.t('active_admin.has_many_remove'), "#", class: 'button has_many_remove' end elsif call_method_or_proc_on(has_many_form.object, [:allow_destroy], exec: false) has_many_form.input(:_destroy, as: :boolean, wrapper_html: {class: 'has_many_delete'}, label: I18n.t('active_admin.has_many_delete')) end if [:sortable] has_many_form.input [:sortable], as: :hidden contents << template.content_tag(:li, class: 'handle') do "MOVE" end end contents end |
#sorted_children(assoc, column) ⇒ Object (protected)
108 109 110 111 112 113 |
# File 'lib/active_admin/form_builder.rb', line 108 def sorted_children(assoc, column) object.public_send(assoc).sort_by do |o| attribute = o.public_send column [attribute.nil? ? Float::INFINITY : attribute, o.id || Float::INFINITY] end end |