refile 0.6.0 → 0.6.1

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: 89c063ad7af052e375f5850f3dd6ab903f242015
4
- data.tar.gz: a3d2eaedc248aea3daec5e59002cab689b593d89
3
+ metadata.gz: 377e173cc9191c388b7deb8ea4c2f3790b8ff7c4
4
+ data.tar.gz: b3103499b3e95d56ff503e875f0f1035e11f669a
5
5
  SHA512:
6
- metadata.gz: 07df0ac320e30fdf85aad47e82fd2306b0a2d33d03039647b5e3343d0fdc127e8234fad15b6e3a6a586d9cbe5bfed4bea47aaf31f659895bf5ab7eb8a98e9217
7
- data.tar.gz: 97a0771976c4f6ef7a5e3cb7446d2e6e7797adb635fe3a47237e7246213a2b1c693365a832dfb31c3efd3257f08263df08be1d05c319b2a09b79e8e91289f949
6
+ metadata.gz: 05e023ee3fa8abb4e01f51a09b4af7ba1822f5f091dcb0ac39f619d8105ea8c634c0e8b26eb0a0492d6f1fb759804d4b4f736e0f55c3b799d588d0be40bbb2af
7
+ data.tar.gz: f63d8105aeebbd70a8aac774d298bb8b3d449d5788fcfc294ad93d8579489d9547172e64a1657c2c5cb07564fa9cdff692588be3439b3854a242806266ca53a8
@@ -0,0 +1,112 @@
1
+ (function() {
2
+ "use strict";
3
+
4
+ function isSuccess(xhr) {
5
+ return (xhr.status >= 200 && xhr.status < 300) || xhr.status === 304
6
+ }
7
+
8
+ function formData(as, file, fields) {
9
+ var data = new FormData();
10
+
11
+ if(fields) {
12
+ Object.keys(fields).forEach(function(key) {
13
+ data.append(key, fields[key]);
14
+ });
15
+ }
16
+
17
+ data.append(as, file);
18
+
19
+ return data;
20
+ }
21
+
22
+ if(!document.addEventListener) { return; } // IE8
23
+
24
+ document.addEventListener("change", function(changeEvent) {
25
+ var input = changeEvent.target;
26
+ if(input.tagName === "INPUT" && input.type === "file" && input.getAttribute("data-direct")) {
27
+ if(!input.files) { return; } // IE9, bail out if file API is not supported.
28
+
29
+ var reference = input.getAttribute("data-reference");
30
+ var metadataField = document.querySelector("input[type=hidden][data-reference='" + reference + "']");
31
+
32
+ var url = input.getAttribute("data-url");
33
+ var fields = JSON.parse(input.getAttribute("data-fields") || "null");
34
+
35
+ var requests = [].map.call(input.files, function(file, index) {
36
+ function dispatchEvent(element, name, progress) {
37
+ var ev = document.createEvent('CustomEvent');
38
+ ev.initCustomEvent(name, true, false, { xhr: xhr, file: file, index: index, progress: progress });
39
+ element.dispatchEvent(ev);
40
+ }
41
+
42
+ var xhr = new XMLHttpRequest();
43
+
44
+ xhr.file = file;
45
+
46
+ xhr.addEventListener("load", function() {
47
+ xhr.complete = true;
48
+ if(requests.every(function(xhr) { return xhr.complete })) {
49
+ finalizeUpload();
50
+ }
51
+ if(isSuccess(xhr)) {
52
+ dispatchEvent(input, "upload:success");
53
+ } else {
54
+ dispatchEvent(input, "upload:failure");
55
+ }
56
+ dispatchEvent(input, "upload:complete");
57
+ });
58
+
59
+ xhr.upload.addEventListener("progress", function(progressEvent) {
60
+ dispatchEvent(input, "upload:progress", progressEvent);
61
+ });
62
+
63
+ if(input.getAttribute("data-presigned")) {
64
+ dispatchEvent(input, "presign:start");
65
+ var presignXhr = new XMLHttpRequest();
66
+ var presignUrl = url + "?t=" + Date.now() + "." + index;
67
+ presignXhr.addEventListener("load", function() {
68
+ dispatchEvent(input, "presign:complete");
69
+ if(isSuccess(presignXhr)) {
70
+ dispatchEvent(input, "presign:success");
71
+ var data = JSON.parse(presignXhr.responseText)
72
+ xhr.id = data.id;
73
+ xhr.open("POST", data.url, true);
74
+ xhr.send(formData(data.as, file, data.fields));
75
+ dispatchEvent(input, "upload:start");
76
+ } else {
77
+ dispatchEvent(input, "presign:failure");
78
+ xhr.complete = true;
79
+ };
80
+ });
81
+ presignXhr.open("GET", presignUrl, true);
82
+ presignXhr.send();
83
+ } else {
84
+ xhr.open("POST", url, true);
85
+ xhr.send(formData(input.getAttribute("data-as"), file, fields));
86
+ dispatchEvent(input, "upload:start");
87
+ }
88
+
89
+ return xhr;
90
+ });
91
+
92
+ if(requests.length) {
93
+ input.classList.add("uploading");
94
+ }
95
+
96
+ var finalizeUpload = function() {
97
+ input.classList.remove("uploading");
98
+
99
+ if(requests.every(isSuccess)) {
100
+ var data = requests.map(function(xhr) {
101
+ var id = xhr.id || JSON.parse(xhr.responseText).id;
102
+ return { id: id, filename: xhr.file.name, content_type: xhr.file.type, size: xhr.file.size };
103
+ });
104
+ if(!input.multiple) data = data[0];
105
+ if(metadataField) metadataField.value = JSON.stringify(data);
106
+
107
+ input.removeAttribute("name");
108
+ }
109
+ }
110
+ }
111
+ });
112
+ })();
@@ -0,0 +1,8 @@
1
+ en:
2
+ activerecord:
3
+ errors:
4
+ messages:
5
+ too_large: "is too large"
6
+ download_failed: "could not be downloaded"
7
+ invalid_content_type: "has an invalid file format"
8
+ invalid_extension: "has an invalid file format"
@@ -0,0 +1,5 @@
1
+ if Refile.automount
2
+ Rails.application.routes.draw do
3
+ mount Refile.app, at: Refile.mount_point, as: :refile_app
4
+ end
5
+ end
@@ -1,3 +1,3 @@
1
1
  module Refile
2
- VERSION = "0.6.0"
2
+ VERSION = "0.6.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: refile
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonas Nicklas
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-10 00:00:00.000000000 Z
11
+ date: 2015-09-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -59,6 +59,9 @@ executables: []
59
59
  extensions: []
60
60
  extra_rdoc_files: []
61
61
  files:
62
+ - app/assets/javascripts/refile.js
63
+ - config/locales/en.yml
64
+ - config/routes.rb
62
65
  - lib/refile.rb
63
66
  - lib/refile/app.rb
64
67
  - lib/refile/attacher.rb
@@ -120,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
120
123
  version: '0'
121
124
  requirements: []
122
125
  rubyforge_project:
123
- rubygems_version: 2.4.8
126
+ rubygems_version: 2.4.5.1
124
127
  signing_key:
125
128
  specification_version: 4
126
129
  summary: Simple and powerful file upload library