rails_admin_uploader 1.0.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.
Files changed (37) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +9 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE.txt +21 -0
  5. data/README.md +78 -0
  6. data/Rakefile +1 -0
  7. data/app/assets/images/rails_admin_uploader/loading.gif +0 -0
  8. data/app/assets/images/rails_admin_uploader/progressbar.gif +0 -0
  9. data/app/assets/javascripts/rails_admin_uploader.coffee +261 -0
  10. data/app/assets/javascripts/rails_admin_uploader/canvas-to-blob.js +95 -0
  11. data/app/assets/javascripts/rails_admin_uploader/jquery.fileupload-audio.js +112 -0
  12. data/app/assets/javascripts/rails_admin_uploader/jquery.fileupload-image.js +321 -0
  13. data/app/assets/javascripts/rails_admin_uploader/jquery.fileupload-process.js +175 -0
  14. data/app/assets/javascripts/rails_admin_uploader/jquery.fileupload-ui.js +710 -0
  15. data/app/assets/javascripts/rails_admin_uploader/jquery.fileupload-validate.js +122 -0
  16. data/app/assets/javascripts/rails_admin_uploader/jquery.fileupload-video.js +112 -0
  17. data/app/assets/javascripts/rails_admin_uploader/jquery.fileupload.js +1477 -0
  18. data/app/assets/javascripts/rails_admin_uploader/jquery.iframe-transport.js +217 -0
  19. data/app/assets/javascripts/rails_admin_uploader/load-image.all.min.js +1 -0
  20. data/app/assets/javascripts/rails_admin_uploader/tmpl.js +87 -0
  21. data/app/assets/stylesheets/rails_admin_uploader.sass +2 -0
  22. data/app/assets/stylesheets/rails_admin_uploader/jquery.fileupload-ui.scss +57 -0
  23. data/app/assets/stylesheets/rails_admin_uploader/jquery.fileupload.scss +37 -0
  24. data/app/controllers/rails_admin_uploader/attachments_controller.rb +94 -0
  25. data/app/views/rails_admin/main/_rails_admin_uploader.html.haml +16 -0
  26. data/bin/console +14 -0
  27. data/bin/setup +7 -0
  28. data/config/locales/ru.yml +6 -0
  29. data/config/routes.rb +8 -0
  30. data/lib/rails_admin_uploader.rb +15 -0
  31. data/lib/rails_admin_uploader/asset.rb +19 -0
  32. data/lib/rails_admin_uploader/base.rb +50 -0
  33. data/lib/rails_admin_uploader/engine.rb +6 -0
  34. data/lib/rails_admin_uploader/field.rb +12 -0
  35. data/lib/rails_admin_uploader/version.rb +3 -0
  36. data/rails_admin_uploader.gemspec +24 -0
  37. metadata +107 -0
