effective_assets 0.1 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (107) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +1 -1
  3. data/README.md +341 -72
  4. data/app/assets/javascripts/effective/snippets/effective_asset.js.coffee +53 -0
  5. data/app/assets/javascripts/effective_assets.js +4 -0
  6. data/app/assets/javascripts/effective_assets/asset_box.js.coffee +36 -0
  7. data/app/assets/javascripts/effective_assets/asset_box_dialog.js.coffee +49 -0
  8. data/app/assets/javascripts/effective_assets/asset_box_drag_and_drop.js.coffee +2 -0
  9. data/app/assets/javascripts/effective_assets/asset_box_filtering.js.coffee +16 -0
  10. data/app/assets/javascripts/effective_assets/asset_box_sorting.js.coffee +8 -0
  11. data/app/assets/javascripts/effective_assets/jquery_ui_sortable.js +813 -585
  12. data/app/assets/javascripts/effective_assets/s3_uploader.js.coffee +268 -0
  13. data/app/assets/javascripts/effective_assets_iframe.js.coffee +28 -0
  14. data/app/assets/stylesheets/active_admin/effective_assets.css.scss +57 -0
  15. data/app/assets/stylesheets/effective_assets/_asset_box_input.scss +54 -175
  16. data/app/assets/stylesheets/effective_assets/_iframe_bootstrap.scss +1714 -0
  17. data/app/assets/stylesheets/effective_assets/_input_bootstrap.scss +508 -0
  18. data/app/assets/stylesheets/effective_assets_iframe.css.scss +23 -0
  19. data/app/controllers/effective/assets_controller.rb +41 -0
  20. data/app/controllers/effective/s3_uploads_controller.rb +58 -74
  21. data/app/helpers/effective_assets_helper.rb +30 -14
  22. data/app/helpers/effective_assets_s3_helper.rb +69 -0
  23. data/app/models/concerns/acts_as_asset_box.rb +75 -11
  24. data/app/models/effective/access_denied.rb +17 -0
  25. data/app/models/effective/asset.rb +130 -93
  26. data/app/models/effective/attachment.rb +2 -7
  27. data/app/models/effective/delayed_job.rb +33 -78
  28. data/app/models/effective/snippets/effective_asset.rb +19 -0
  29. data/app/models/effective/user_uploads.rb +19 -0
  30. data/app/models/inputs/asset_box.rb +154 -0
  31. data/app/models/inputs/asset_box_form_input.rb +7 -0
  32. data/app/models/inputs/asset_box_formtastic_input.rb +9 -0
  33. data/app/models/inputs/asset_box_input.rb +13 -82
  34. data/app/models/inputs/asset_box_simple_form_input.rb +7 -0
  35. data/app/uploaders/effective_assets_uploader.rb +14 -2
  36. data/app/uploaders/{asset_uploader.rb → test_asset_uploader.rb} +1 -1
  37. data/app/views/active_admin/effective_assets/_edit.html.haml +3 -3
  38. data/app/views/active_admin/effective_assets/_new.html.haml +2 -1
  39. data/app/views/asset_box_input/_attachment_as_list.html.haml +17 -0
  40. data/app/views/asset_box_input/_attachment_as_table.html.haml +32 -0
  41. data/app/views/asset_box_input/_attachment_as_thumbnail.html.haml +20 -0
  42. data/app/views/asset_box_input/_dialog.html.haml +18 -0
  43. data/app/views/asset_box_input/_progress_bar_template.html.haml +8 -0
  44. data/app/views/asset_box_input/_uploader.html.haml +21 -115
  45. data/app/views/effective/assets/iframe.html.haml +17 -0
  46. data/app/views/effective/snippets/_effective_asset.html.haml +8 -0
  47. data/config/routes.rb +8 -2
  48. data/db/migrate/01_create_effective_assets.rb.erb +3 -0
  49. data/lib/effective_assets.rb +34 -3
  50. data/lib/effective_assets/engine.rb +11 -8
  51. data/lib/effective_assets/version.rb +1 -1
  52. data/lib/generators/templates/asset_uploader.rb +35 -0
  53. data/lib/generators/templates/effective_assets.rb +31 -4
  54. data/lib/tasks/effective_assets_tasks.rake +115 -4
  55. data/spec/internal/config/database.yml +3 -0
  56. data/spec/internal/config/initializers/effective_assets.rb +18 -0
  57. data/spec/internal/config/routes.rb +3 -0
  58. data/spec/internal/db/combustion_test.sqlite +0 -0
  59. data/spec/internal/db/schema.rb +52 -0
  60. data/spec/internal/log/test.log +793 -0
  61. data/spec/{dummy → internal}/public/favicon.ico +0 -0
  62. data/spec/internal/public/sprites.png +0 -0
  63. data/spec/models/asset_spec.rb +119 -35
  64. data/spec/spec_helper.rb +9 -3
  65. metadata +95 -234
  66. data/app/assets/images/effective_assets/s3_down_button.gif +0 -0
  67. data/app/assets/images/effective_assets/s3_over_button.gif +0 -0
  68. data/app/assets/images/effective_assets/s3_up_button.gif +0 -0
  69. data/app/assets/images/effective_assets/s3_upload.swf +0 -0
  70. data/app/assets/javascripts/effective_assets/asset_box_input.js.coffee +0 -71
  71. data/app/assets/javascripts/effective_assets/asset_box_uploader.js +0 -122
  72. data/app/assets/javascripts/effective_assets/asset_box_uploader_customization.js +0 -166
  73. data/app/controllers/effective/attachments_controller.rb +0 -14
  74. data/app/views/asset_box_input/_attachment_fields.html.haml +0 -14
  75. data/spec/dummy/README.rdoc +0 -261
  76. data/spec/dummy/Rakefile +0 -7
  77. data/spec/dummy/app/assets/javascripts/application.js +0 -15
  78. data/spec/dummy/app/assets/stylesheets/application.css +0 -13
  79. data/spec/dummy/app/controllers/application_controller.rb +0 -3
  80. data/spec/dummy/app/helpers/application_helper.rb +0 -2
  81. data/spec/dummy/app/views/layouts/application.html.erb +0 -14
  82. data/spec/dummy/config.ru +0 -4
  83. data/spec/dummy/config/application.rb +0 -65
  84. data/spec/dummy/config/boot.rb +0 -10
  85. data/spec/dummy/config/database.yml +0 -25
  86. data/spec/dummy/config/environment.rb +0 -5
  87. data/spec/dummy/config/environments/development.rb +0 -37
  88. data/spec/dummy/config/environments/production.rb +0 -67
  89. data/spec/dummy/config/environments/test.rb +0 -37
  90. data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -7
  91. data/spec/dummy/config/initializers/inflections.rb +0 -15
  92. data/spec/dummy/config/initializers/mime_types.rb +0 -5
  93. data/spec/dummy/config/initializers/secret_token.rb +0 -7
  94. data/spec/dummy/config/initializers/session_store.rb +0 -8
  95. data/spec/dummy/config/initializers/wrap_parameters.rb +0 -14
  96. data/spec/dummy/config/locales/en.yml +0 -5
  97. data/spec/dummy/config/routes.rb +0 -58
  98. data/spec/dummy/db/development.sqlite3 +0 -0
  99. data/spec/dummy/db/schema.rb +0 -16
  100. data/spec/dummy/db/test.sqlite3 +0 -0
  101. data/spec/dummy/log/development.log +0 -71
  102. data/spec/dummy/log/test.log +0 -33
  103. data/spec/dummy/public/404.html +0 -26
  104. data/spec/dummy/public/422.html +0 -26
  105. data/spec/dummy/public/500.html +0 -25
  106. data/spec/dummy/script/rails +0 -6
  107. data/spec/dummy/spec_link +0 -3
