uploadbox 0.2.0.rc2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3ce741794130c261aef059af05192beb434d9188
4
- data.tar.gz: e29fccdb4aac51e707205345245b72a36665db57
3
+ metadata.gz: e7bb12a0625b5f87aacfc0021316fe4b67bd1c60
4
+ data.tar.gz: 135c2fd550e08c6d1df330492cd578fe4290d561
5
5
  SHA512:
6
- metadata.gz: 10de8ed633a20adc447a8a24d004a84480bb05390400a21bcbd61d1b8f62d294974d08a5995066407238ef756f2d1646150a56924bf210457c846f17539ae71e
7
- data.tar.gz: 913db75094815ae9b645aaac352370c88ccd88fa9a50ed2dc0950f0bade6dd7bed0c49ef11f8cde1b5bfeea4f9456a9a68f8bd715f4fab9ed06e3fe15c7c7fea
6
+ metadata.gz: 63eff65e15bd81b2b1e16350618cbe75c37fb195933049b5554796f33c308a6668855543c87bad1089808a284eb4b3ca691ba573a994e601d2ce71f10c095d9d
7
+ data.tar.gz: 09ec34fd695b3fd5ee732e200f562405489cc5923b09aac9c291d286f7e90106db8a8812d9b4f26d5e1a0d8381b88f958382bedde3e0e97ae3d50ce8cfe60fec
@@ -0,0 +1,135 @@
1
+ class @FileUploader
2
+ constructor: (@container) ->
3
+ @preview = @container.find('[data-provides="fileupload"]')
4
+ @fileInput = @container.find('input[type="file"]')
5
+ @typeInput = @container.find('input[name="image[imageable_type]"]')
6
+ @uploadNameInput = @container.find('input[name="image[upload_name]"]')
7
+ @idInput = @container.find('[data-item="id"]')
8
+ @container.find('a.btn.fileupload-exists').bind('ajax:success', @delete)
9
+ @thumbContainer = @container.find('.fileupload-preview.preview')
10
+
11
+ @setupLabel()
12
+
13
+ @fileInput.show()
14
+
15
+ @fileInput.fileupload
16
+ type: 'POST'
17
+ dataType: 'xml'
18
+ formData: @getFormData
19
+ dropZone: @container
20
+ pasteZone: @container
21
+ add: @add
22
+ progress: @progress
23
+ done: @done
24
+
25
+ add: (e, data) =>
26
+ @file = data.files[0]
27
+ if @loader
28
+ @loader.detach()
29
+
30
+ if @verifyProcessingInterval
31
+ clearInterval(@verifyProcessingInterval)
32
+
33
+ @makePreview(@file)
34
+
35
+ @loader = $('<div><div class="progress progress-striped active"><div class="bar" style="width: 0%;"></div></div><div class="uploader-overlay"></div></div>').hide()
36
+ @loader.find('.uploader-overlay').height(@thumbContainer.data('height'))
37
+ @preview.prepend(@loader)
38
+ @loader.show()
39
+
40
+ data.submit()
41
+ @container.find('.fileupload').removeClass('processing').addClass('uploading')
42
+ @container.closest('form').find('[type=submit]').attr("disabled", true)
43
+
44
+ makePreview: (file) =>
45
+ @thumbContainer.html('')
46
+ @container.find('.fileupload-preview.preview').append($("<a data-item='filename'>#{file.name}</a>"))
47
+ @container.find('.fileupload').removeClass('fileupload-new').addClass('fileupload-uploading')
48
+
49
+ getFormData: (arg) =>
50
+ file = @file
51
+ @filePath = @container.find('input[name="key"]').val() + file.name
52
+ [
53
+ { name: 'key', value: @filePath },
54
+ { name: 'acl', value: @container.find('input[name="acl"]').val() },
55
+ { name: 'Content-Type', value: file.type },
56
+ { name: 'AWSAccessKeyId', value: @container.find('input[name="AWSAccessKeyId"]').val() },
57
+ { name: 'policy', value: @container.find('input[name="policy"]').val() },
58
+ { name: 'signature', value: @container.find('input[name="signature"]').val() },
59
+ { name: "file", value: file }
60
+ ]
61
+
62
+ progress: (e, data) =>
63
+ progress = parseInt(data.loaded / data.total * 100, 10)
64
+ @loader.find('.bar').css({width: progress + '%'})
65
+
66
+ done: (e, data) =>
67
+ @container.find('.fileupload').removeClass('uploading').addClass('processing')
68
+ @originalFileURL = @fileInput.data('url') + @filePath
69
+ $.ajax
70
+ type: 'POST'
71
+ url: @fileInput.data('callback-url')
72
+ data:
73
+ 'image[remote_file_url]': @originalFileURL
74
+ 'image[imageable_type]': @typeInput.val()
75
+ 'image[upload_name]': @uploadNameInput.val()
76
+ 'image[secure_random]': @fileInput.data('secure-random')
77
+ 'processed': true
78
+
79
+ complete: (data) =>
80
+ @verifyProcessingInterval = setInterval(@verifyProcessing, 100)
81
+
82
+ error: =>
83
+ @loader.detach()
84
+ @container.find('.fileupload').removeClass('uploading').removeClass('processing')
85
+ @container.closest('form').find('[type=submit]').attr("disabled", false)
86
+
87
+ verifyProcessing: =>
88
+ arr = @filePath.split('/')
89
+ filename = arr[arr.length - 1]
90
+ $.ajax
91
+ type: 'GET'
92
+ dataType: 'json'
93
+ url: @fileInput.data('find-url')
94
+ data:
95
+ image:
96
+ 'imageable_type': @typeInput.val()
97
+ 'upload_name': @uploadNameInput.val()
98
+ 'secure_random': @fileInput.data('secure-random')
99
+
100
+ complete: (data) =>
101
+ if data.responseJSON.hasOwnProperty('id')
102
+ clearInterval(@verifyProcessingInterval)
103
+ @showThumb(data.responseJSON)
104
+
105
+ error: =>
106
+ @loader.detach()
107
+ @container.find('.fileupload').removeClass('uploading').removeClass('processing')
108
+ @container.closest('form').find('[type=submit]').attr("disabled", false)
109
+
110
+ delete: =>
111
+ @idInput.val('')
112
+ @container.find('.fileupload-preview.preview a').detach()
113
+ @container.find('.fileupload').addClass('fileupload-new').removeClass('fileupload-exists')
114
+
115
+ fail: (e, data) =>
116
+ @loader.detach()
117
+ @container.find('.fileupload').removeClass('uploading').removeClass('processing')
118
+ @container.closest('form').find('[type=submit]').attr("disabled", false)
119
+
120
+ showThumb: (image) =>
121
+ @container.trigger('uploadbox:complete', {url: @originalFileURL})
122
+ @loader.fadeOut =>
123
+ @loader.detach()
124
+ @idInput.val(image.id)
125
+ @container.find('a.btn.fileupload-exists').attr('href', image.url)
126
+ @container.find('[data-item="filename"]').attr('href', @originalFileURL).attr('target', '_blank')
127
+ @container.find('.fileupload').removeClass('fileupload-new').addClass('fileupload-exists')
128
+ @container.find('.fileupload').removeClass('uploading').removeClass('processing')
129
+ @container.closest('form').find('[type=submit]').attr("disabled", false)
130
+
131
+ setupLabel: =>
132
+ labels = @container.find('.fileupload-actions .fileupload-new, .fileupload-actions .fileupload-exists')
133
+ labels.each (index, label) ->
134
+ $(label).css({marginLeft: $(label).outerWidth() * -0.5, marginTop: $(label).outerHeight() * -0.5})
135
+
@@ -77,6 +77,7 @@ class @ImageUploader
77
77
 