@@ -0,0 +1,112 @@
1
+ /*
2
+ * jQuery File Upload Audio Preview Plugin
3
+ * https://github.com/blueimp/jQuery-File-Upload
4
+ *
5
+ * Copyright 2013, Sebastian Tschan
6
+ * https://blueimp.net
7
+ *
8
+ * Licensed under the MIT license:
9
+ * http://www.opensource.org/licenses/MIT
10
+ */
11
+
12
+ /* jshint nomen:false */
13
+ /* global define, require, window, document */
14
+
15
+ (function (factory) {
16
+ 'use strict';
17
+ if (typeof define === 'function' && define.amd) {
18
+ // Register as an anonymous AMD module:
19
+ define([
20
+ 'jquery',
21
+ 'load-image',
22
+ './jquery.fileupload-process'
23
+ ], factory);
24
+ } else if (typeof exports === 'object') {
25
+ // Node/CommonJS:
26
+ factory(
27
+ require('jquery'),
28
+ require('load-image')
29
+ );
30
+ } else {
31
+ // Browser globals:
32
+ factory(
33
+ window.jQuery,
34
+ window.loadImage
35
+ );
36
+ }
37
+ }(function ($, loadImage) {
38
+ 'use strict';
39
+
40
+ // Prepend to the default processQueue:
41
+ $.blueimp.fileupload.prototype.options.processQueue.unshift(
42
+ {
43
+ action: 'loadAudio',
44
+ // Use the action as prefix for the "@" options:
45
+ prefix: true,
46
+ fileTypes: '@',
47
+ maxFileSize: '@',
48
+ disabled: '@disableAudioPreview'
49
+ },
50
+ {
51
+ action: 'setAudio',
52
+ name: '@audioPreviewName',
53
+ disabled: '@disableAudioPreview'
54
+ }
55
+ );
56
+
57
+ // The File Upload Audio Preview plugin extends the fileupload widget
58
+ // with audio preview functionality:
59
+ $.widget('blueimp.fileupload', $.blueimp.fileupload, {
60
+
61
+ options: {
62
+ // The regular expression for the types of audio files to load,
63
+ // matched against the file type:
64
+ loadAudioFileTypes: /^audio\/.*$/
65
+ },
66
+
67
+ _audioElement: document.createElement('audio'),
68
+
69
+ processActions: {
70
+
71
+ // Loads the audio file given via data.files and data.index
72
+ // as audio element if the browser supports playing it.
73
+ // Accepts the options fileTypes (regular expression)
74
+ // and maxFileSize (integer) to limit the files to load:
75
+ loadAudio: function (data, options) {
76
+ if (options.disabled) {
77
+ return data;
78
+ }
79
+ var file = data.files[data.index],
80
+ url,
81
+ audio;
82
+ if (this._audioElement.canPlayType &&
83
+ this._audioElement.canPlayType(file.type) &&
84
+ ($.type(options.maxFileSize) !== 'number' ||
85
+ file.size <= options.maxFileSize) &&
86
+ (!options.fileTypes ||
87
+ options.fileTypes.test(file.type))) {
88
+ url = loadImage.createObjectURL(file);
89
+ if (url) {
90
+ audio = this._audioElement.cloneNode(false);
91
+ audio.src = url;
92
+ audio.controls = true;
93
+ data.audio = audio;
94
+ return data;
95
+ }
96
+ }
97
+ return data;
98
+ },
99
+
100
+ // Sets the audio element as a property of the file object:
101
+ setAudio: function (data, options) {
102
+ if (data.audio && !options.disabled) {
103
+ data.files[data.index][options.name || 'preview'] = data.audio;
104
+ }
105
+ return data;
106
+ }
107
+
108
+ }
109
+
110
+ });
111
+
112
+ }));
@@ -0,0 +1,321 @@
1
+ /*
2
+ * jQuery File Upload Image Preview & Resize Plugin
3
+ * https://github.com/blueimp/jQuery-File-Upload
4
+ *
5
+ * Copyright 2013, Sebastian Tschan
6
+ * https://blueimp.net
7
+ *
8
+ * Licensed under the MIT license:
9
+ * http://www.opensource.org/licenses/MIT
10
+ */
11
+
12
+ /* jshint nomen:false */
13
+ /* global define, require, window, Blob */
14
+
15
+ (function (factory) {
16
+ 'use strict';
17
+ if (typeof define === 'function' && define.amd) {
18
+ // Register as an anonymous AMD module:
19
+ define([
20
+ 'jquery',
21
+ 'load-image',
22
+ 'load-image-meta',
23
+ 'load-image-exif',
24
+ 'load-image-ios',
25
+ 'canvas-to-blob',
26
+ './jquery.fileupload-process'
27
+ ], factory);
28
+ } else if (typeof exports === 'object') {
29
+ // Node/CommonJS:
30
+ factory(
31
+ require('jquery'),
32
+ require('load-image')
33
+ );
34
+ } else {
35
+ // Browser globals:
36
+ factory(
37
+ window.jQuery,
38
+ window.loadImage
39
+ );
40
+ }
41
+ }(function ($, loadImage) {
42
+ 'use strict';
43
+
44
+ // Prepend to the default processQueue:
45
+ $.blueimp.fileupload.prototype.options.processQueue.unshift(
46
+ {
47
+ action: 'loadImageMetaData',
48
+ disableImageHead: '@',
49
+ disableExif: '@',
50
+ disableExifThumbnail: '@',
51
+ disableExifSub: '@',
52
+ disableExifGps: '@',
53
+ disabled: '@disableImageMetaDataLoad'
54
+ },
55
+ {
56
+ action: 'loadImage',
57
+ // Use the action as prefix for the "@" options:
58
+ prefix: true,
59
+ fileTypes: '@',
60
+ maxFileSize: '@',
61
+ noRevoke: '@',
62
+ disabled: '@disableImageLoad'
63
+ },
64
+ {
65
+ action: 'resizeImage',
66
+ // Use "image" as prefix for the "@" options:
67
+ prefix: 'image',
68
+ maxWidth: '@',
69
+ maxHeight: '@',
70
+ minWidth: '@',
71
+ minHeight: '@',
72
+ crop: '@',
73
+ orientation: '@',
74
+ forceResize: '@',
75
+ disabled: '@disableImageResize'
76
+ },
77
+ {
78
+ action: 'saveImage',
79
+ quality: '@imageQuality',
80
+ type: '@imageType',
81
+ disabled: '@disableImageResize'
82
+ },
83
+ {
84
+ action: 'saveImageMetaData',
85
+ disabled: '@disableImageMetaDataSave'
86
+ },
87
+ {
88
+ action: 'resizeImage',
89
+ // Use "preview" as prefix for the "@" options:
90
+ prefix: 'preview',
91
+ maxWidth: '@',
92
+ maxHeight: '@',
93
+ minWidth: '@',
94
+ minHeight: '@',
95
+ crop: '@',
96
+ orientation: '@',
97
+ thumbnail: '@',
98
+ canvas: '@',
99
+ disabled: '@disableImagePreview'
100
+ },
101
+ {
102
+ action: 'setImage',
103
+ name: '@imagePreviewName',
104
+ disabled: '@disableImagePreview'
105
+ },
106
+ {
107
+ action: 'deleteImageReferences',
108
+ disabled: '@disableImageReferencesDeletion'
109
+ }
110
+ );
111
+
112
+ // The File Upload Resize plugin extends the fileupload widget
113
+ // with image resize functionality:
114
+ $.widget('blueimp.fileupload', $.blueimp.fileupload, {
115
+
116
+ options: {
117
+ // The regular expression for the types of images to load:
118
+ // matched against the file type:
119
+ loadImageFileTypes: /^image\/(gif|jpeg|png|svg\+xml)$/,
120
+ // The maximum file size of images to load:
121
+ loadImageMaxFileSize: 10000000, // 10MB
122
+ // The maximum width of resized images:
123
+ imageMaxWidth: 1920,
124
+ // The maximum height of resized images:
125
+ imageMaxHeight: 1080,
126
+ // Defines the image orientation (1-8) or takes the orientation
127
+ // value from Exif data if set to true:
128
+ imageOrientation: false,
129
+ // Define if resized images should be cropped or only scaled:
130
+ imageCrop: false,
131
+ // Disable the resize image functionality by default:
132
+ disableImageResize: true,
133
+ // The maximum width of the preview images:
134
+ previewMaxWidth: 80,
135
+ // The maximum height of the preview images:
136
+ previewMaxHeight: 80,
137
+ // Defines the preview orientation (1-8) or takes the orientation
138
+ // value from Exif data if set to true:
139
+ previewOrientation: true,
140
+ // Create the preview using the Exif data thumbnail:
141
+ previewThumbnail: true,
142
+ // Define if preview images should be cropped or only scaled:
143
+ previewCrop: false,
144
+ // Define if preview images should be resized as canvas elements:
145
+ previewCanvas: true
146
+ },
147
+
148
+ processActions: {
149
+
150
+ // Loads the image given via data.files and data.index
151
+ // as img element, if the browser supports the File API.
152
+ // Accepts the options fileTypes (regular expression)
153
+ // and maxFileSize (integer) to limit the files to load:
154
+ loadImage: function (data, options) {
155
+ if (options.disabled) {
156
+ return data;
157
+ }
158
+ var that = this,
159
+ file = data.files[data.index],
160
+ dfd = $.Deferred();
161
+ if (($.type(options.maxFileSize) === 'number' &&
162
+ file.size > options.maxFileSize) ||
163
+ (options.fileTypes &&
164
+ !options.fileTypes.test(file.type)) ||
165
+ !loadImage(
166
+ file,
167
+ function (img) {
168
+ if (img.src) {
169
+ data.img = img;
170
+ }
171
+ dfd.resolveWith(that, [data]);
172
+ },
173
+ options
174
+ )) {
175
+ return data;
176
+ }
177
+ return dfd.promise();
178
+ },
179
+
180
+ // Resizes the image given as data.canvas or data.img
181
+ // and updates data.canvas or data.img with the resized image.
182
+ // Also stores the resized image as preview property.
183
+ // Accepts the options maxWidth, maxHeight, minWidth,
184
+ // minHeight, canvas and crop:
185
+ resizeImage: function (data, options) {
186
+ if (options.disabled || !(data.canvas || data.img)) {
187
+ return data;
188
+ }
189
+ options = $.extend({canvas: true}, options);
190
+ var that = this,
191
+ dfd = $.Deferred(),
192
+ img = (options.canvas && data.canvas) || data.img,
193
+ resolve = function (newImg) {
194
+ if (newImg && (newImg.width !== img.width ||
195
+ newImg.height !== img.height ||
196
+ options.forceResize)) {
197
+ data[newImg.getContext ? 'canvas' : 'img'] = newImg;
198
+ }
199
+ data.preview = newImg;
200
+ dfd.resolveWith(that, [data]);
201
+ },
202
+ thumbnail;
203
+ if (data.exif) {
204
+ if (options.orientation === true) {
205
+ options.orientation = data.exif.get('Orientation');
206
+ }
207
+ if (options.thumbnail) {
208
+ thumbnail = data.exif.get('Thumbnail');
209
+ if (thumbnail) {
210
+ loadImage(thumbnail, resolve, options);
211
+ return dfd.promise();
212
+ }
213
+ }
214
+ // Prevent orienting the same image twice:
215
+ if (data.orientation) {
216
+ delete options.orientation;
217
+ } else {
218
+ data.orientation = options.orientation;
219
+ }
220
+ }
221
+ if (img) {
222
+ resolve(loadImage.scale(img, options));
223
+ return dfd.promise();
224
+ }
225
+ return data;
226
+ },
227
+
228
+ // Saves the processed image given as data.canvas
229
+ // inplace at data.index of data.files:
230
+ saveImage: function (data, options) {
231
+ if (!data.canvas || options.disabled) {
232
+ return data;
233
+ }
234
+ var that = this,
235
+ file = data.files[data.index],
236
+ dfd = $.Deferred();
237
+ if (data.canvas.toBlob) {
238
+ data.canvas.toBlob(
239
+ function (blob) {
240
+ if (!blob.name) {
241
+ if (file.type === blob.type) {
242
+ blob.name = file.name;
243
+ } else if (file.name) {
244
+ blob.name = file.name.replace(
245
+ /\.\w+$/,
246
+ '.' + blob.type.substr(6)
247
+ );
248
+ }
249
+ }
250
+ // Don't restore invalid meta data:
251
+ if (file.type !== blob.type) {
252
+ delete data.imageHead;
253
+ }
254
+ // Store the created blob at the position
255
+ // of the original file in the files list:
256
+ data.files[data.index] = blob;
257
+ dfd.resolveWith(that, [data]);
258
+ },
259
+ options.type || file.type,
260
+ options.quality
261
+ );
262
+ } else {
263
+ return data;
264
+ }
265
+ return dfd.promise();
266
+ },
267
+
268
+ loadImageMetaData: function (data, options) {
269
+ if (options.disabled) {
270
+ return data;
271
+ }
272
+ var that = this,
273
+ dfd = $.Deferred();
274
+ loadImage.parseMetaData(data.files[data.index], function (result) {
275
+ $.extend(data, result);
276
+ dfd.resolveWith(that, [data]);
277
+ }, options);
278
+ return dfd.promise();
279
+ },
280
+
281
+ saveImageMetaData: function (data, options) {
282
+ if (!(data.imageHead && data.canvas &&
283
+ data.canvas.toBlob && !options.disabled)) {
284
+ return data;
285
+ }
286
+ var file = data.files[data.index],
287
+ blob = new Blob([
288
+ data.imageHead,
289
+ // Resized images always have a head size of 20 bytes,
290
+ // including the JPEG marker and a minimal JFIF header:
291
+ this._blobSlice.call(file, 20)
292
+ ], {type: file.type});
293
+ blob.name = file.name;
294
+ data.files[data.index] = blob;
295
+ return data;
296
+ },
297
+
298
+ // Sets the resized version of the image as a property of the
299
+ // file object, must be called after "saveImage":
300
+ setImage: function (data, options) {
301
+ if (data.preview && !options.disabled) {
302
+ data.files[data.index][options.name || 'preview'] = data.preview;
303
+ }
304
+ return data;
305
+ },
306
+
307
+ deleteImageReferences: function (data, options) {
308
+ if (!options.disabled) {
309
+ delete data.img;
310
+ delete data.canvas;
311
+ delete data.preview;
312
+ delete data.imageHead;
313
+ }
314
+ return data;
315
+ }
316
+
317
+ }
318
+
319
+ });
320
+
321
+ }));
@@ -0,0 +1,175 @@
1
+ /*
2
+ * jQuery File Upload Processing Plugin
3
+ * https://github.com/blueimp/jQuery-File-Upload
4
+ *
5
+ * Copyright 2012, Sebastian Tschan
6
+ * https://blueimp.net
7
+ *
8
+ * Licensed under the MIT license:
9
+ * http://www.opensource.org/licenses/MIT
10
+ */
11
+
12
+ /* jshint nomen:false */
13
+ /* global define, require, window */
14
+
15
+ (function (factory) {
16
+ 'use strict';
17
+ if (typeof define === 'function' && define.amd) {
18
+ // Register as an anonymous AMD module:
19
+ define([
20
+ 'jquery',
21
+ './jquery.fileupload'
22
+ ], factory);
23
+ } else if (typeof exports === 'object') {
24
+ // Node/CommonJS:
25
+ factory(require('jquery'));
26
+ } else {
27
+ // Browser globals:
28
+ factory(
29
+ window.jQuery
30
+ );
31
+ }
32
+ }(function ($) {
33
+ 'use strict';
34
+
35
+ var originalAdd = $.blueimp.fileupload.prototype.options.add;
36
+
37
+ // The File Upload Processing plugin extends the fileupload widget
38
+ // with file processing functionality:
39
+ $.widget('blueimp.fileupload', $.blueimp.fileupload, {
40
+
41
+ options: {
42
+ // The list of processing actions:
43
+ processQueue: [
44
+ /*
45
+ {
46
+ action: 'log',
47
+ type: 'debug'
48
+ }
49
+ */
50
+ ],
51
+ add: function (e, data) {
52
+ var $this = $(this);
53
+ data.process(function () {
54
+ return $this.fileupload('process', data);
55
+ });
56
+ originalAdd.call(this, e, data);
57
+ }
58
+ },
59
+
60
+ processActions: {
61
+ /*
62
+ log: function (data, options) {
63
+ console[options.type](
64
+ 'Processing "' + data.files[data.index].name + '"'
65
+ );
66
+ }
67
+ */
68
+ },
69
+
70
+ _processFile: function (data, originalData) {
71
+ var that = this,
72
+ dfd = $.Deferred().resolveWith(that, [data]),
73
+ chain = dfd.promise();
74
+ this._trigger('process', null, data);
75
+ $.each(data.processQueue, function (i, settings) {
76
+ var func = function (data) {
77
+ if (originalData.errorThrown) {
78
+ return $.Deferred()
79
+ .rejectWith(that, [originalData]).promise();
80
+ }
81
+ return that.processActions[settings.action].call(
82
+ that,
83
+ data,
84
+ settings
85
+ );
86
+ };
87
+ chain = chain.pipe(func, settings.always && func);
88
+ });
89
+ chain
90
+ .done(function () {
91
+ that._trigger('processdone', null, data);
92
+ that._trigger('processalways', null, data);
93
+ })
94
+ .fail(function () {
95
+ that._trigger('processfail', null, data);
96
+ that._trigger('processalways', null, data);
97
+ });
98
+ return chain;
99
+ },
100
+
101
+ // Replaces the settings of each processQueue item that
102
+ // are strings starting with an "@", using the remaining
103
+ // substring as key for the option map,
104
+ // e.g. "@autoUpload" is replaced with options.autoUpload:
105
+ _transformProcessQueue: function (options) {
106
+ var processQueue = [];
107
+ $.each(options.processQueue, function () {
108
+ var settings = {},
109
+ action = this.action,
110
+ prefix = this.prefix === true ? action : this.prefix;
111
+ $.each(this, function (key, value) {
112
+ if ($.type(value) === 'string' &&
113
+ value.charAt(0) === '@') {
114
+ settings[key] = options[
115
+ value.slice(1) || (prefix ? prefix +
116
+ key.charAt(0).toUpperCase() + key.slice(1) : key)
117
+ ];
118
+ } else {
119
+ settings[key] = value;
120
+ }
121
+
122
+ });
123
+ processQueue.push(settings);
124
+ });
125
+ options.processQueue = processQueue;
126
+ },
127
+
128
+ // Returns the number of files currently in the processsing queue:
129
+ processing: function () {
130
+ return this._processing;
131
+ },
132
+
133
+ // Processes the files given as files property of the data parameter,
134
+ // returns a Promise object that allows to bind callbacks:
135
+ process: function (data) {
136
+ var that = this,
137
+ options = $.extend({}, this.options, data);
138
+ if (options.processQueue && options.processQueue.length) {
139
+ this._transformProcessQueue(options);
140
+ if (this._processing === 0) {
141
+ this._trigger('processstart');
142
+ }
143
+ $.each(data.files, function (index) {
144
+ var opts = index ? $.extend({}, options) : options,
145
+ func = function () {
146
+ if (data.errorThrown) {
147
+ return $.Deferred()
148
+ .rejectWith(that, [data]).promise();
149
+ }
150
+ return that._processFile(opts, data);
151
+ };
152
+ opts.index = index;
153
+ that._processing += 1;
154
+ that._processingQueue = that._processingQueue.pipe(func, func)
155
+ .always(function () {
156
+ that._processing -= 1;
157
+ if (that._processing === 0) {
158
+ that._trigger('processstop');
159
+ }
160
+ });
161
+ });
162
+ }
163
+ return this._processingQueue;
164
+ },
165
+
166
+ _create: function () {
167
+ this._super();
168
+ this._processing = 0;
169
+ this._processingQueue = $.Deferred().resolveWith(this)
170
+ .promise();
171
+ }
172
+
173
+ });
174
+
175
+ }));