Class: Effective::FormInputs::HasMany
- Inherits:
-
Effective::FormInput
- Object
- Effective::FormInput
- Effective::FormInputs::HasMany
- Defined in:
- app/models/effective/form_inputs/has_many.rb
Constant Summary collapse
- BLANK =
''.html_safe
Constants inherited from Effective::FormInput
Effective::FormInput::DEFAULT_FEEDBACK_OPTIONS, Effective::FormInput::DEFAULT_INPUT_GROUP_OPTIONS, Effective::FormInput::EMPTY_HASH, Effective::FormInput::EXCLUSIVE_CLASS_PREFIXES, Effective::FormInput::EXCLUSIVE_CLASS_SUFFIXES, Effective::FormInput::HORIZONTAL_LABEL_OPTIONS, Effective::FormInput::HORIZONTAL_WRAPPER_OPTIONS, Effective::FormInput::INLINE_LABEL_OPTIONS, Effective::FormInput::VERTICAL_WRAPPER_OPTIONS
Instance Attribute Summary
Attributes inherited from Effective::FormInput
Instance Method Summary collapse
-
#add? ⇒ Boolean
add: true.
-
#build? ⇒ Boolean
build: true.
- #can_remove_method ⇒ Object
- #collection ⇒ Object
-
#display ⇒ Object
cards: false.
-
#errors? ⇒ Boolean
errors: true.
- #input_html_options ⇒ Object
- #input_js_options ⇒ Object
-
#insert ⇒ Object
insert: false.
- #insert? ⇒ Boolean
-
#remove ⇒ Object
remove: true.
- #remove? ⇒ Boolean
-
#reorder? ⇒ Boolean
reorder: true.
- #to_html(&block) ⇒ Object
Methods inherited from Effective::FormInput
#feedback_options, #hint_options, #initialize, #input_group_options, #label_options, #wrapper_options
Constructor Details
This class inherits a constructor from Effective::FormInput
Instance Method Details
#add? ⇒ Boolean
add: true
47 48 49 50 51 52 53 54 |
# File 'app/models/effective/form_inputs/has_many.rb', line 47 def add? return @add unless @add.nil? @add ||= begin add = [:input].delete(:add) add.nil? ? true : add end end |
#build? ⇒ Boolean
build: true
37 38 39 40 41 42 43 44 |
# File 'app/models/effective/form_inputs/has_many.rb', line 37 def build? return @build unless @build.nil? @build ||= begin build = [:input].delete(:build) build.nil? ? true : build end end |
#can_remove_method ⇒ Object
100 101 102 103 |
# File 'app/models/effective/form_inputs/has_many.rb', line 100 def can_remove_method return @can_remove_method unless @can_remove_method.nil? @can_remove_method = ([:input].delete(:can_remove_method) || false) end |
#collection ⇒ Object
27 28 29 |
# File 'app/models/effective/form_inputs/has_many.rb', line 27 def collection Array([:input][:collection] || object.send(name)) end |
#display ⇒ Object
cards: false
32 33 34 |
# File 'app/models/effective/form_inputs/has_many.rb', line 32 def display @display ||= ([:input].delete(:cards) ? :cards : :rows) end |
#errors? ⇒ Boolean
errors: true
71 72 73 74 75 76 77 78 |
# File 'app/models/effective/form_inputs/has_many.rb', line 71 def errors? return @errors unless @errors.nil? @errors ||= begin errors = [:input].delete(:errors) errors.nil? ? true : errors end end |
#input_html_options ⇒ Object
19 20 21 |
# File 'app/models/effective/form_inputs/has_many.rb', line 19 def { class: 'form-has-many mb-4' } end |
#input_js_options ⇒ Object
23 24 25 |
# File 'app/models/effective/form_inputs/has_many.rb', line 23 def { sortable: true } end |
#insert ⇒ Object
insert: false
57 58 59 60 61 62 63 64 |
# File 'app/models/effective/form_inputs/has_many.rb', line 57 def insert return @insert unless @insert.nil? @insert ||= begin insert = [:input].delete(:insert) insert.nil? ? false : insert end end |
#insert? ⇒ Boolean
66 67 68 |
# File 'app/models/effective/form_inputs/has_many.rb', line 66 def insert? !!insert end |
#remove ⇒ Object
remove: true
81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'app/models/effective/form_inputs/has_many.rb', line 81 def remove return @remove unless @remove.nil? @remove ||= begin remove = [:input].delete(:remove) if remove != nil remove else opts = (object.class.[name] || {}) opts[:update_only] != true && opts[:allow_destroy] != false end end end |
#remove? ⇒ Boolean
96 97 98 |
# File 'app/models/effective/form_inputs/has_many.rb', line 96 def remove? !!remove end |
#reorder? ⇒ Boolean
reorder: true
106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'app/models/effective/form_inputs/has_many.rb', line 106 def reorder? return @reorder unless @reorder.nil? @reorder ||= begin reorder = [:input].delete(:reorder) if reorder != nil reorder else build_resource().class.columns_hash['position']&.type == :integer end end end |
#to_html(&block) ⇒ Object
8 9 10 11 12 13 14 15 16 17 |
# File 'app/models/effective/form_inputs/has_many.rb', line 8 def to_html(&block) object.send(name).build() if build? && collection.blank? errors = (@builder.error(name) if errors?) || BLANK can_remove_method errors + content_tag(:div, [:input].except(:collection)) do has_many_fields_for(block) + has_many_links_for(block) end end |