@@ -0,0 +1,19 @@
1
+ if defined?(EffectiveRegions)
2
+ module Effective
3
+ module Snippets
4
+ class EffectiveAsset < Snippet
5
+ attribute :asset_id, Integer
6
+ attribute :html_class, String
7
+
8
+ def asset
9
+ @asset ||= (Effective::Asset.where(:id => asset_id).first if asset_id)
10
+ end
11
+
12
+ def snippet_tag
13
+ :span
14
+ end
15
+
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ # This is a class used for the IFrame views
2
+
3
+ module Effective
4
+ class UserUploads < ActiveRecord::Base
5
+ acts_as_asset_box :uploads
6
+
7
+ def initialize(items = nil)
8
+ super()
9
+ @column_types = {}
10
+
11
+ add_to_asset_box(:uploads, items)
12
+ end
13
+
14
+ def self.columns
15
+ @columns ||= []
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,154 @@
1
+ module Inputs
2
+ class AssetBox
3
+ delegate :content_tag, :render, :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
+ output += attachments_html
16
+
17
+ output += dialog_html if @options[:dialog]
18
+ output += uploader_html if @options[:uploader]
19
+
20
+ output += footer_html
21
+
22
+ output.html_safe
23
+ end
24
+
25
+ private
26
+
27
+ def header_html
28
+ "<div class='asset-box-input #{@options[:box]}'
29
+ data-box='#{@options[:box]}'
30
+ data-uploader='s3_#{@options[:uid]}'
31
+ data-limit='#{@options[:limit]}'
32
+ data-attachable-id='#{@options[:attachable_id]}'
33
+ data-attachable-type='#{@options[:attachable_type]}'
34
+ data-attachable-object-name='#{@object_name}'
35
+ data-attachment-style='#{@options[:attachment_style]}'
36
+ data-attachment-actions='#{@options[:attachment_actions].to_json()}'
37
+ data-aws-acl='#{@options[:aws_acl]}'
38
+ >".html_safe
39
+ end
40
+
41
+ def attachments_html
42
+ if @options[:attachment_style] == :table
43
+ content_tag(:table, :class => 'table') do
44
+ content_tag(:thead) do
45
+ content_tag(:tr) do
46
+ [
47
+ content_tag(:th, 'Thumbnail'),
48
+ content_tag(:th, 'Title'.html_safe + (@options[:table_filter_bar] ? filter_bar_html : '')),
49
+ content_tag(:th, 'Size'),
50
+ content_tag(:th)
51
+ ].join().html_safe
52
+ end
53
+ end + content_tag(:tbody, build_values_html, :class => 'attachments')
54
+ end
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 dialog_html
63
+ render(
64
+ :partial => 'asset_box_input/dialog',
65
+ :locals => {
66
+ :dialog_url => @options[:dialog_url]
67
+ }
68
+ ).html_safe
69
+ end
70
+
71
+ def uploader_html
72
+ render(
73
+ :partial => 'asset_box_input/uploader',
74
+ :locals => {
75
+ :uid => @options[:uid],
76
+ :limit => @options[:limit],
77
+ :disabled => @options[:disabled],
78
+ :file_types => @options[:file_types],
79
+ :progress_bar_partial => @options[:progress_bar_partial],
80
+ :aws_acl => @options[:aws_acl]
81
+ }
82
+ ).html_safe
83
+ end
84
+
85
+ def filter_bar_html
86
+ "<input type='text' class='form-control filter-attachments' placeholder='Search Title'>".html_safe
87
+ end
88
+
89
+ def build_values_html
90
+ count = 0
91
+
92
+ attachments.map do |attachment|
93
+ count += 1 unless attachment.marked_for_destruction?
94
+
95
+ attachment_partial =
96
+ case @options[:attachment_style]
97
+ when :table
98
+ 'attachment_as_table'
99
+ when :list
100
+ 'attachment_as_list'
101
+ when :thumbnail
102
+ 'attachment_as_thumbnail'
103
+ when nil
104
+ 'attachment_as_thumbnail'
105
+ else
106
+ raise "unknown AssetBox attachment_style: #{@options[:attachment_style]}. Valid options are :thumbnail, :list and :table"
107
+ end
108
+
109
+ render(
110
+ :partial => "asset_box_input/#{attachment_partial}",
111
+ :locals => {
112
+ :attachment => attachment,
113
+ :attachment_actions => @options[:attachment_actions].map(&:to_s),
114
+ :hidden => (count > @options[:limit]),
115
+ :disabled => @options[:disabled],
116
+ :attachable_object_name => @object_name,
117
+ }
118
+ )
119
+ end.join.html_safe
120
+ end
121
+
122
+ def footer_html
123
+ "</div>".html_safe
124
+ end
125
+
126
+ def attachments
127
+ @object.attachments.select { |attachment| attachment.box == @options[:box] }
128
+ end
129
+
130
+ def initialize_options(method, opts)
131
+ {
132
+ :uploader => true,
133
+ :progress_bar_partial => 'asset_box_input/progress_bar_template',
134
+ :attachment_style => :thumbnail, # :thumbnail, :table, or :list
135
+ :attachment_actions => [:remove], # or :insert, :delete, :remove
136
+ :table_filter_bar => false,
137
+ :dialog => false,
138
+ :dialog_url => @template.effective_assets.effective_assets_path,
139
+ :disabled => false,
140
+ :file_types => [:any],
141
+ :aws_acl => EffectiveAssets.aws_acl
142
+ }.merge(opts).tap do |options|
143
+ options[:method] = method.to_s
144
+ options[:box] = method.to_s.pluralize
145
+ options[:attachable_id] ||= (@object.try(:id) rescue nil)
146
+ options[:attachable_type] ||= @object.class.name.titleize.gsub(" ", "_").gsub('/', '_').downcase
147
+
148
+ options[:uid] = "#{options[:attachable_type]}-#{options[:attachable_id]}-#{options[:method]}-#{Time.zone.now.to_f}".parameterize
149
+ options[:limit] = (options[:method] == options[:box] ? (options[:limit] || 10000) : 1)
150
+ end
151
+ end
152
+ end
153
+ end
154
+
@@ -0,0 +1,7 @@
1
+ module Inputs
2
+ module AssetBoxFormInput
3
+ def asset_box_input(method, opts = {})
4
+ AssetBox.new(@object, @object_name, @template, method, opts).to_html
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,9 @@
1
+ if defined?(Formtastic)
2
+ class AssetBoxFormtasticInput < Formtastic::Inputs::FileInput
3
+ def to_html
4
+ input_wrapping do
5
+ label_html << Inputs::AssetBox.new(@object, @object_name, @template, @method, @options).to_html
6
+ end
7
+ end
8
+ end
9
+ end
@@ -1,87 +1,18 @@
1
- require "formtastic"
1
+ # This allows the app to call f.input :something, :as => :asset_box
2
+ # in either Formtastic or SimpleForm, but not both at the same time
2
3
 
