effective_assets 1.11.2 → 1.11.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/effective_assets/engine.rb +5 -1
- data/lib/effective_assets/version.rb +1 -1
- data/lib/inputs/asset_box.rb +210 -0
- data/lib/inputs/asset_box_form_input.rb +5 -0
- data/lib/inputs/asset_box_formtastic_input.rb +7 -0
- data/{app/models → lib}/inputs/asset_box_input.rb +8 -2
- data/lib/inputs/asset_box_simple_form_input.rb +5 -0
- data/{app/models → lib}/validators/asset_box_length_validator.rb +0 -0
- data/{app/models → lib}/validators/asset_box_presence_validator.rb +0 -0
- metadata +8 -8
- data/app/models/inputs/asset_box.rb +0 -213
- data/app/models/inputs/asset_box_form_input.rb +0 -7
- data/app/models/inputs/asset_box_formtastic_input.rb +0 -9
- data/app/models/inputs/asset_box_simple_form_input.rb +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 82cfdb81fc92b1b74f6c541a6c5372241e6be602dbb0a28cd9d63481e6b9a61e
|
4
|
+
data.tar.gz: 63c9c06bdd0995ab93ac45956a5d23260a2c702787507a666e68fb184242b6ee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aa569d27fc080268b9faa389b9d55e1fc167726a5092dcff4ca7e38709decc675941f1e8bf34af531ceea05a6d2085f5c68098c2748d1580bb4765322312fb9f
|
7
|
+
data.tar.gz: 69c91034760b37ccd07043461d304f77ce1ec5d00eb524e922147c511049326baad6942fd95ab938074960c8d8c6daa3eaa92adb682e68c798cfeb84abb83acc
|
@@ -2,6 +2,10 @@ module EffectiveAssets
|
|
2
2
|
class Engine < ::Rails::Engine
|
3
3
|
engine_name 'effective_assets'
|
4
4
|
|
5
|
+
config.autoload_paths += Dir["#{config.root}/lib/validators/", "#{config.root}/lib/inputs/"]
|
6
|
+
|
7
|
+
config.eager_load_paths += Dir["#{config.root}/lib/validators/", "#{config.root}/lib/inputs/"]
|
8
|
+
|
5
9
|
# Include acts_as_addressable concern and allow any ActiveRecord object to call it
|
6
10
|
initializer 'effective_assets.active_record' do |app|
|
7
11
|
ActiveSupport.on_load :active_record do
|
@@ -11,7 +15,7 @@ module EffectiveAssets
|
|
11
15
|
|
12
16
|
initializer 'effective_assets.action_view' do |app|
|
13
17
|
ActiveSupport.on_load :action_view do
|
14
|
-
ActionView::Helpers::FormBuilder.send(:include,
|
18
|
+
ActionView::Helpers::FormBuilder.send(:include, AssetBoxFormInput)
|
15
19
|
end
|
16
20
|
end
|
17
21
|
|
@@ -0,0 +1,210 @@
|
|
1
|
+
class AssetBox
|
2
|
+
delegate :content_tag, :render, :current_user, :to => :@template
|
3
|
+
|
4
|
+
def initialize(object, object_name, template, method, opts)
|
5
|
+
@object = object
|
6
|
+
@object_name = object_name
|
7
|
+
@template = template
|
8
|
+
@options = initialize_options(method, opts)
|
9
|
+
end
|
10
|
+
|
11
|
+
def to_html
|
12
|
+
output = ''
|
13
|
+
output += header_html
|
14
|
+
|
15
|
+
if @options[:uploader] == :top
|
16
|
+
output += uploader_html
|
17
|
+
output += attachments_html
|
18
|
+
output += dialog_html if @options[:dialog]
|
19
|
+
else
|
20
|
+
output += attachments_html
|
21
|
+
output += dialog_html if @options[:dialog]
|
22
|
+
output += uploader_html if @options[:uploader]
|
23
|
+
end
|
24
|
+
|
25
|
+
output += footer_html
|
26
|
+
|
27
|
+
output.html_safe
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def header_html
|
33
|
+
"<div id='asset-box-input-#{@options[:uid]}'
|
34
|
+
class='asset-box-input #{@options[:box]}'
|
35
|
+
data-box='#{@options[:box]}'
|
36
|
+
data-uploader='s3_#{@options[:uid]}'
|
37
|
+
data-limit='#{@options[:limit]}'
|
38
|
+
data-attachable-id='#{@options[:attachable_id]}'
|
39
|
+
data-attachable-type='#{@options[:attachable_type]}'
|
40
|
+
data-attachable-object-name='#{@object_name}'
|
41
|
+
data-attachment-style='#{@options[:attachment_style]}'
|
42
|
+
data-attachment-add-to='#{@options[:attachment_add_to]}'
|
43
|
+
data-attachment-actions='#{@options[:attachment_actions].to_json()}'
|
44
|
+
data-attachment-count='#{attachments.length}'
|
45
|
+
data-attachment-links='#{@options[:attachment_links]}'
|
46
|
+
data-over-limit-alerted='false'
|
47
|
+
data-aws-acl='#{@options[:aws_acl]}'
|
48
|
+
>".html_safe
|
49
|
+
end
|
50
|
+
|
51
|
+
def attachments_html
|
52
|
+
if @options[:attachment_style] == :table
|
53
|
+
attachments_table_html
|
54
|
+
elsif @options[:attachment_style] == :list
|
55
|
+
content_tag(:ul, build_values_html, :class => 'attachments')
|
56
|
+
else
|
57
|
+
content_tag(:div, build_values_html, :class => 'row attachments thumbnails')
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def attachments_table_html
|
62
|
+
content_tag(:table, :class => 'table') do
|
63
|
+
head = attachments_table_head_html if @options[:table_filter_bar]
|
64
|
+
body = content_tag(:tbody, build_values_html, :class => 'attachments')
|
65
|
+
head ? head + body : body
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def attachments_table_head_html
|
70
|
+
content_tag(:thead) do
|
71
|
+
content_tag(:tr) do
|
72
|
+
content_tag(:th, filter_bar_html, :colspan => 4)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def dialog_html
|
78
|
+
render(
|
79
|
+
:partial => 'asset_box_input/dialog',
|
80
|
+
:locals => {
|
81
|
+
:dialog_url => @options[:dialog_url]
|
82
|
+
}
|
83
|
+
).html_safe
|
84
|
+
end
|
85
|
+
|
86
|
+
def uploader_html
|
87
|
+
# Check that we have permission to upload.
|
88
|
+
asset = Effective::Asset.new(user_id: ((current_user.try(:id) || 1) rescue 1), upload_file: 'placeholder')
|
89
|
+
|
90
|
+
unless (EffectiveAssets.authorized?(@template.controller, :create, asset) rescue false)
|
91
|
+
@options[:btn_title] = 'Unable to upload. (cannot :create Effective::Asset)'
|
92
|
+
@options[:disabled] = true
|
93
|
+
end
|
94
|
+
|
95
|
+
html_class = [
|
96
|
+
('drop-files' if @options[:uploader_drop_files]),
|
97
|
+
((@options[:uploader_html] || {})[:class])
|
98
|
+
].compact.join(' ')
|
99
|
+
|
100
|
+
render(
|
101
|
+
:partial => 'asset_box_input/uploader',
|
102
|
+
:locals => {
|
103
|
+
:uid => @options[:uid],
|
104
|
+
:click_submit => @options[:click_submit],
|
105
|
+
:html_class => html_class,
|
106
|
+
:limit => @options[:limit],
|
107
|
+
:disabled => @options[:disabled],
|
108
|
+
:required => (@options[:required] == true && attachments.length == 0),
|
109
|
+
:file_types => @options[:file_types],
|
110
|
+
:progress_bar_partial => @options[:progress_bar_partial],
|
111
|
+
:drop_files => @options[:uploader_drop_files],
|
112
|
+
:drop_files_help_text => @options[:drop_files_help_text],
|
113
|
+
:aws_acl => @options[:aws_acl],
|
114
|
+
:btn_label => @options[:btn_label],
|
115
|
+
:btn_title => @options[:btn_title]
|
116
|
+
}
|
117
|
+
).html_safe
|
118
|
+
end
|
119
|
+
|
120
|
+
def filter_bar_html
|
121
|
+
"<input type='text' class='form-control filter-attachments' placeholder='Filter by title'>".html_safe
|
122
|
+
end
|
123
|
+
|
124
|
+
def build_values_html
|
125
|
+
attachment_partial =
|
126
|
+
case @options[:attachment_style]
|
127
|
+
when :table
|
128
|
+
'attachment_as_table'
|
129
|
+
when :list
|
130
|
+
'attachment_as_list'
|
131
|
+
when :thumbnail
|
132
|
+
'attachment_as_thumbnail'
|
133
|
+
when nil
|
134
|
+
'attachment_as_thumbnail'
|
135
|
+
else
|
136
|
+
raise "unknown AssetBox attachment_style: #{@options[:attachment_style]}. Valid options are :thumbnail, :list and :table"
|
137
|
+
end
|
138
|
+
|
139
|
+
render(
|
140
|
+
:partial => "asset_box_input/#{attachment_partial}",
|
141
|
+
:collection => attachments.reject { |attachment| attachment.marked_for_destruction? },
|
142
|
+
:as => :attachment,
|
143
|
+
:locals => {
|
144
|
+
:attachment_actions => @options[:attachment_actions].map { |action| action.to_s },
|
145
|
+
:attachment_links => @options[:attachment_links],
|
146
|
+
:limit => @options[:limit],
|
147
|
+
:disabled => @options[:disabled],
|
148
|
+
:attachable_object_name => @object_name
|
149
|
+
}
|
150
|
+
)
|
151
|
+
end
|
152
|
+
|
153
|
+
def footer_html
|
154
|
+
"</div>".html_safe
|
155
|
+
end
|
156
|
+
|
157
|
+
def attachments
|
158
|
+
@object.attachments.select { |attachment| attachment.box == @options[:box] }
|
159
|
+
end
|
160
|
+
|
161
|
+
def initialize_options(method, opts)
|
162
|
+
{
|
163
|
+
:uploader => true, # :top, :bottom, true or false
|
164
|
+
:uploader_drop_files => false,
|
165
|
+
:drop_files_help_text => 'Drop files here',
|
166
|
+
:progress_bar_partial => 'asset_box_input/progress_bar_template',
|
167
|
+
:attachment_style => :thumbnail, # :thumbnail, :table, or :list
|
168
|
+
:attachment_links => true,
|
169
|
+
:attachment_add_to => :bottom, # :bottom or :top (of attachments div)
|
170
|
+
:attachment_actions => [:remove], # or :insert, :delete, :remove
|
171
|
+
:table_filter_bar => false,
|
172
|
+
:dialog => false,
|
173
|
+
:dialog_url => @template.effective_assets.effective_assets_path,
|
174
|
+
:disabled => false,
|
175
|
+
:file_types => [:any],
|
176
|
+
:btn_label => 'Upload...',
|
177
|
+
:btn_title => 'Click or drag & drop to upload a file'
|
178
|
+
}.merge(opts).tap do |options|
|
179
|
+
options[:method] = method.to_s
|
180
|
+
options[:box] = method.to_s.pluralize
|
181
|
+
options[:attachable_id] ||= (@object.try(:id) rescue nil)
|
182
|
+
options[:attachable_type] ||= @object.class.name.titleize.gsub(" ", "_").gsub('/', '_').downcase
|
183
|
+
|
184
|
+
# The logic for the AWS ACL is such that:
|
185
|
+
# 1.) If the :private or :aws_acl keys are set on the asset_box input, use those values
|
186
|
+
# 2.) If the :private or :public keys are set on the acts_as_asset_box declaration, use those values
|
187
|
+
# 3.) Fall back to default EffectiveAssets.aws_acl as per config file
|
188
|
+
|
189
|
+
uploader_private = (opts[:private] == true || opts[:public] == false || opts[:aws_acl] == EffectiveAssets::AWS_PRIVATE)
|
190
|
+
uploader_public = (opts[:private] == false || opts[:public] == true || opts[:aws_acl] == EffectiveAssets::AWS_PUBLIC)
|
191
|
+
object_private = ((@object.asset_boxes[method] == :private || @object.asset_boxes[method].first[:private] == true || @object.asset_boxes[method].first[:public] == false) rescue false)
|
192
|
+
object_public = ((@object.asset_boxes[method] == :public || @object.asset_boxes[method].first[:public] == true || @object.asset_boxes[method].first[:private] == false) rescue false)
|
193
|
+
|
194
|
+
if uploader_private
|
195
|
+
options[:aws_acl] = EffectiveAssets::AWS_PRIVATE
|
196
|
+
elsif uploader_public
|
197
|
+
options[:aws_acl] = EffectiveAssets::AWS_PUBLIC
|
198
|
+
elsif object_private
|
199
|
+
options[:aws_acl] = EffectiveAssets::AWS_PRIVATE
|
200
|
+
elsif object_public
|
201
|
+
options[:aws_acl] = EffectiveAssets::AWS_PUBLIC
|
202
|
+
else
|
203
|
+
options[:aws_acl] = EffectiveAssets.aws_acl
|
204
|
+
end
|
205
|
+
|
206
|
+
options[:uid] = "#{options[:attachable_type]}-#{options[:attachable_id]}-#{options[:method]}-#{Time.zone.now.to_f}".parameterize
|
207
|
+
options[:limit] = (options[:method] == options[:box] ? (options[:limit] || 10000) : 1)
|
208
|
+
end
|
209
|
+
end
|
210
|
+
end
|
@@ -4,15 +4,21 @@
|
|
4
4
|
if defined?(SimpleForm)
|
5
5
|
class AssetBoxInput < SimpleForm::Inputs::FileInput
|
6
6
|
def input(wrapper_options = nil)
|
7
|
-
|
7
|
+
AssetBox.new(object, object_name, template, attribute_name, options).to_html
|
8
8
|
end
|
9
9
|
end
|
10
10
|
elsif defined?(Formtastic)
|
11
11
|
class AssetBoxInput < Formtastic::Inputs::FileInput
|
12
12
|
def to_html
|
13
13
|
input_wrapping do
|
14
|
-
label_html <<
|
14
|
+
label_html << AssetBox.new(@object, @object_name, @template, @method, @options).to_html
|
15
15
|
end
|
16
16
|
end
|
17
17
|
end
|
18
|
+
else
|
19
|
+
class AssetBoxInput < Object
|
20
|
+
def to_html
|
21
|
+
'expected simpleform or formtastic'
|
22
|
+
end
|
23
|
+
end
|
18
24
|
end
|
File without changes
|
File without changes
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: effective_assets
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.11.
|
4
|
+
version: 1.11.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Code and Effect
|
@@ -173,13 +173,6 @@ files:
|
|
173
173
|
- app/models/effective/attachment.rb
|
174
174
|
- app/models/effective/iframe_upload.rb
|
175
175
|
- app/models/effective/snippets/effective_asset.rb
|
176
|
-
- app/models/inputs/asset_box.rb
|
177
|
-
- app/models/inputs/asset_box_form_input.rb
|
178
|
-
- app/models/inputs/asset_box_formtastic_input.rb
|
179
|
-
- app/models/inputs/asset_box_input.rb
|
180
|
-
- app/models/inputs/asset_box_simple_form_input.rb
|
181
|
-
- app/models/validators/asset_box_length_validator.rb
|
182
|
-
- app/models/validators/asset_box_presence_validator.rb
|
183
176
|
- app/uploaders/effective_assets_uploader.rb
|
184
177
|
- app/uploaders/test_asset_uploader.rb
|
185
178
|
- app/views/active_admin/effective_assets/_edit.html.haml
|
@@ -202,7 +195,14 @@ files:
|
|
202
195
|
- lib/effective_assets/version.rb
|
203
196
|
- lib/generators/effective_assets/install_generator.rb
|
204
197
|
- lib/generators/templates/asset_uploader.rb
|
198
|
+
- lib/inputs/asset_box.rb
|
199
|
+
- lib/inputs/asset_box_form_input.rb
|
200
|
+
- lib/inputs/asset_box_formtastic_input.rb
|
201
|
+
- lib/inputs/asset_box_input.rb
|
202
|
+
- lib/inputs/asset_box_simple_form_input.rb
|
205
203
|
- lib/tasks/effective_assets_tasks.rake
|
204
|
+
- lib/validators/asset_box_length_validator.rb
|
205
|
+
- lib/validators/asset_box_presence_validator.rb
|
206
206
|
homepage: https://github.com/code-and-effect/effective_assets
|
207
207
|
licenses:
|
208
208
|
- MIT
|
@@ -1,213 +0,0 @@
|
|
1
|
-
module Inputs
|
2
|
-
class AssetBox
|
3
|
-
delegate :content_tag, :render, :current_user, :to => :@template
|
4
|
-
|
5
|
-
def initialize(object, object_name, template, method, opts)
|
6
|
-
@object = object
|
7
|
-
@object_name = object_name
|
8
|
-
@template = template
|
9
|
-
@options = initialize_options(method, opts)
|
10
|
-
end
|
11
|
-
|
12
|
-
def to_html
|
13
|
-
output = ''
|
14
|
-
output += header_html
|
15
|
-
|
16
|
-
if @options[:uploader] == :top
|
17
|
-
output += uploader_html
|
18
|
-
output += attachments_html
|
19
|
-
output += dialog_html if @options[:dialog]
|
20
|
-
else
|
21
|
-
output += attachments_html
|
22
|
-
output += dialog_html if @options[:dialog]
|
23
|
-
output += uploader_html if @options[:uploader]
|
24
|
-
end
|
25
|
-
|
26
|
-
output += footer_html
|
27
|
-
|
28
|
-
output.html_safe
|
29
|
-
end
|
30
|
-
|
31
|
-
private
|
32
|
-
|
33
|
-
def header_html
|
34
|
-
"<div id='asset-box-input-#{@options[:uid]}'
|
35
|
-
class='asset-box-input #{@options[:box]}'
|
36
|
-
data-box='#{@options[:box]}'
|
37
|
-
data-uploader='s3_#{@options[:uid]}'
|
38
|
-
data-limit='#{@options[:limit]}'
|
39
|
-
data-attachable-id='#{@options[:attachable_id]}'
|
40
|
-
data-attachable-type='#{@options[:attachable_type]}'
|
41
|
-
data-attachable-object-name='#{@object_name}'
|
42
|
-
data-attachment-style='#{@options[:attachment_style]}'
|
43
|
-
data-attachment-add-to='#{@options[:attachment_add_to]}'
|
44
|
-
data-attachment-actions='#{@options[:attachment_actions].to_json()}'
|
45
|
-
data-attachment-count='#{attachments.length}'
|
46
|
-
data-attachment-links='#{@options[:attachment_links]}'
|
47
|
-
data-over-limit-alerted='false'
|
48
|
-
data-aws-acl='#{@options[:aws_acl]}'
|
49
|
-
>".html_safe
|
50
|
-
end
|
51
|
-
|
52
|
-
def attachments_html
|
53
|
-
if @options[:attachment_style] == :table
|
54
|
-
attachments_table_html
|
55
|
-
elsif @options[:attachment_style] == :list
|
56
|
-
content_tag(:ul, build_values_html, :class => 'attachments')
|
57
|
-
else
|
58
|
-
content_tag(:div, build_values_html, :class => 'row attachments thumbnails')
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
def attachments_table_html
|
63
|
-
content_tag(:table, :class => 'table') do
|
64
|
-
head = attachments_table_head_html if @options[:table_filter_bar]
|
65
|
-
body = content_tag(:tbody, build_values_html, :class => 'attachments')
|
66
|
-
head ? head + body : body
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
def attachments_table_head_html
|
71
|
-
content_tag(:thead) do
|
72
|
-
content_tag(:tr) do
|
73
|
-
content_tag(:th, filter_bar_html, :colspan => 4)
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
def dialog_html
|
79
|
-
render(
|
80
|
-
:partial => 'asset_box_input/dialog',
|
81
|
-
:locals => {
|
82
|
-
:dialog_url => @options[:dialog_url]
|
83
|
-
}
|
84
|
-
).html_safe
|
85
|
-
end
|
86
|
-
|
87
|
-
def uploader_html
|
88
|
-
# Check that we have permission to upload.
|
89
|
-
asset = Effective::Asset.new(user_id: ((current_user.try(:id) || 1) rescue 1), upload_file: 'placeholder')
|
90
|
-
|
91
|
-
unless (EffectiveAssets.authorized?(@template.controller, :create, asset) rescue false)
|
92
|
-
@options[:btn_title] = 'Unable to upload. (cannot :create Effective::Asset)'
|
93
|
-
@options[:disabled] = true
|
94
|
-
end
|
95
|
-
|
96
|
-
html_class = [
|
97
|
-
('drop-files' if @options[:uploader_drop_files]),
|
98
|
-
((@options[:uploader_html] || {})[:class])
|
99
|
-
].compact.join(' ')
|
100
|
-
|
101
|
-
render(
|
102
|
-
:partial => 'asset_box_input/uploader',
|
103
|
-
:locals => {
|
104
|
-
:uid => @options[:uid],
|
105
|
-
:click_submit => @options[:click_submit],
|
106
|
-
:html_class => html_class,
|
107
|
-
:limit => @options[:limit],
|
108
|
-
:disabled => @options[:disabled],
|
109
|
-
:required => (@options[:required] == true && attachments.length == 0),
|
110
|
-
:file_types => @options[:file_types],
|
111
|
-
:progress_bar_partial => @options[:progress_bar_partial],
|
112
|
-
:drop_files => @options[:uploader_drop_files],
|
113
|
-
:drop_files_help_text => @options[:drop_files_help_text],
|
114
|
-
:aws_acl => @options[:aws_acl],
|
115
|
-
:btn_label => @options[:btn_label],
|
116
|
-
:btn_title => @options[:btn_title]
|
117
|
-
}
|
118
|
-
).html_safe
|
119
|
-
end
|
120
|
-
|
121
|
-
def filter_bar_html
|
122
|
-
"<input type='text' class='form-control filter-attachments' placeholder='Filter by title'>".html_safe
|
123
|
-
end
|
124
|
-
|
125
|
-
def build_values_html
|
126
|
-
attachment_partial =
|
127
|
-
case @options[:attachment_style]
|
128
|
-
when :table
|
129
|
-
'attachment_as_table'
|
130
|
-
when :list
|
131
|
-
'attachment_as_list'
|
132
|
-
when :thumbnail
|
133
|
-
'attachment_as_thumbnail'
|
134
|
-
when nil
|
135
|
-
'attachment_as_thumbnail'
|
136
|
-
else
|
137
|
-
raise "unknown AssetBox attachment_style: #{@options[:attachment_style]}. Valid options are :thumbnail, :list and :table"
|
138
|
-
end
|
139
|
-
|
140
|
-
render(
|
141
|
-
:partial => "asset_box_input/#{attachment_partial}",
|
142
|
-
:collection => attachments.reject { |attachment| attachment.marked_for_destruction? },
|
143
|
-
:as => :attachment,
|
144
|
-
:locals => {
|
145
|
-
:attachment_actions => @options[:attachment_actions].map { |action| action.to_s },
|
146
|
-
:attachment_links => @options[:attachment_links],
|
147
|
-
:limit => @options[:limit],
|
148
|
-
:disabled => @options[:disabled],
|
149
|
-
:attachable_object_name => @object_name
|
150
|
-
}
|
151
|
-
)
|
152
|
-
end
|
153
|
-
|
154
|
-
def footer_html
|
155
|
-
"</div>".html_safe
|
156
|
-
end
|
157
|
-
|
158
|
-
def attachments
|
159
|
-
@object.attachments.select { |attachment| attachment.box == @options[:box] }
|
160
|
-
end
|
161
|
-
|
162
|
-
def initialize_options(method, opts)
|
163
|
-
{
|
164
|
-
:uploader => true, # :top, :bottom, true or false
|
165
|
-
:uploader_drop_files => false,
|
166
|
-
:drop_files_help_text => 'Drop files here',
|
167
|
-
:progress_bar_partial => 'asset_box_input/progress_bar_template',
|
168
|
-
:attachment_style => :thumbnail, # :thumbnail, :table, or :list
|
169
|
-
:attachment_links => true,
|
170
|
-
:attachment_add_to => :bottom, # :bottom or :top (of attachments div)
|
171
|
-
:attachment_actions => [:remove], # or :insert, :delete, :remove
|
172
|
-
:table_filter_bar => false,
|
173
|
-
:dialog => false,
|
174
|
-
:dialog_url => @template.effective_assets.effective_assets_path,
|
175
|
-
:disabled => false,
|
176
|
-
:file_types => [:any],
|
177
|
-
:btn_label => 'Upload...',
|
178
|
-
:btn_title => 'Click or drag & drop to upload a file'
|
179
|
-
}.merge(opts).tap do |options|
|
180
|
-
options[:method] = method.to_s
|
181
|
-
options[:box] = method.to_s.pluralize
|
182
|
-
options[:attachable_id] ||= (@object.try(:id) rescue nil)
|
183
|
-
options[:attachable_type] ||= @object.class.name.titleize.gsub(" ", "_").gsub('/', '_').downcase
|
184
|
-
|
185
|
-
# The logic for the AWS ACL is such that:
|
186
|
-
# 1.) If the :private or :aws_acl keys are set on the asset_box input, use those values
|
187
|
-
# 2.) If the :private or :public keys are set on the acts_as_asset_box declaration, use those values
|
188
|
-
# 3.) Fall back to default EffectiveAssets.aws_acl as per config file
|
189
|
-
|
190
|
-
uploader_private = (opts[:private] == true || opts[:public] == false || opts[:aws_acl] == EffectiveAssets::AWS_PRIVATE)
|
191
|
-
uploader_public = (opts[:private] == false || opts[:public] == true || opts[:aws_acl] == EffectiveAssets::AWS_PUBLIC)
|
192
|
-
object_private = ((@object.asset_boxes[method] == :private || @object.asset_boxes[method].first[:private] == true || @object.asset_boxes[method].first[:public] == false) rescue false)
|
193
|
-
object_public = ((@object.asset_boxes[method] == :public || @object.asset_boxes[method].first[:public] == true || @object.asset_boxes[method].first[:private] == false) rescue false)
|
194
|
-
|
195
|
-
if uploader_private
|
196
|
-
options[:aws_acl] = EffectiveAssets::AWS_PRIVATE
|
197
|
-
elsif uploader_public
|
198
|
-
options[:aws_acl] = EffectiveAssets::AWS_PUBLIC
|
199
|
-
elsif object_private
|
200
|
-
options[:aws_acl] = EffectiveAssets::AWS_PRIVATE
|
201
|
-
elsif object_public
|
202
|
-
options[:aws_acl] = EffectiveAssets::AWS_PUBLIC
|
203
|
-
else
|
204
|
-
options[:aws_acl] = EffectiveAssets.aws_acl
|
205
|
-
end
|
206
|
-
|
207
|
-
options[:uid] = "#{options[:attachable_type]}-#{options[:attachable_id]}-#{options[:method]}-#{Time.zone.now.to_f}".parameterize
|
208
|
-
options[:limit] = (options[:method] == options[:box] ? (options[:limit] || 10000) : 1)
|
209
|
-
end
|
210
|
-
end
|
211
|
-
end
|
212
|
-
end
|
213
|
-
|