s3_relay 0.2.0 → 0.3.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: 7eb3749db208e34c25730efc1bac3cdaa60cbbca
4
- data.tar.gz: 5ab8beaaa957f5abcf41f687d82e2f7c06deea37
3
+ metadata.gz: 7cb796ed4a1f0134a5e67322bb2e198362daa846
4
+ data.tar.gz: cb022aa8cf619ba5e239bef972c69abd4a6017f6
5
5
  SHA512:
6
- metadata.gz: 4d6166f156b612b5619c355a19b42ede0dc6572505cd301985916c809ac6822729dd30c92a58a25bb92fc14a10d3f2cc01047ad305372abc1b31e3d101a03b22
7
- data.tar.gz: 28f2e274966d3a849afaa2ecbaaca004c28f7de45d7fd35b9c95da668c1a0a54cec1e83d6e9253f5c56217357fca44f28e82ebcf4dc575a2dcea2aeda22ba23e
6
+ metadata.gz: 5526db7bf2a0782f2b8efc298bac34458583c111080bf2698d6a8247bb1b345515819699e8e8e7b27ced4f0fc755fa839f4d57e2e6ee1efb2f1d8fef9c101540
7
+ data.tar.gz: 585e6e39dd6564e0713575680155aea61a26ea9ab6e00aadc5d70abeba0521210e2d021da53537dbcfb37dca9bb82f290fb25f31977215c1080b8e5ced8f9e6d
@@ -4,18 +4,15 @@ displayFailedUpload = (progressColumn=null) ->
4
4
  else
5
5
  alert("File could not be uploaded")
6
6
 
7
- publishEvent = (name, detail) ->
8
- ev = document.createEvent "CustomEvent"
9
- ev.initCustomEvent name, true, false, detail
10
- document.dispatchEvent ev
7
+ publishEvent = (target, name, detail) ->
8
+ $(target).trigger( name, detail )
11
9
 
12
- saveUrl = (container, uuid, filename, contentType, publicUrl) ->
10
+ saveUrl = (container, uuid, filename, contentType, publicUrl, progressColumn, fileColumn) ->
13
11
  privateUrl = null
14
12
 
15
13
  $.ajax
16
14
  type: "POST"
17
15
  url: "/s3_relay/uploads"
18
- async: false
19
16
  data:
20
17
  parent_type: container.data("parentType")
21
18
  parent_id: container.data("parentId")
@@ -26,7 +23,15 @@ saveUrl = (container, uuid, filename, contentType, publicUrl) ->
26
23
  public_url: publicUrl
27
24
  success: (data, status, xhr) ->
28
25
  privateUrl = data.private_url
29
- publishEvent "upload:success", { uuid: uuid }
26
+ if privateUrl == null
27
+ displayFailedUpload(progressColumn)
28
+ else
29
+ fileColumn.html("<a href='#{privateUrl}'>#{filename}</a>")
30
+
31
+ virtualAttr = "#{container.data('parentType')}[new_#{container.data('association')}_uuids]"
32
+ hiddenField = "<input type='hidden' name='#{virtualAttr}[]' value='#{uuid}' />"
33
+ container.append(hiddenField)
34
+ publishEvent(container, "upload:success", [ uuid, filename, privateUrl ])
30
35
  error: (xhr) ->
31
36
  console.log xhr.responseText
32
37
 
@@ -44,7 +49,6 @@ uploadFile = (container, file) ->
44
49
  $.ajax
45
50
  type: "GET"
46
51
  url: "/s3_relay/uploads/new"
47
- async: false
48
52
  success: (data, status, xhr) ->
49
53
  formData = new FormData()
50
54
  xhr = new XMLHttpRequest()
@@ -72,8 +76,8 @@ uploadFile = (container, file) ->
72
76
  progressMeter = $(".s3r-meter", progressColumn)
73
77
 
74
78
  xhr.upload.addEventListener "progress", (ev) ->
75
- if ev.position
76
- percentage = ((ev.position / ev.totalSize) * 100.0).toFixed(0)
79
+ if ev.loaded
80
+ percentage = ((ev.loaded / ev.total) * 100.0).toFixed(0)
77
81
  progressBar.show()
78
82
  progressMeter.css "width", "#{percentage}%"
79
83
  else
@@ -87,17 +91,7 @@ uploadFile = (container, file) ->
87
91
  if xhr.status == 201
88
92
  contentType = file.type
89
93
  publicUrl = $("Location", xhr.responseXML).text()
90
- privateUrl = saveUrl(container, uuid, fileName, contentType, publicUrl)
91
-
92
- if privateUrl == null
93
- displayFailedUpload(progressColumn)
94
- else
95
- fileColumn.html("<a href='#{privateUrl}'>#{fileName}</a>")
96
-
97
- virtualAttr = "#{container.data('parentType')}[new_#{container.data('association')}_uuids]"
98
- hiddenField = "<input type='hidden' name='#{virtualAttr}[]' value='#{uuid}' />"
99
- container.append(hiddenField)
100
-
94
+ saveUrl(container, uuid, fileName, contentType, publicUrl, progressColumn, fileColumn)
101
95
  else
102
96
  displayFailedUpload(progressColumn)
103
97
  console.log $("Message", xhr.responseXML).text()
@@ -1,3 +1,3 @@
1
1
  module S3Relay
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: s3_relay
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kenny Johnston