78
78
  done: (e, data) =>
79
79
  @container.find('.fileupload').removeClass('uploading').addClass('processing')
80
+ @originalFileURL = @fileInput.data('url') + @filePath
80
81
 
81
82
  $.ajax
82
83
  type: 'POST'
@@ -130,6 +131,7 @@ class @ImageUploader
130
131
  @container.closest('form').find('[type=submit]').attr("disabled", false)
131
132
 
132
133
  showThumb: (image) =>
134
+ @container.trigger('uploadbox:complete', {url: @originalFileURL})
133
135
  @loader.fadeOut =>
134
136
  @loader.detach()
135
137
  @idInput.val(image.id)
@@ -7,6 +7,7 @@
7
7
  #= require cors/jquery.xdr-transport
8
8
  #= require jquery.fileupload
9
9
  #= require _image_uploader
10
+ #= require _file_uploader
10
11
  #= require _uploader_preview
11
12
  #= require _gallery_uploader
12
13
  #= require _show_image
@@ -201,4 +201,46 @@
201
201
 
202
202
  .fileupload-uploading
203
203
  .btn.fileupload-exists
204
- display: none
204
+ display: none
205
+
206
+ [data-component="FileUploader"]
207
+ height: 60px
208
+ width: 300px
209
+
210
+ .fileupload-preview.preview
211
+ a
212
+ display: block
213
+ text-align: left
214
+ a:hover
215
+ background: transparent
216
+ color: black
217
+
218
+ .fileupload-exists
219
+ .btn.fileupload-exists
220
+ display: block
221
+ // .fileupload-new
222
+ // display: none !important
223
+
224
+ .fileupload
225
+ background: transparent
226
+
227
+ .fileupload-actions
228
+ background: transparent
229
+ height: 50px
230
+ width: 230px
231
+
232
+ .btn-file
233
+ background: transparent
234
+
235
+ .fileupload-new
236
+ width: 200px
237
+ display: block
238
+ height: 30px
239
+ line-height: 30px
240
+ position: static
241
+ margin-top: 0 !important
242
+ margin-left: 0 !important
243
+
244
+
245
+ .fileupload-actions
246
+ position: static
@@ -12,10 +12,12 @@ module Uploadbox
12
12
 