3
- # With formtastic, just use
4
- #
5
- # = f.input :pictures, :as => :asset_box
6
- # = f.input :fav_icon, :as => :asset_box, :limit => 4, :file_types => [:jpg, :gif, :png]
7
- # = f.input :logo, :as => :asset_box, :uploader => false, :dialog => true
8
- # = f.input :logo, :as => :asset_box, :uploader => true, :uploader_visible => true
9
-
10
- class AssetBoxInput
11
- include ::Formtastic::Inputs::Base
12
-
13
- def to_html
14
- @@uid = (@@uid ||= 0) + 1 # We just need a unique number to pass along, incase we have multiple SWF Uploaders per form
15
-
16
- input_wrapping do
17
- output = label_html
18
- output += header_html
19
- output += "<div class='attachments'>".html_safe
20
- output += build_values_html
21
- output += "</div>".html_safe
22
-
23
- if options[:uploader]
24
- output += insert_uploader_html
25
- output += uploader_html
26
- end
27
-
28
- if options[:dialog]
29
- output += insert_dialog_html
30
- end
31
-
32
- output += "</div>".html_safe
4
+ if defined?(SimpleForm)
5
+ class AssetBoxInput < SimpleForm::Inputs::FileInput
6
+ def input(wrapper_options = nil)
7
+ Inputs::AssetBox.new(object, object_name, template, attribute_name, options).to_html
33
8
  end
