Class: Effective::FormInputs::FileField
Constant Summary
Effective::FormInput::BLANK, Effective::FormInput::EXCLUSIVE_CLASS_PREFIXES, Effective::FormInput::EXCLUSIVE_CLASS_SUFFIXES
Instance Attribute Summary
#name, #options
Instance Method Summary
collapse
#feedback_options, #hint_options, #initialize, #input_group_options, #input_js_options, #label_options, #to_html, #wrapper_options
Instance Method Details
#build_attachment(attachment) ⇒ Object
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'app/models/effective/form_inputs/file_field.rb', line 30
def build_attachment(attachment)
url = (@template.url_for(attachment) rescue false)
return unless url
content_tag(:div, class: 'col') do
content_tag(:div, class: 'card mb-3') do
if attachment.image?
content_tag(:div, class: 'card-body') do
content_tag(:img, '', class: 'img-fluid', src: url, alt: attachment.filename.to_s) +
link_to(attachment.filename, url, class: 'card-link')
end
else
content_tag(:div, class: 'card-body') do
content_tag(:p, link_to(attachment.filename, url, class: 'card-link'), class: 'card-text') +
content_tag(:p, class: 'card-text') do
(attachment.content_type + '<br>' + @template.number_to_human_size(attachment.byte_size)).html_safe
end
end
end.html_safe
end
end
end
|
#build_attachments ⇒ Object
22
23
24
25
26
27
28
|
# File 'app/models/effective/form_inputs/file_field.rb', line 22
def build_attachments
return ''.html_safe unless object.respond_to?(name) && object.send(name).respond_to?(:attached?) && object.send(name).attached?
attachments = object.send(name).respond_to?(:length) ? object.send(name) : [object.send(name)]
content_tag(:div, attachments.map { |attachment| build_attachment(attachment) }.join.html_safe, class: 'attachments row')
end
|
5
6
7
|
# File 'app/models/effective/form_inputs/file_field.rb', line 5
def build_input(&block)
build_attachments + build_uploads + super
end
|
#build_uploads ⇒ Object
55
56
57
|
# File 'app/models/effective/form_inputs/file_field.rb', line 55
def build_uploads
content_tag(:div, '', class: 'uploads')
end
|
9
10
11
12
13
14
15
16
|
# File 'app/models/effective/form_inputs/file_field.rb', line 9
def input_html_options
{
class: 'form-control form-control-file btn btn-outline-secondary',
multiple: multiple?,
direct_upload: true,
'data-progress-template': progress_template
}
end
|
#multiple? ⇒ Boolean
18
19
20
|
# File 'app/models/effective/form_inputs/file_field.rb', line 18
def multiple?
name.to_s.pluralize == name.to_s
end
|
#progress_template ⇒ Object
59
60
61
62
63
64
|
# File 'app/models/effective/form_inputs/file_field.rb', line 59
def progress_template
content_tag(:div, class: 'direct-upload direct-upload--pending', 'data-direct-upload-id': '$ID$') do
content_tag(:div, '', class: 'direct-upload__progress', style: 'width: 0%') +
content_tag(:span, '$FILENAME$', class: 'direct-upload__filename')
end
end
|