Module: Para::FormBuilder::Containers
- Defined in:
- lib/para/form_builder/containers.rb
Instance Method Summary collapse
- #actions(options = {}, &block) ⇒ Object
- #actions_buttons_for(options) ⇒ Object
- #component_path ⇒ Object
- #fieldset(options = {}, &block) ⇒ Object
- #para_cancel_button ⇒ Object
- #para_submit_and_add_another_button ⇒ Object
- #para_submit_and_edit_button ⇒ Object
- #para_submit_button(_options = {}) ⇒ Object
- #return_to_hidden_field ⇒ Object
- #return_to_path ⇒ Object
Instance Method Details
#actions(options = {}, &block) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/para/form_builder/containers.rb', line 16 def actions( = {}, &block) template.content_tag(:div, class: 'form-actions') do next template.capture(&block) if block if .empty? [:only] = template.instance_variable_get(:@component).default_form_actions end ().join("\n").html_safe end end |
#actions_buttons_for(options) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/para/form_builder/containers.rb', line 29 def () names = %i[submit submit_and_edit] names << :submit_and_add_another if template.can?(:create, object.class) names << :cancel names.select! { |name| Array.wrap([:only]).include?(name) } if [:only] names.reject! { |name| Array.wrap([:except]).include?(name) } if [:except] = names.map { |name| send(:"para_#{name}_button") } .unshift(return_to_hidden_field) end |
#component_path ⇒ Object
98 99 100 101 102 |
# File 'lib/para/form_builder/containers.rb', line 98 def component_path return unless (component = template.instance_variable_get(:@component)) component.path end |
#fieldset(options = {}, &block) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 |
# File 'lib/para/form_builder/containers.rb', line 4 def fieldset( = {}, &block) template.content_tag(:div, class: 'form-inputs') do buffer = if (title = [:title]) template.content_tag(:legend, title) else ''.html_safe end buffer + template.capture(&block) end end |
#para_cancel_button ⇒ Object
86 87 88 89 90 91 92 |
# File 'lib/para/form_builder/containers.rb', line 86 def template.link_to( ::I18n.t('para.shared.cancel'), return_to_path, class: 'btn btn-danger btn-shadow' ) end |
#para_submit_and_add_another_button ⇒ Object
76 77 78 79 80 81 82 83 84 |
# File 'lib/para/form_builder/containers.rb', line 76 def ( :submit, ::I18n.t('para.shared.save_and_add_another_button'), name: '_save_and_add_another', class: 'btn-primary btn-shadow', data: { 'turbo-submits-with': ::I18n.t('para.form.shared.saving') } ) end |
#para_submit_and_edit_button ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/para/form_builder/containers.rb', line 56 def # Create a hidden field that will hold the last tab used by the user, # allowing redirection and re-rendering to display it directly current_anchor_tag = template.hidden_field_tag( :_current_anchor, template.params[:_current_anchor], data: { 'current-anchor': true } ) = ( :submit, ::I18n.t('para.shared.save_and_edit'), name: '_save_and_edit', class: 'btn-primary btn-shadow', data: { 'turbo-submits-with': ::I18n.t('para.form.shared.saving') } ) current_anchor_tag + end |
#para_submit_button(_options = {}) ⇒ Object
46 47 48 49 50 51 52 53 54 |
# File 'lib/para/form_builder/containers.rb', line 46 def ( = {}) ( :submit, ::I18n.t('para.shared.save'), name: '_save', class: 'btn-success btn-shadow', data: { 'turbo-submits-with': ::I18n.t('para.form.shared.saving') } ) end |
#return_to_hidden_field ⇒ Object
42 43 44 |
# File 'lib/para/form_builder/containers.rb', line 42 def return_to_hidden_field template.hidden_field_tag(:return_to, return_to_path) end |
#return_to_path ⇒ Object
94 95 96 |
# File 'lib/para/form_builder/containers.rb', line 94 def return_to_path template.params[:return_to].presence || component_path end |