34
9
  end
35
-
36
- def header_html
37
- "<div class='asset_box_input #{method.to_s.pluralize}' data-box='#{method.to_s.pluralize}' data-swf='s3_swf_#{@@uid}' data-limit='#{limit}' data-attachable-id='#{attachable_id}' data-attachable-type='#{attachable_type}'>".html_safe
38
- end
39
-
40
- def insert_uploader_html
41
- "<a href='#' class='asset-box-upload'>Upload...</a>".html_safe
42
- end
43
-
44
- def uploader_html
45
- template.render(:partial => 'asset_box_input/uploader', :locals => {:attachable_id => attachable_id, :attachable_type => attachable_type, :box => method.to_s.pluralize, :uid => @@uid, :file_types => options[:file_types], :limit => limit, :uploader_visible => options[:uploader_visible]}).html_safe
46
- end
47
-
48
- def insert_dialog_html
49
- "<a href='#' class='asset-box-dialog'>Attach...</a>".html_safe
50
- end
51
-
52
- def build_values_html
53
- count = 0
54
- attachments_limit = limit
55
-
56
- attachments.map do |attachment|
57
- count += 1 unless attachment.marked_for_destruction?
58
-
59
- template.render(
60
- :partial => 'asset_box_input/attachment_fields',
61
- :locals => {:attachment => attachment, :attachable_type => attachable_type, :hidden => (count > attachments_limit) }
62
- )
63
- end.join.html_safe
64
- end
65
-
66
- def attachments
67
- method_name = method.to_s.pluralize
68
- object.attachments.select { |attachment| attachment.box == method_name }
69
- end
70
-
71
- def attachable_type
72
- options[:attachable_type] || object.class.name.titleize.gsub(" ", "_").gsub('/', '_').downcase
73
- end
74
-
75
- def attachable_id
76
- options[:attachable_id] || (object.try(:id) rescue nil)
77
- end
78
-
79
- def limit
80
- method.to_s == method.to_s.pluralize ? (options[:limit] || 10000) : 1
81
- end
82
-
83
- def options
84
- {:uploader => false, :dialog => false, :uploader_visible => false}.merge(super)
10
+ elsif defined?(Formtastic)
11
+ class AssetBoxInput < Formtastic::Inputs::FileInput
12
+ def to_html
13
+ input_wrapping do
14
+ label_html << Inputs::AssetBox.new(@object, @object_name, @template, @method, @options).to_html
15
+ end
16
+ end
85
17
  end
