Class: Formstrap::FileView
Instance Method Summary
collapse
Methods inherited from ViewModel
#attributes, #initialize, #to_hash
Constructor Details
This class inherits a constructor from ViewModel
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class ViewModel
Instance Method Details
#attached ⇒ Object
41
42
43
|
# File 'app/models/formstrap/file_view.rb', line 41
def attached
form.object&.send(attribute)
end
|
#attachments ⇒ Object
45
46
47
|
# File 'app/models/formstrap/file_view.rb', line 45
def attachments
attached&.attachments || []
end
|
#destroy ⇒ Object
37
38
39
|
# File 'app/models/formstrap/file_view.rb', line 37
def destroy
@destroy || false
end
|
#dropzone_options ⇒ Object
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
# File 'app/models/formstrap/file_view.rb', line 57
def dropzone_options
if dropzone
{
class: ["formstrap-dropzone", validation_class],
data: {
controller: "dropzone"
}
}
else
{
class: validation_class
}
end
end
|
18
19
20
21
22
|
# File 'app/models/formstrap/file_view.rb', line 18
def input_group_options
default_input_group_options
.deep_merge(label_input_group_options)
.deep_merge(@input_group || {})
end
|
10
11
12
13
14
15
16
|
# File 'app/models/formstrap/file_view.rb', line 10
def input_options
keys = attributes - %i[append attribute dropzone destroy form input_group label prepend preview validate wrapper]
options = to_h.slice(*keys)
options = default_input_options.deep_merge(options)
options = options.deep_merge(required: false) if attachments.any?
options
end
|
#nested_attribute ⇒ Object
53
54
55
|
# File 'app/models/formstrap/file_view.rb', line 53
def nested_attribute
attached.is_a?(ActiveStorage::Attached::Many) ? :"#{attribute}_attachments" : :"#{attribute}_attachment"
end
|
#number_of_files ⇒ Object
49
50
51
|
# File 'app/models/formstrap/file_view.rb', line 49
def number_of_files
multiple ? 2 : 1
end
|
#preview ⇒ Object
33
34
35
|
# File 'app/models/formstrap/file_view.rb', line 33
def preview
@preview || dropzone
end
|
#wrapper_options ⇒ Object
24
25
26
27
28
29
30
31
|
# File 'app/models/formstrap/file_view.rb', line 24
def wrapper_options
default_wrapper_options.deep_merge({
class: ["mb-3 formstrap-file", ("form-floating" if float)],
data: {
controller: ("file-preview" if preview)
}
}).deep_merge(@wrapper || {})
end
|