Permalink
Browse files

experimenting with progress bars

  • Loading branch information...
1 parent 86613d6 commit 6c9327958b83032a0d9aefea87d8236087fd7eb8 @korny committed Apr 1, 2013
@@ -17,13 +17,17 @@ $ ->
if --draglevel <= 0
$('body').removeClass 'dragging'
-progress = (event) ->
- if event.lengthComputable
- complete = event.loaded / event.total * 100 | 0
- $('#progress').val complete
-
upload = (files, index = 0) ->
- if file = files.item(index)
+ if file = files.item index
+ image = new Image
+ image.width = 100 # a fake resize
+ $('.images').append $(image).wrap('<div class="image" />').parent()
+ $progress = $ '<progress min=0 max=100 value=0>'
+ progress = (event) ->
+ if event.lengthComputable
+ $progress.val event.loaded / event.total * 100 | 0
+ $(image).after $progress
+
formData = new FormData
formData.append 'file', file
@@ -39,6 +43,10 @@ upload = (files, index = 0) ->
)
.done (data, textStatus) ->
upload files, index + 1
+ image.src = data.url
+ $(image).next('progress').remove()
+ $(image).on 'loaded', ->
+ $(@).removeAttr 'width'
.fail ->
console.log 'Something went terribly wrong...'
@@ -50,9 +58,6 @@ upload = (files, index = 0) ->
if acceptedTypes[file.type]
reader = new FileReader
reader.onload = (event) ->
- image = new Image
image.src = event.target.result
- image.width = 100 # a fake resize
- document.body.appendChild image
reader.readAsDataURL file
@@ -4,3 +4,12 @@
body.dragging
background-color: yellow
+
+.image
+ display: inline
+ position: relative
+ progress
+ position: absolute
+ bottom: 0
+ left: 0
+ z-index: 1
@@ -22,17 +22,18 @@ def edit
# POST /images
def create
if params[:file]
- Rails.logger.debug { params[:file] }
- sleep 1
- return head :ok
- end
-
- @image = Image.new(image_params)
-
- if @image.save
- redirect_to @image, notice: 'Image was successfully created.'
+ image = Image.create! :picture => params[:file]
+ render :json => {
+ :url => image.picture.url(:thumb)
+ }
else
- render action: 'new'
+ @image = Image.new(image_params)
+
+ if @image.save
+ redirect_to @image, notice: 'Image was successfully created.'
+ else
+ render action: 'new'
+ end
end
end
@@ -1 +1,4 @@
-%progress#progress{ min: 0, max: 100, value: 0 } 0
+.images
+ - for image in Image.where 'picture_file_name IS NOT NULL'
+ .image
+ = image_tag image.picture(:thumb)

0 comments on commit 6c93279

Please sign in to comment.