86
-
87
18
  end
@@ -0,0 +1,7 @@
1
+ if defined?(SimpleForm)
2
+ class AssetBoxSimpleFormInput < SimpleForm::Inputs::FileInput
3
+ def input(wrapper_options = nil)
4
+ Inputs::AssetBox.new(object, object_name, template, attribute_name, options).to_html
5
+ end
6
+ end
7
+ end
@@ -3,7 +3,7 @@ class EffectiveAssetsUploader < CarrierWave::Uploader::Base
3
3
  storage :fog
4
4
 
5
5
  def store_dir
6
- "#{EffectiveAssets.aws_final_path.chomp('/')}/#{model.id}"
6
+ "#{EffectiveAssets.aws_path.chomp('/')}/#{model.id.to_i}"
7
7
  end
8
8
 
9
9
  # Returns a Hash as per the versions above
@@ -12,6 +12,18 @@ class EffectiveAssetsUploader < CarrierWave::Uploader::Base
12
12
  @versions_info ||= calculate_versions_info
13
13
  end
14
14
 
15
+ def fog_public
16
+ model.aws_acl == 'public-read' rescue true
17
+ end
18
+
19
+ def fog_authenticated_url_expiration
20
+ @fog_authenticated_url_expiration || 10.minutes
21
+ end
22
+
23
+ def fog_authenticated_url_expiration=(expires_in)
24
+ @fog_authenticated_url_expiration = expires_in
25
+ end
26
+
15
27
  protected
