Class: ActiveAdmin::FormBuilder
- Inherits:
-
Formtastic::SemanticFormBuilder
- Object
- Formtastic::SemanticFormBuilder
- ActiveAdmin::FormBuilder
- Defined in:
- lib/active_admin/form_builder.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#form_buffers ⇒ Object
readonly
Returns the value of attribute form_buffers.
Instance Method Summary collapse
-
#buttons(*args, &block) ⇒ Object
The buttons method always needs to be wrapped in a new buffer.
- #cancel_link(url = nil, html_options = {}, li_attributes = {}) ⇒ Object
- #commit_button(*args) ⇒ Object
- #commit_button_with_cancel_link ⇒ Object
- #datepicker_input(method, options) ⇒ Object
- #has_many(association, options = {}, &block) ⇒ Object
-
#initialize(*args) ⇒ FormBuilder
constructor
A new instance of FormBuilder.
-
#input(*args) ⇒ Object
The input method returns a properly formatted string for its contents, so we want to skip the internal buffering while building up its contents.
- #inputs(*args, &block) ⇒ Object
Constructor Details
#initialize(*args) ⇒ FormBuilder
Returns a new instance of FormBuilder.
8 9 10 11 |
# File 'lib/active_admin/form_builder.rb', line 8 def initialize(*args) @form_buffers = ["".html_safe] super end |
Instance Attribute Details
#form_buffers ⇒ Object (readonly)
Returns the value of attribute form_buffers.
6 7 8 |
# File 'lib/active_admin/form_builder.rb', line 6 def form_buffers @form_buffers end |
Instance Method Details
#buttons(*args, &block) ⇒ Object
The buttons method always needs to be wrapped in a new buffer
30 31 32 33 34 35 |
# File 'lib/active_admin/form_builder.rb', line 30 def (*args, &block) content = with_new_form_buffer do block_given? ? super : super { } end form_buffers.last << content.html_safe end |
#cancel_link(url = nil, html_options = {}, li_attributes = {}) ⇒ Object
42 43 44 45 46 |
# File 'lib/active_admin/form_builder.rb', line 42 def cancel_link(url = nil, = {}, li_attributes = {}) li_attributes[:class] ||= "cancel" url ||= {:action => "index"} template.content_tag(:li, (template.link_to I18n.t('active_admin.cancel'), url, ), li_attributes) end |
#commit_button(*args) ⇒ Object
37 38 39 40 |
# File 'lib/active_admin/form_builder.rb', line 37 def (*args) content = with_new_form_buffer{ super } form_buffers.last << content.html_safe end |
#commit_button_with_cancel_link ⇒ Object
48 49 50 51 |
# File 'lib/active_admin/form_builder.rb', line 48 def content = content << cancel_link end |
#datepicker_input(method, options) ⇒ Object
53 54 55 56 57 58 59 |
# File 'lib/active_admin/form_builder.rb', line 53 def datepicker_input(method, ) = .dup [:input_html] ||= {} [:input_html][:class] = [[:input_html][:class], "datepicker"].compact.join(' ') [:input_html][:size] ||= "10" string_input(method, ) end |
#has_many(association, options = {}, &block) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/active_admin/form_builder.rb', line 61 def has_many(association, = {}, &block) = { :for => association }.merge() [:class] ||= "" [:class] << "inputs has_many_fields" # Add Delete Links form_block = proc do |has_many_form| block.call(has_many_form) + if has_many_form.object.new_record? template.content_tag :li do template.link_to I18n.t('active_admin.has_many_delete'), "#", :onclick => "$(this).closest('.has_many_fields').remove(); return false;", :class => "button" end else end end content = with_new_form_buffer do template.content_tag :div, :class => "has_many #{association}" do form_buffers.last << template.content_tag(:h3, association.to_s.titlecase) inputs , &form_block # Capture the ADD JS js = with_new_form_buffer do inputs_for_nested_attributes :for => [association, object.class.reflect_on_association(association).klass.new], :class => "inputs has_many_fields", :for_options => { :child_index => "NEW_RECORD" }, &form_block end js = template.escape_javascript(js) js = template.link_to I18n.t('active_admin.has_many_new', :model => association.to_s.singularize.titlecase), "#", :onclick => "$(this).before('#{js}'.replace(/NEW_RECORD/g, new Date().getTime())); return false;", :class => "button" form_buffers.last << js.html_safe end end form_buffers.last << content.html_safe end |
#input(*args) ⇒ Object
The input method returns a properly formatted string for its contents, so we want to skip the internal buffering while building up its contents
23 24 25 26 27 |
# File 'lib/active_admin/form_builder.rb', line 23 def input(*args) content = with_new_form_buffer { super } return content.html_safe unless @inputs_with_block form_buffers.last << content.html_safe end |
#inputs(*args, &block) ⇒ Object
13 14 15 16 17 18 |
# File 'lib/active_admin/form_builder.rb', line 13 def inputs(*args, &block) # Store that we are creating inputs without a block @inputs_with_block = block_given? ? true : false content = with_new_form_buffer { super } form_buffers.last << content.html_safe end |