Module: Para::FormBuilder::Containers

Defined in:
lib/para/form_builder/containers.rb

Instance Method Summary collapse

Instance Method Details

#actions(options = {}, &block) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/para/form_builder/containers.rb', line 18

def actions(options = {}, &block)
  template.(:div, class: 'block form-actions form-group') do
    template.(:div, class: 'col-sm-9 col-sm-offset-3') do
      if block
        template.capture(&block)
      else
        if options.empty?
          options[:only] = template.instance_variable_get(:@component).default_form_actions
        end
        actions_buttons_for(options).join("\n").html_safe
      end
    end
  end
end

#actions_buttons_for(options) ⇒ Object



33
34
35
36
37
38
39
40
41
# File 'lib/para/form_builder/containers.rb', line 33

def actions_buttons_for(options)
  names = [:submit, :submit_and_edit, :submit_and_add_another, :cancel]

  names.select! { |name| Array.wrap(options[:only]).include?(name) } if options[:only]
  names.reject! { |name| Array.wrap(options[:except]).include?(name) } if options[:except]
  buttons = names.map { |name| send(:"para_#{ name }_button") }
  buttons.unshift(return_to_hidden_field)
  buttons
end

#component_pathObject



71
72
73
74
75
# File 'lib/para/form_builder/containers.rb', line 71

def component_path
  if (component = template.instance_variable_get(:@component))
    component.path
  end
end

#fieldset(options = {}, &block) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/para/form_builder/containers.rb', line 4

def fieldset(options = {}, &block)
  template.(:div, class: 'block form-inputs') do
    buffer = if (title = options[:title])
      template.(:div, class: 'form-group') do
        template.(:legend, title)
      end
    else
      ''.html_safe
    end

    buffer + template.capture(&block)
  end
end

#para_cancel_buttonObject



59
60
61
62
63
64
65
# File 'lib/para/form_builder/containers.rb', line 59

def para_cancel_button
  template.link_to(
    ::I18n.t('para.shared.cancel'),
    return_to_path,
    class: 'btn btn-danger'
  )
end

#para_submit_and_add_another_buttonObject



55
56
57
# File 'lib/para/form_builder/containers.rb', line 55

def para_submit_and_add_another_button
  button(:submit, ::I18n.t('para.shared.save_and_add_another_button'), name: '_save_and_add_another', class: 'btn-primary')
end

#para_submit_and_edit_buttonObject



51
52
53
# File 'lib/para/form_builder/containers.rb', line 51

def para_submit_and_edit_button
  button(:submit, ::I18n.t('para.shared.save_and_edit'), name: '_save_and_edit', class: 'btn-primary')
end

#para_submit_button(options = {}) ⇒ Object



47
48
49
# File 'lib/para/form_builder/containers.rb', line 47

def para_submit_button(options = {})
  button(:submit, ::I18n.t('para.shared.save'), name: '_save', class: 'btn-success')
end

#return_to_hidden_fieldObject



43
44
45
# File 'lib/para/form_builder/containers.rb', line 43

def return_to_hidden_field
  template.hidden_field_tag(:return_to, return_to_path)
end

#return_to_pathObject



67
68
69
# File 'lib/para/form_builder/containers.rb', line 67

def return_to_path
  template.params[:return_to].presence || component_path
end