16
28
 
17
29
  # record_info
@@ -30,7 +42,7 @@ class EffectiveAssetsUploader < CarrierWave::Uploader::Base
30
42
  def record_info(version)
31
43
  if model and model.respond_to?(:versions_info) and @file.present?
32
44
  info = {}
33
- info[:data_size] = @file.size
45
+ info[:data_size] = @file.try(:size).to_i
34
46
 
35
47
  img = MiniMagick::Image.open(@file.file)
36
48
  info[:width] = img[:width]
@@ -1,4 +1,4 @@
1
- class AssetUploader < EffectiveAssetsUploader
1
+ class TestAssetUploader < EffectiveAssetsUploader
2
2
  # resize_to_fit
3
3
  # Resize the image to fit within the specified dimensions while retaining the
4
4
  # original aspect ratio. The image may be shorter or narrower than specified in the smaller dimension
@@ -2,7 +2,7 @@
2
2
  = f.inputs "Asset" do
3
3
  %li
4
4
  %label.label Asset
5
- %p.inline-hints= effective_asset_image_tag(asset, :thumb)
5
+ %p.inline-hints= effective_asset_image_tag(asset, nil, {:height => 100, :width => 100})
6
6
  %li
7
7
  %label.label Uploaded by
8
8
  %p
@@ -16,11 +16,11 @@
16
16
  %label.label Files
17
17
  %p.inline-hints{:style => 'font-style: normal'}
18
18
  - if asset.image?
19
- = link_to "Original", assets_image_url(asset), :class => 'asset-insertable', :data => {'asset-id' => asset.id, 'asset' => effective_asset_image_tag(asset)}
19
+ = link_to "Original", _effective_asset_image_url(asset), :class => 'asset-insertable', :data => {'asset-id' => asset.id, 'asset' => effective_asset_image_tag(asset)}
20
20
  = "#{asset.width || '?'}x#{asset.height || '?'}px #{number_to_human_size(asset.data_size, :precision => 3)}"
21
21
  - asset.versions_info.each do |version, attributes|
22
22
  %br
23
- = link_to "#{version.to_s.gsub('_',' ').titleize}", assets_image_url(asset, version), :class => 'asset-insertable', :data => {'asset-id' => asset.id, 'asset' => assets_image_tag(asset, version) }
23
+ = link_to "#{version.to_s.gsub('_',' ').titleize}", _effective_asset_image_url(asset, version), :class => 'asset-insertable', :data => {'asset-id' => asset.id, 'asset' => effective_asset_image_tag(asset, version) }
24
24
  = "#{attributes[:width]}x#{attributes[:height]}px #{number_to_human_size(attributes[:data_size], :precision => 3)}"
25
25
  - elsif asset.icon?
26
26
  = link_to asset.file_name, asset.image, :class => 'asset-insertable', :data => {'asset-id' => asset.id, 'asset' => effective_asset_image_tag(asset)}
@@ -1,3 +1,4 @@
1
1
  = semantic_form_for asset, :url => '/' do |f|
2
- = f.input :uploads, :as => :asset_box, :uploader => true, :uploader_visible => true
2
+ = f.input :uploads, :as => :asset_box, :uploader => true
3
+ %hr
3
4
  = link_to 'Back', :back
