spree_image_multi_upload 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +15 -0
  3. data/.rspec +1 -0
  4. data/Gemfile +3 -0
  5. data/LICENSE +26 -0
  6. data/README.md +29 -0
  7. data/Rakefile +15 -0
  8. data/Versionfile +1 -0
  9. data/app/assets/javascripts/admin/jquery-fileupload/basic.js +4 -0
  10. data/app/assets/javascripts/admin/jquery-fileupload/cors/jquery.postmessage-transport.js +117 -0
  11. data/app/assets/javascripts/admin/jquery-fileupload/cors/jquery.xdr-transport.js +87 -0
  12. data/app/assets/javascripts/admin/jquery-fileupload/index.js +9 -0
  13. data/app/assets/javascripts/admin/jquery-fileupload/jquery.fileupload-fp.js +223 -0
  14. data/app/assets/javascripts/admin/jquery-fileupload/jquery.fileupload-ui.js +799 -0
  15. data/app/assets/javascripts/admin/jquery-fileupload/jquery.fileupload.js +1164 -0
  16. data/app/assets/javascripts/admin/jquery-fileupload/jquery.iframe-transport.js +185 -0
  17. data/app/assets/javascripts/admin/jquery-fileupload/locale.js.erb +30 -0
  18. data/app/assets/javascripts/admin/jquery-fileupload/vendor/canvas-to-blob.js +91 -0
  19. data/app/assets/javascripts/admin/jquery-fileupload/vendor/jquery.ui.widget.js +530 -0
  20. data/app/assets/javascripts/admin/jquery-fileupload/vendor/load-image.js +121 -0
  21. data/app/assets/javascripts/admin/jquery-fileupload/vendor/tmpl.js +86 -0
  22. data/app/assets/javascripts/admin/spree_image_multi_upload.js +3 -0
  23. data/app/assets/stylesheets/admin/jquery.fileupload-ui.scss +84 -0
  24. data/app/assets/stylesheets/admin/spree_image_multi_upload.css +4 -0
  25. data/app/controllers/spree/admin/images_controller_decorator.rb +39 -0
  26. data/app/models/image_decorator.rb +17 -0
  27. data/app/overrides/admin_decorator.rb +6 -0
  28. data/app/views/spree/admin/images/_template_download.html.erb +33 -0
  29. data/app/views/spree/admin/images/_template_upload.html.erb +36 -0
  30. data/app/views/spree/admin/images/multi_upload.html.erb +48 -0
  31. data/app/views/spree/admin/images/multi_upload.js.erb +4 -0
  32. data/config/locales/en.yml +15 -0
  33. data/config/locales/ru.yml +15 -0
  34. data/config/routes.rb +11 -0
  35. data/lib/generators/spree_image_multi_upload/install/install_generator.rb +16 -0
  36. data/lib/spree_image_multi_upload.rb +2 -0
  37. data/lib/spree_image_multi_upload/engine.rb +22 -0
  38. data/script/rails +7 -0
  39. data/spec/spec_helper.rb +46 -0
  40. data/spree_image_multi_upload.gemspec +25 -0
  41. metadata +154 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7230b3b2b488039710fd9fc9bd8437a79c92a79e