13
13
  upload = Uploadbox.const_get(upload_class_name).create!(attributes)
14
14
 
15
- if Uploadbox.background_processing
16
- Resque.enqueue(ProcessImage, {id: upload.id, upload_class_name: upload_class_name})
17
- else
18
- upload.process
15
+ unless params["processed"].present?
16
+ if Uploadbox.background_processing
17
+ Resque.enqueue(ProcessImage, {id: upload.id, upload_class_name: upload_class_name})
18
+ else
19
+ upload.process
20
+ end
19
21
  end
20
22
 
21
23
  render nothing: true
@@ -34,7 +36,7 @@ module Uploadbox
34
36
 
35
37
  private
36
38
  def image_params
37
- params.require(:image).permit(:remote_file_url, :imageable_type, :upload_name, :secure_random)
39
+ params.require(:image).permit(:remote_file_url, :imageable_type, :upload_name, :secure_random, :processed)
38
40
  end
39
41
 
40
42
  def upload_class_name
@@ -5,6 +5,10 @@ class Image < ActiveRecord::Base
5
5
  update(remote_file_url: original_file)
6
6
  end
7
7
 
8
+ def name
9
+ File.basename(original_file)
10
+ end
11
+
8
12
  def processing?
9
13
  file.blank?
10
14
  end
@@ -0,0 +1,44 @@
1
+ = form.fields_for upload_name do |f|
2
+ / forces multipart/form-data
3
+ = f.file_field :temp, style: 'display: none'
4
+
5
+ / old browsers
6
+ - if browser.ie? and browser.version.to_i <= 9
7
+ - if namespace
8
+ input name="[#{resource.class.name.underscore}][#{namespace}]#{upload_name}" data-item="id" type="file"
9
+ - else
10
+ input name="[#{resource.class.name.underscore}]#{upload_name}" data-item="id" type="file"
11
+ - else
12
+ - secure_random = SecureRandom.uuid
13
+ .uploadbox-image-uploader.uploads-one data-component="FileUploader"
14
+ - if namespace
15
+ input name="[#{resource.class.name.underscore}][#{namespace}]#{upload_name}" data-item="id" type="hidden" value="#{resource.send(upload_name).try :id}"
16
+ - else
17
+ input name="[#{resource.class.name.underscore}]#{upload_name}" data-item="id" type="hidden" value="#{resource.send(upload_name).try :id}"
18
+
19
+ .fileupload data-provides="fileupload" class="fileupload-#{resource.send("#{upload_name}?") ? 'exists' : 'new'}"
20
+ .fileupload-preview.preview
21
+ - if resource.send("#{upload_name}?")
22
+ = link_to resource.send(upload_name).name, resource.send(upload_name).original_file
23
+
24
+ .fileupload-actions
25
+ span.btn.btn-file
26
+ span.fileupload-new = choose_label
27
+ span.fileupload-exists = update_label
28
+
29
+
30
+ input type="file" name="image[file]" data-callback-url="#{uploadbox.images_path}" data-find-url="#{uploadbox.find_images_path(format: :json)}" data-url="https://#{CarrierWave::Uploader::Base.fog_directory}.s3.amazonaws.com/" data-secure-random="#{secure_random}"
31
+ input type="hidden" name="policy" value="#{s3_policy}"
32
+ input type="hidden" name="signature" value="#{s3_signature}"
33
+ input type="hidden" name="AWSAccessKeyId" value="#{CarrierWave::Uploader::Base.fog_credentials[:aws_access_key_id]}"
34
+ input type="hidden" name="acl" value="public-read"
35
+ input type="hidden" name="key" value="uploads/#{secure_random}/"
36
+
37
+ input type="hidden" name="image[imageable_type]" value="#{resource.class.base_class}"
38
+ input type="hidden" name="image[upload_name]" value="#{upload_name}"
39
+ - if removable
40
+ - if resource.send(upload_name).present?
41
+ = link_to destroy_label, uploadbox.image_path(resource.send(upload_name)), class: 'btn fileupload-exists', remote: true, method: :delete
42
+ - else
43
+ = link_to destroy_label, '#', class: 'btn fileupload-exists', remote: true, method: :delete
44
+
@@ -39,27 +39,47 @@ end
39
39
  class ActionView::Helpers::FormBuilder
