s3_relay 0.2.0 → 0.3.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.
- checksums.yaml +4 -4
- data/app/assets/javascripts/s3_relay.coffee +15 -21
- data/lib/s3_relay/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7cb796ed4a1f0134a5e67322bb2e198362daa846
|
4
|
+
data.tar.gz: cb022aa8cf619ba5e239bef972c69abd4a6017f6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
|
-
|
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.
|
76
|
-
percentage = ((ev.
|
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
|
-
|
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()
|
data/lib/s3_relay/version.rb
CHANGED