Class: Uchi::Field::HasMany::Edit
Instance Attribute Summary
Attributes inherited from Base::Edit
#form, #hint, #label
#field, #record, #repository
Instance Method Summary
collapse
Methods inherited from Base::Edit
#initialize
#initialize, #value
Instance Method Details
#associated_records ⇒ Object
9
10
11
12
13
14
|
# File 'app/components/uchi/field/has_many.rb', line 9
def associated_records
records = field.value(record)
return [] if records.nil?
associated_repository.find_all(scope: records)
end
|
#associated_repository ⇒ Object
16
17
18
19
20
21
22
|
# File 'app/components/uchi/field/has_many.rb', line 16
def associated_repository
@associated_repository ||= begin
model = reflection.klass
repository_class = Uchi::Repository.for_model(model)
repository_class.new
end
end
|
#attribute_name ⇒ Object
24
25
26
|
# File 'app/components/uchi/field/has_many.rb', line 24
def attribute_name
"#{field.name.to_s.singularize}_ids"
end
|
28
29
30
|
# File 'app/components/uchi/field/has_many.rb', line 28
def dom_id_for_filter_query_input
"#{form.object_name}_#{attribute_name}_has_many_filter_query"
end
|
#dom_id_for_toggle ⇒ Object
32
33
34
|
# File 'app/components/uchi/field/has_many.rb', line 32
def dom_id_for_toggle
"#{form.object_name}_#{attribute_name}_has_many_toggle"
end
|
36
37
38
|
# File 'app/components/uchi/field/has_many.rb', line 36
def field_name_for_input
"#{form.object_name}[#{attribute_name}][]"
end
|
#record_title(record) ⇒ Object
40
41
42
43
44
|
# File 'app/components/uchi/field/has_many.rb', line 40
def record_title(record)
return "" if record.nil?
associated_repository.title(record)
end
|
#selected_titles ⇒ Object
46
47
48
|
# File 'app/components/uchi/field/has_many.rb', line 46
def selected_titles
associated_records.map { |record| record_title(record) }.join(", ")
end
|