40
40
  def uploads_one(upload_name, options={})
41
41
  upload_model_class = "Uploadbox::#{@object.class.base_class.to_s + upload_name.to_s.camelize}".constantize
42
- options.reverse_merge!(preview: upload_model_class.versions.keys.first,
43
- namespace: false,
44
- default: false,
45
- update_label: 'Alterar',
46
- choose_label: 'Escolher',
47
- destroy_label: '&times;'.html_safe)
48
- dimensions = upload_model_class.versions[options[:preview]]
49
- @template.render partial: 'uploadbox/images/uploads_one', locals: {
50
- upload_name: upload_name,
51
- resource: @object,
52
- form: self,
53
- version: options[:preview],
54
- width: dimensions[0],
55
- height: dimensions[1],
56
- namespace: options[:namespace],
57
- default: options[:default],
58
- removable: upload_model_class.removable?,
59
- update_label: options[:update_label],
60
- choose_label: options[:choose_label],
61
- destroy_label: options[:destroy_label]
62
- }
42
+
43
+ if upload_model_class.versions.present?
44
+ options.reverse_merge!(preview: upload_model_class.versions.keys.first,
45
+ namespace: false,
46
+ default: false,
47
+ update_label: 'Alterar',
48
+ choose_label: 'Escolher',
49
+ destroy_label: '&times;'.html_safe)
50
+ dimensions = upload_model_class.versions[options[:preview]]
51
+ @template.render partial: 'uploadbox/images/uploads_one', locals: {
52
+ upload_name: upload_name,
53
+ resource: @object,
54
+ form: self,
55
+ version: options[:preview],
56
+ width: dimensions[0],
57
+ height: dimensions[1],
58
+ namespace: options[:namespace],
59
+ default: options[:default],
60
+ removable: upload_model_class.removable?,
61
+ update_label: options[:update_label],
62
+ choose_label: options[:choose_label],
63
+ destroy_label: options[:destroy_label]
64
+ }
65
+ else
66
+ options.reverse_merge!(namespace: false,
67
+ default: false,
68
+ update_label: 'Alterar',
69
+ choose_label: 'Escolher',
70
+ destroy_label: '&times;'.html_safe)
71
+ dimensions = upload_model_class.versions[options[:preview]]
72
+ @template.render partial: 'uploadbox/files/uploads_one', locals: {
73
+ upload_name: upload_name,
74
+ resource: @object,
75
+ form: self,
76
+ namespace: options[:namespace],
77
+ removable: upload_model_class.removable?,
78
+ update_label: options[:update_label],
79
+ choose_label: options[:choose_label],
80
+ destroy_label: options[:destroy_label]
81
+ }
82
+ end
63
83
  end
64
84
 
65
85
  def uploads_many(upload_name, options={})
@@ -127,6 +127,7 @@ module Uploadbox
127
127
  def original_file
128
128
  model.original_file
129
129
  end
130
+
130
131
  end
131
132
  end
132
133
  mount_uploader :file, dynamic_uploader
@@ -1,3 +1,3 @@
1
1
  module Uploadbox
2
- VERSION = "0.2.0.rc2"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uploadbox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0.rc2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julio Protzek
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-05-04 00:00:00.000000000 Z
12
+ date: 2014-07-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -547,6 +547,7 @@ executables: []
547
547
  extensions: []
548
548
  extra_rdoc_files: []
549
549
  files:
550
+ - app/assets/javascripts/_file_uploader.coffee
550
551
  - app/assets/javascripts/_gallery_uploader.coffee
551
552
  - app/assets/javascripts/_image_uploader.coffee
552
553
  - app/assets/javascripts/_manager.coffee
@@ -571,6 +572,7 @@ files:
571
572
  - app/models/image.rb
572
573
  - app/uploaders/uploadbox/image_processing_uploader.rb
573
574
  - app/views/layouts/uploadbox/application.html.erb
575
+ - app/views/uploadbox/files/_uploads_one.slim
574
576
  - app/views/uploadbox/images/_uploads_many.slim
575
577
  - app/views/uploadbox/images/_uploads_one.slim
576
578
  - app/views/uploadbox/images/find.json.jbuilder
@@ -606,9 +608,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
606
608
  version: 1.9.3
607
609
  required_rubygems_version: !ruby/object:Gem::Requirement
608
610
  requirements:
609
- - - '>'
611
+ - - '>='
610
612
  - !ruby/object:Gem::Version
611
- version: 1.3.1
613
+ version: '0'
612
614
  requirements: []
613
615
  rubyforge_project:
614
616
  rubygems_version: 2.1.11