4
+ data.tar.gz: 0ea9ab910562b00277e20e104dcfbb5d61e0cd8f
5
+ SHA512:
6
+ metadata.gz: 43bb708849a0e09f7b40002065d9ea480105e543b5358391bf4bf401a008854cbb63914195255da668ac6b6c2634223b1d81c65234f2d8697d08185396133791
7
+ data.tar.gz: 3e0142bf8b62ce271a7b88f9158439f96268932d486025db3bf74acc9268b4ebf39b63443a88a0c8a470b12682f0141d92036bb4ef731297727810e64e477f88
data/.gitignore ADDED
@@ -0,0 +1,15 @@
1
+ \#*
2
+ *~
3
+ .#*
4
+ .DS_Store
5
+ .idea
6
+ .project
7
+ .sass-cache
8
+ coverage
9
+ Gemfile.lock
10
+ tmp
11
+ nbproject
12
+ pkg
13
+ *.swp
14
+ spec/dummy
15
+ .rvmrc
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --colour
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'http://rubygems.org'
2
+ gem 'spree_auth_devise', :git => "git://github.com/spree/spree_auth_devise", :branch => '2-3-stable'
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,26 @@
1
+ Copyright (c) 2013 Maks Sleptsov (Service & Consulting)
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without modification,
5
+ are permitted provided that the following conditions are met:
6
+
7
+ * Redistributions of source code must retain the above copyright notice,
8
+ this list of conditions and the following disclaimer.
9
+ * Redistributions in binary form must reproduce the above copyright notice,
10
+ this list of conditions and the following disclaimer in the documentation
11
+ and/or other materials provided with the distribution.
12
+ * Neither the name Spree nor the names of its contributors may be used to
13
+ endorse or promote products derived from this software without specific
14
+ prior written permission.
15
+
16
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
20
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
24
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ Spree Image Multi Upload
2
+ =====================
3
+
4
+ Allow Spree to upload multi product images at the same time
5
+
6
+ Requirements
7
+ ------------
8
+
9
+ Extension in master branch depends on Spree 2.3.x.
10
+
11
+
12
+ Installation
13
+ ------------
14
+
15
+ To use the last stable release of spree_image_multi_upload, add the following to your Gemfile:
16
+ ```ruby
17
+ gem 'spree_image_multi_upload', :git => 'git://github.com/huyngvu/spree_image_multi_upload.git'
18
+ ```
19
+
20
+ Now bundle up with:
21
+ ```
22
+ bundle install
23
+ ```
24
+
25
+ Now you should be able to boot up your server with:
26
+ ```
27
+ rails s
28
+ ```
29
+
data/Rakefile ADDED
@@ -0,0 +1,15 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'rspec/core/rake_task'
5
+ require 'spree/core/testing_support/common_rake'
6
+
7
+ RSpec::Core::RakeTask.new
8
+
9
+ task :default => [:spec]
10
+
11
+ desc 'Generates a dummy app for testing'
12
+ task :test_app do
13
+ ENV['LIB_NAME'] = 'spree_image_multi_upload'
14
+ Rake::Task['common:test_app'].invoke
15
+ end
data/Versionfile ADDED
@@ -0,0 +1 @@
1
+ '1.0.x' => { :branch => 'master' }
@@ -0,0 +1,4 @@
1
+ //=require ./vendor/jquery.ui.widget
2
+ //=require ./jquery.iframe-transport
3
+ //=require ./jquery.fileupload
4
+
@@ -0,0 +1,117 @@
1
+ /*
2
+ * jQuery postMessage Transport Plugin 1.1
3
+ * https://github.com/blueimp/jQuery-File-Upload
4
+ *
5
+ * Copyright 2011, Sebastian Tschan
6
+ * https://blueimp.net
7
+ *
8
+ * Licensed under the MIT license:
9
+ * http://www.opensource.org/licenses/MIT
10
+ */
11
+
12
+ /*jslint unparam: true, nomen: true */
13
+ /*global define, 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(['jquery'], factory);
20
+ } else {
21
+ // Browser globals:
22
+ factory(window.jQuery);
23
+ }
24
+ }(function ($) {
25
+ 'use strict';
26
+
27
+ var counter = 0,
28
+ names = [
29
+ 'accepts',
30
+ 'cache',
31
+ 'contents',
32
+ 'contentType',
33
+ 'crossDomain',
34
+ 'data',
35
+ 'dataType',
36
+ 'headers',
37
+ 'ifModified',
38
+ 'mimeType',
39
+ 'password',
40
+ 'processData',
41
+ 'timeout',
42
+ 'traditional',
43
+ 'type',
44
+ 'url',
45
+ 'username'
46
+ ],
47
+ convert = function (p) {
48
+ return p;
49
+ };
50
+
51
+ $.ajaxSetup({
52
+ converters: {
53
+ 'postmessage text': convert,
54
+ 'postmessage json': convert,
55
+ 'postmessage html': convert
56
+ }
57
+ });
58
+
59
+ $.ajaxTransport('postmessage', function (options) {
60
+ if (options.postMessage && window.postMessage) {
61
+ var iframe,
62
+ loc = $('<a>').prop('href', options.postMessage)[0],
63
+ target = loc.protocol + '//' + loc.host,
64
+ xhrUpload = options.xhr().upload;
65
+ return {
66
+ send: function (_, completeCallback) {
67
+ var message = {
68
+ id: 'postmessage-transport-' + (counter += 1)
69
+ },
70
+ eventName = 'message.' + message.id;
71
+ iframe = $(
72
+ '<iframe style="display:none;" src="' +
73
+ options.postMessage + '" name="' +
74
+ message.id + '"></iframe>'
75
+ ).bind('load', function () {
76
+ $.each(names, function (i, name) {
77
+ message[name] = options[name];
78
+ });
79
+ message.dataType = message.dataType.replace('postmessage ', '');
80
+ $(window).bind(eventName, function (e) {
81
+ e = e.originalEvent;
82
+ var data = e.data,
83
+ ev;
84
+ if (e.origin === target && data.id === message.id) {
85
+ if (data.type === 'progress') {
86
+ ev = document.createEvent('Event');
87
+ ev.initEvent(data.type, false, true);
88
+ $.extend(ev, data);
89
+ xhrUpload.dispatchEvent(ev);
90
+ } else {
91
+ completeCallback(
92
+ data.status,
93
+ data.statusText,
94
+ {postmessage: data.result},
95
+ data.headers
96
+ );
97
+ iframe.remove();
98
+ $(window).unbind(eventName);
99
+ }
100
+ }
101
+ });
102
+ iframe[0].contentWindow.postMessage(
103
+ message,
104
+ target
105
+ );
106
+ }).appendTo(document.body);
107
+ },
108
+ abort: function () {
109
+ if (iframe) {
110
+ iframe.remove();
111
+ }
112
+ }
113
+ };
114
+ }
115
+ });
116
+
117
+ }));
@@ -0,0 +1,87 @@
1
+ /*
2
+ * jQuery XDomainRequest Transport Plugin 1.1.3
3
+ * https://github.com/blueimp/jQuery-File-Upload
4
+ *
5
+ * Copyright 2011, Sebastian Tschan
6
+ * https://blueimp.net
7
+ *
8
+ * Licensed under the MIT license:
9
+ * http://www.opensource.org/licenses/MIT
10
+ *
11
+ * Based on Julian Aubourg's ajaxHooks xdr.js:
12
+ * https://github.com/jaubourg/ajaxHooks/
13
+ */
14
+
15
+ /*jslint unparam: true */
16
+ /*global define, window, XDomainRequest */
17
+
18
+ (function (factory) {
19
+ 'use strict';
20
+ if (typeof define === 'function' && define.amd) {
21
+ // Register as an anonymous AMD module:
22
+ define(['jquery'], factory);
23
+ } else {
24
+ // Browser globals:
25
+ factory(window.jQuery);
26
+ }
27
+ }(function ($) {
28
+ 'use strict';
29
+ if (window.XDomainRequest && !$.support.cors) {
30
+ $.ajaxTransport(function (s) {
31
+ if (s.crossDomain && s.async) {
32
+ if (s.timeout) {
33
+ s.xdrTimeout = s.timeout;
34
+ delete s.timeout;
35
+ }
36
+ var xdr;
37
+ return {
38
+ send: function (headers, completeCallback) {
39
+ var addParamChar = /\?/.test(s.url) ? '&' : '?';
40
+ function callback(status, statusText, responses, responseHeaders) {
41
+ xdr.onload = xdr.onerror = xdr.ontimeout = $.noop;
42
+ xdr = null;
43
+ completeCallback(status, statusText, responses, responseHeaders);
44
+ }
45
+ xdr = new XDomainRequest();
46
+ // XDomainRequest only supports GET and POST:
47
+ if (s.type === 'DELETE') {
48
+ s.url = s.url + addParamChar + '_method=DELETE';
49
+ s.type = 'POST';
50
+ } else if (s.type === 'PUT') {
51
+ s.url = s.url + addParamChar + '_method=PUT';
52
+ s.type = 'POST';
53
+ } else if (s.type === 'PATCH') {
54
+ s.url = s.url + addParamChar + '_method=PATCH';
55
+ s.type = 'POST';
56
+ }
57
+ xdr.open(s.type, s.url);
58
+ xdr.onload = function () {
59
+ callback(
60
+ 200,
61
+ 'OK',
62
+ {text: xdr.responseText},
63
+ 'Content-Type: ' + xdr.contentType
64
+ );
65
+ };
66
+ xdr.onerror = function () {
67
+ callback(404, 'Not Found');
68
+ };
69
+ if (s.xdrTimeout) {
70
+ xdr.ontimeout = function () {
71
+ callback(0, 'timeout');
72
+ };
73
+ xdr.timeout = s.xdrTimeout;
74
+ }
75
+ xdr.send((s.hasContent && s.data) || null);
76
+ },
77
+ abort: function () {
78
+ if (xdr) {
79
+ xdr.onerror = $.noop();
80
+ xdr.abort();
81
+ }
82
+ }
83
+ };
84
+ }
85
+ });
86
+ }
87
+ }));
@@ -0,0 +1,9 @@
1
+ //=require ./vendor/jquery.ui.widget
2
+ //=require ./vendor/load-image
3
+ //=require ./vendor/canvas-to-blob
4
+ //=require ./vendor/tmpl
5
+ //=require ./jquery.iframe-transport
6
+ //=require ./jquery.fileupload
7
+ //=require ./jquery.fileupload-fp
8
+ //=require ./jquery.fileupload-ui
9
+ //=require ./locale
@@ -0,0 +1,223 @@
1
+ /*
2
+ * jQuery File Upload File Processing Plugin 1.2.1
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
+ /*jslint nomen: true, unparam: true, regexp: true */
13
+ /*global define, 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
+ 'canvas-to-blob',
23
+ './jquery.fileupload'
24
+ ], factory);
25
+ } else {
26
+ // Browser globals:
27
+ factory(
28
+ window.jQuery,
29
+ window.loadImage
30
+ );
31
+ }
32
+ }(function ($, loadImage) {
33
+ 'use strict';
34
+
35
+ // The File Upload FP version extends the fileupload widget
36
+ // with file processing functionality:
37
+ $.widget('blueimp.fileupload', $.blueimp.fileupload, {
38
+
39
+ options: {
40
+ // The list of file processing actions:
41
+ process: [
42
+ /*
43
+ {
44
+ action: 'load',
45
+ fileTypes: /^image\/(gif|jpeg|png)$/,
46
+ maxFileSize: 20000000 // 20MB
47
+ },
48
+ {
49
+ action: 'resize',
50
+ maxWidth: 1920,
51
+ maxHeight: 1200,
52
+ minWidth: 800,
53
+ minHeight: 600
54
+ },
55
+ {
56
+ action: 'save'
57
+ }
58
+ */
59
+ ],
60
+
61
+ // The add callback is invoked as soon as files are added to the
62
+ // fileupload widget (via file input selection, drag & drop or add
63
+ // API call). See the basic file upload widget for more information:
64
+ add: function (e, data) {
65
+ $(this).fileupload('process', data).done(function () {
66
+ data.submit();
67
+ });
68
+ }
69
+ },
70
+
71
+ processActions: {
72
+ // Loads the image given via data.files and data.index
73
+ // as img element if the browser supports canvas.
74
+ // Accepts the options fileTypes (regular expression)
75
+ // and maxFileSize (integer) to limit the files to load:
76
+ load: function (data, options) {
77
+ var that = this,
78
+ file = data.files[data.index],
79
+ dfd = $.Deferred();
80
+ if (window.HTMLCanvasElement &&
81
+ window.HTMLCanvasElement.prototype.toBlob &&
82
+ ($.type(options.maxFileSize) !== 'number' ||
83
+ file.size < options.maxFileSize) &&
84
+ (!options.fileTypes ||
85
+ options.fileTypes.test(file.type))) {
86
+ loadImage(
87
+ file,
88
+ function (img) {
89
+ if (!img.src) {
90
+ return dfd.rejectWith(that, [data]);
91
+ }
92
+ data.img = img;
93
+ dfd.resolveWith(that, [data]);
94
+ }
95
+ );
96
+ } else {
97
+ dfd.rejectWith(that, [data]);
98
+ }
99
+ return dfd.promise();
100
+ },
101
+ // Resizes the image given as data.img and updates
102
+ // data.canvas with the resized image as canvas element.
103
+ // Accepts the options maxWidth, maxHeight, minWidth and
104
+ // minHeight to scale the given image:
105
+ resize: function (data, options) {
106
+ var img = data.img,
107
+ canvas;
108
+ options = $.extend({canvas: true}, options);
109
+ if (img) {
110
+ canvas = loadImage.scale(img, options);
111
+ if (canvas.width !== img.width ||
112
+ canvas.height !== img.height) {
113
+ data.canvas = canvas;
114
+ }
115
+ }
116
+ return data;
117
+ },
118
+ // Saves the processed image given as data.canvas
119
+ // inplace at data.index of data.files:
120
+ save: function (data, options) {
121
+ // Do nothing if no processing has happened:
122
+ if (!data.canvas) {
123
+ return data;
124
+ }
125
+ var that = this,
126
+ file = data.files[data.index],
127
+ name = file.name,
128
+ dfd = $.Deferred(),
129
+ callback = function (blob) {
130
+ if (!blob.name) {
131
+ if (file.type === blob.type) {
132
+ blob.name = file.name;
133
+ } else if (file.name) {
134
+ blob.name = file.name.replace(
135
+ /\..+$/,
136
+ '.' + blob.type.substr(6)
137
+ );
138
+ }
139
+ }
140
+ // Store the created blob at the position
141
+ // of the original file in the files list:
142
+ data.files[data.index] = blob;
143
+ dfd.resolveWith(that, [data]);
144
+ };
145
+ // Use canvas.mozGetAsFile directly, to retain the filename, as
146
+ // Gecko doesn't support the filename option for FormData.append:
147
+ if (data.canvas.mozGetAsFile) {
148
+ callback(data.canvas.mozGetAsFile(
149
+ (/^image\/(jpeg|png)$/.test(file.type) && name) ||
150
+ ((name && name.replace(/\..+$/, '')) ||
151
+ 'blob') + '.png',
152
+ file.type
153
+ ));
154
+ } else {
155
+ data.canvas.toBlob(callback, file.type);
156
+ }
157
+ return dfd.promise();
158
+ }
159
+ },
160
+
161
+ // Resizes the file at the given index and stores the created blob at
162
+ // the original position of the files list, returns a Promise object:
163
+ _processFile: function (files, index, options) {
164
+ var that = this,
165
+ dfd = $.Deferred().resolveWith(that, [{
166
+ files: files,
167
+ index: index
168
+ }]),
169
+ chain = dfd.promise();
170
+ that._processing += 1;
171
+ $.each(options.process, function (i, settings) {
172
+ chain = chain.pipe(function (data) {
173
+ return that.processActions[settings.action]
174
+ .call(this, data, settings);
175
+ });
176
+ });
177
+ chain.always(function () {
178
+ that._processing -= 1;
179
+ if (that._processing === 0) {
180
+ that.element
181
+ .removeClass('fileupload-processing');
182
+ }
183
+ });
184
+ if (that._processing === 1) {
185
+ that.element.addClass('fileupload-processing');
186
+ }
187
+ return chain;
188
+ },
189
+
190
+ // Processes the files given as files property of the data parameter,
191
+ // returns a Promise object that allows to bind a done handler, which
192
+ // will be invoked after processing all files (inplace) is done:
193
+ process: function (data) {
194
+ var that = this,
195
+ options = $.extend({}, this.options, data);
196
+ if (options.process && options.process.length &&
197
+ this._isXHRUpload(options)) {
198
+ $.each(data.files, function (index, file) {
199
+ that._processingQueue = that._processingQueue.pipe(
200
+ function () {
201
+ var dfd = $.Deferred();
202
+ that._processFile(data.files, index, options)
203
+ .always(function () {
204
+ dfd.resolveWith(that);
205
+ });
206
+ return dfd.promise();
207
+ }
208
+ );
209
+ });
210
+ }
211
+ return this._processingQueue;
212
+ },
213
+
214
+ _create: function () {
215
+ this._super();
216
+ this._processing = 0;
217
+ this._processingQueue = $.Deferred().resolveWith(this)
218
+ .promise();
219
+ }
220
+
221
+ });
222
+
223
+ }));