@@ -0,0 +1,17 @@
1
+ - uid = (attachment.persisted? ? attachment.id : Time.now.to_f.to_s.split('.')[1] + Random.rand(10000).to_s)
2
+ - hidden ||= false
3
+
4
+ %li.attachment
5
+ .attachment-title.caption
6
+ = link_to attachment.asset.title, attachment.asset.url, :target => '_blank'
7
+
8
+ - if attachment_actions.include?('remove')
9
+ %a.attachment-remove{:href => '#'}
10
+ %img{:src => asset_path('effective_assets/icon_close.png'), :alt => 'Remove'}
11
+
12
+ - if attachment.persisted?
13
+ = hidden_field_tag(attachable_object_name + "[attachments_attributes][#{uid}][id]", attachment.id)
14
+ = hidden_field_tag(attachable_object_name + "[attachments_attributes][#{uid}][asset_id]", attachment.asset_id)
15
+ = hidden_field_tag(attachable_object_name + "[attachments_attributes][#{uid}][box]", attachment.box)
16
+ = hidden_field_tag(attachable_object_name + "[attachments_attributes][#{uid}][_destroy]", attachment.marked_for_destruction? ? 1 : nil, :class => 'asset-box-remove')
17
+ = hidden_field_tag(attachable_object_name + "[attachments_attributes][#{uid}][position]", 1)
@@ -0,0 +1,32 @@
1
+ - uid = (attachment.persisted? ? attachment.id : Time.now.to_f.to_s.split('.')[1] + Random.rand(10000).to_s)
2
+ - hidden ||= false
3
+
4
+ %tr.attachment{:style => "#{(attachment.marked_for_destruction? || hidden) ? 'display: none;' : ''}"}
5
+ %td.attachment-image
6
+ = effective_asset_image_tag(attachment.asset)
7
+ %td.attachment-title{:title => effective_asset_title(attachment.asset)}
8
+ = link_to attachment.asset.title, attachment.asset.url, :target => '_blank'
9
+ %td.attachment-size
10
+ = number_to_human_size(attachment.asset.data_size)
11
+ %td
12
+ - if attachment_actions.include?('insert') || attachment_actions.include?('attach')
13
+ - asset = attachment.asset
14
+ - if asset.image? || asset.icon?
15
+ %a.btn.btn-primary.attachment-insert{:href => '#', 'data-asset-id' => asset.id, 'data-asset' => effective_asset_image_tag(asset)} Attach
16
+ - elsif asset.video?
17
+ %a.btn.btn-primary.attachment-insert{:href => '#', 'data-asset-id' => asset.id, 'data-asset' => effective_asset_video_tag(asset)} Attach
18
+ - else
19
+ %a.btn.btn-primary.attachment-insert{:href => '#', 'data-asset-id' => asset.id, 'data-asset' => effective_asset_link_to(asset)} Attach
20
+
21
+ - if attachment_actions.include?('remove')
22
+ %a.attachment-remove{:href => '#', :title => 'Remove'}
23
+ %img{:src => asset_path('effective_assets/icon_close.png'), :alt => 'Remove'}
24
+
25
+ - if attachment_actions.include?('delete')
26
+ = link_to 'Delete', effective_assets.effective_asset_path(attachment.asset), :class => 'btn btn-danger attachment-delete', :data => {:method => :delete, :confirm => "Are you sure? This cannot be undone!"}
27
+
28
+ - if attachment.persisted?
29
+ = hidden_field_tag(attachable_object_name + "[attachments_attributes][#{uid}][id]", attachment.id)
30
+ = hidden_field_tag(attachable_object_name + "[attachments_attributes][#{uid}][asset_id]", attachment.asset_id)
31
+ = hidden_field_tag(attachable_object_name + "[attachments_attributes][#{uid}][box]", attachment.box)
32
+ = hidden_field_tag(attachable_object_name + "[attachments_attributes][#{uid}][_destroy]", attachment.marked_for_destruction? ? 1 : nil, :class => 'asset-box-remove')