thin_man 0.19.14 → 0.19.15

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
- SHA1:
3
- metadata.gz: d5b4cbda5757d7b31222d644d2685f6a3d713bc9
4
- data.tar.gz: c36e05fad643a166894b348f9c67c66b16757c48
2
+ SHA256:
3
+ metadata.gz: 59ad3b81d5beae60cfc461c76293e76c6223eebc6db7fea4a8fbce937c86d8ef
4
+ data.tar.gz: fd665789f547ac1d5a48d3ac6edda1d77d582663a20a035dd8c1719968e7b18f
5
5
  SHA512:
6
- metadata.gz: 6e72e621228b0a20289207d0c3f96bbd54c3e420fefd6b61b97d69a628cff0ff3a0f703e0d72eade329c24d915170c361917db083f121fc83e2546f8a0aa9c79
7
- data.tar.gz: 0aa04f2b853df8a725796cc2ca00d0ae4c6412c86b3a8c0fd312efe02ef81dddeede1ff33c35676cc2838cfbe2ab930282d91decae08677b5b7be55d2bd04357
6
+ metadata.gz: dcc02247caef48aae38629eb8ae3044765de86a4f3664e1d35669a5f7c6efbe44d00d8bb5f05a1e5f97fa03dbd77b5a6992c09aefd24c686ed55705ef153e9e4
7
+ data.tar.gz: c0482b6690f1d312afc976d0c25a0c1edb7310795c8652ce08cfe292db9c795334dad928abd3db343e2a4c8e72514e6dd64953dda6c7edf306786d3e6023afbb
@@ -0,0 +1,366 @@
1
+ /*S3*/
2
+ thin_man.s3Upload = Class.extend({
3
+ init: function($s3_upload_form){
4
+ this.upload_style = thin_man.getUploadStyle()
5
+ this.$s3_upload_form = $s3_upload_form;
6
+ var s3_upload = this;
7
+ this.$file_fields = this.$s3_upload_form.find('input[type="file"]');
8
+ if(this.$file_fields[0].files.length == 0){
9
+ this.sendWithoutFile()
10
+ return true
11
+ }
12
+
13
+ if('single_file' == this.upload_style){
14
+ this.fireOnlyFile()
15
+ } else if('multiple_file' == this.upload_style){
16
+ this.fireMultipleFiles()
17
+ }
18
+ },
19
+ sendWithoutFile: function(){
20
+ this.$s3_upload_form.attr('action',this.$s3_upload_form.data('local-url'));
21
+ var $s3_fields = this.$s3_upload_form.find('[data-sthree-fields]');
22
+ var $csrf_token = $('meta[name=csrf-token]').attr('content')
23
+ $s3_fields.remove();
24
+ this.$s3_upload_form.prepend("<input type='hidden' name='authenticity_token' value='" + $csrf_token + "'>")
25
+ new thin_man.AjaxFormSubmission(this.$s3_upload_form);
26
+ },
27
+ fireOnlyFile: function(){
28
+ var file = this.$file_fields[0].files[0]
29
+ new thin_man.s3UploadOnly(this.$s3_upload_form,file,this);
30
+ },
31
+ fireMultipleFiles: function(){
32
+ this.$file_fields.detach();
33
+ this.ajax_queue_length = 0;
34
+ this.file_queue = [];
35
+ var s3_upload = this
36
+ this.$file_fields.each(function(){
37
+ $.each(this.files, function(index,file){
38
+ s3_upload.file_queue.push(file);
39
+ })
40
+ })
41
+ var i = -1;
42
+ while(++i < 3){ //Start off 3 uploads. The others will be chained as these complete.
43
+ if(this.file_queue.length > 0){
44
+ s3_upload.fireOne(this.file_queue.shift());
45
+ }
46
+ }
47
+
48
+ },
49
+ fireOne: function(file){
50
+ var $cloned_form = this.$s3_upload_form.clone();
51
+ new thin_man.s3UploadSingle($cloned_form,file,this);
52
+ this.ajax_queue_length += 1;
53
+ },
54
+ completeOne: function(){
55
+ this.ajax_queue_length -= 1;
56
+ if(this.ajax_queue_length < 3){
57
+ if(this.file_queue.length > 0){
58
+ try{ // This could fail due to a race condition emptying the array. If so, we're done, don't throw an error
59
+ var next_file = this.file_queue.shift();
60
+ this.fireOne(next_file);
61
+ } catch(e){}
62
+ }
63
+ }
64
+ if(this.ajax_queue_length == 0){
65
+ this.$s3_upload_form.remove();
66
+ }
67
+ }
68
+ })
69
+
70
+ thin_man.s3UploadOnly = thin_man.AjaxFormSubmission.extend({
71
+ init: function($form,file,s3_upload){
72
+ this.$form = $form
73
+ this.file = file
74
+ this.file_slug = convertToSlug(this.file.name)
75
+ this.s3_upload = s3_upload;
76
+ this.$local_fields = this.$form.find('[data-local-field]');
77
+ this.$local_fields.detach();
78
+ var new_uuid = new UUID;
79
+ this.uniq_id = new_uuid.value;
80
+ this._super($form);
81
+ },
82
+ getData: function(){
83
+ var $key_field = this.$form.find('input[name="key"]:last')
84
+ $key_field.val($key_field.val() + this.uniq_id + '/' + this.file_slug)
85
+ var $file_field = this.$form.find('input[type="file"]:first')
86
+ $file_field.attr('name','file')
87
+ $file_field.removeAttr('multiple')
88
+ return new FormData(this.$form[0])
89
+ },
90
+ ajaxSuccess: function(data,textStatus,jqXHR){
91
+ this.$form.attr('action',this.$form.data('local-url'));
92
+ var $s3_fields = this.$form.find('[data-sthree-fields]');
93
+ $s3_fields.remove();
94
+ this.$form.append(this.$local_fields);
95
+ var $new_file_uniq_id = $('<input type="hidden" name="location_photo[uuid]" value="' + this.uniq_id + '">')
96
+ var $new_file_name = $('<input type="hidden" name="new_file_name" value="' + this.file_slug + '">')
97
+ var $csrf_token = $('meta[name=csrf-token]').attr('content')
98
+ this.$form.append($new_file_uniq_id)
99
+ this.$form.append($new_file_name)
100
+ this.$form.prepend("<input type='hidden' name='authenticity_token' value='" + $csrf_token + "'>")
101
+ new thin_man.AjaxFormSubmission(this.$form);
102
+ }
103
+ })
104
+ thin_man.s3UploadSingle = thin_man.AjaxFormSubmission.extend({
105
+ init: function($form,file,s3_upload){
106
+ this.$form = $form;
107
+ this.file = file;
108
+ this.file_slug = convertToSlug(this.file.name);
109
+ this.s3_upload = s3_upload;
110
+ this.base_target = this.$form.data('progress-target');
111
+ this.$base_target = $(this.base_target);
112
+ this.actual_progress_target_id = this.base_target + this.file_slug;
113
+ if(this.actual_progress_target_id.substr(0,1) == '#'){ this.actual_progress_target_id = this.actual_progress_target_id.slice(1)}
114
+ this.actual_progress_target_id = this.actual_progress_target_id.substr(0,this.actual_progress_target_id.indexOf('.'));
115
+ this.$actual_progress_target = $('<div class="ih-row" id="' + this.actual_progress_target_id + '">' + this.file.name + ' <progress max="1" value="0"></progress></div>');
116
+ this.$base_target.append(this.$actual_progress_target);
117
+ this.$form.data('progress-target', '#' + this.actual_progress_target_id );
118
+ this.$local_fields = this.$form.find('[data-local-field]');
119
+ this.$local_fields.detach();
120
+ var new_uuid = new UUID;
121
+ this.uniq_id = new_uuid.value;
122
+ this._super($form);
123
+ },
124
+ getData: function(){
125
+ var $key_field = this.$form.find('input[name="key"]:last')
126
+ s3_upload_single = this;
127
+ $key_field.val($key_field.val() + s3_upload_single.uniq_id + '/' + s3_upload_single.file_slug)
128
+ var form_data = new FormData();
129
+ var form_obj = arrayToObject(this.$form.serializeArray());
130
+ $.each(form_obj, function(name,value){
131
+ form_data.append(name, value);
132
+ })
133
+ form_data.append('file',this.file);
134
+ return form_data;
135
+ },
136
+ ajaxSuccess: function(data,textStatus,jqXHR){
137
+ this.$form.attr('action',this.$form.data('local-url'));
138
+ var $s3_fields = this.$form.find('[data-sthree-fields]');
139
+ $s3_fields.remove();
140
+ this.$form.append(this.$local_fields);
141
+ var $new_file_uniq_id = $('<input type="hidden" name="location_photo[uuid]" value="' + this.uniq_id + '">')
142
+ var $new_file_name = $('<input type="hidden" name="new_file_name" value="' + this.file_slug + '">')
143
+ var $csrf_token = $('meta[name=csrf-token]').attr('content')
144
+ this.$form.append($new_file_uniq_id)
145
+ this.$form.append($new_file_name)
146
+ this.$form.prepend("<input type='hidden' name='authenticity_token' value='" + $csrf_token + "'>")
147
+ new thin_man.AjaxFormSubmission(this.$form);
148
+ this.s3_upload.completeOne();
149
+ },
150
+ customXHR: function(){
151
+ var xhr = $.ajaxSettings.xhr();
152
+ if(xhr.upload){
153
+ var thin_man_obj = this.thin_man_obj;
154
+ xhr.upload.addEventListener('progress',
155
+ function(e){
156
+ if(e.lengthComputable){
157
+ var progress_bar = thin_man_obj.progress_target.find('progress');
158
+ progress_bar.attr('max',e.total);
159
+ progress_bar.attr('value',e.loaded);
160
+ }
161
+ },
162
+ false);
163
+ xhr.upload.addEventListener('load',
164
+ function(e){
165
+ thin_man_obj.progress_target.remove();
166
+ }
167
+ );
168
+ xhr.upload.addEventListener('abort',
169
+ function(e){
170
+ thin_man_obj.progress_target.remove();
171
+ }
172
+ );
173
+ xhr.upload.addEventListener('error',
174
+ function(e){
175
+ thin_man_obj.progress_target.html("There was an error upoading this file.");
176
+ }
177
+ );
178
+
179
+ }
180
+ return xhr;
181
+ }
182
+ })
183
+
184
+ /*google cloud*/
185
+ thin_man.googleCloudUpload = Class.extend({
186
+ init: function($gcloud_upload_form){
187
+ this.upload_style = thin_man.getUploadStyle()
188
+ this.$gcloud_upload_form = $gcloud_upload_form;
189
+ var gcloud_upload = this;
190
+ this.$file_fields = this.$gcloud_upload_form.find('input[type="file"]');
191
+ this.$file_fields.detach()
192
+ if(this.$file_fields[0].files.length == 0){
193
+ this.sendWithoutFile()
194
+ return true
195
+ } else {
196
+ this.getPresignedUrls()
197
+ }
198
+ },
199
+ getPresignedUrls: function(){
200
+ var presigned_forms_path = this.$gcloud_upload_form.data('presigned-forms-path')
201
+ var gcloud_upload = this;
202
+ this.filenames = {}
203
+ $.each(this.$file_fields[0].files,function(){
204
+ var filename = this.name
205
+ gcloud_upload.filenames[filename] = this
206
+ })
207
+ $.post(presigned_forms_path, {filenames: Object.keys(gcloud_upload.filenames)}, function(data){
208
+ gcloud_upload.presigned_posts = data
209
+ gcloud_upload.beginUpload()
210
+ })
211
+ },
212
+ beginUpload: function(){
213
+ if('single_file' == this.upload_style){
214
+ this.fireOnlyFile()
215
+ } else if('multiple_file' == this.upload_style){
216
+ this.fireMultipleFiles()
217
+ }
218
+ },
219
+ sendWithoutFile: function(){
220
+ this.$gcloud_upload_form.attr('action',this.$gcloud_upload_form.data('local-url'));
221
+ var $gcloud_fields = this.$gcloud_upload_form.find('[data-sthree-fields]');
222
+ var $csrf_token = $('meta[name=csrf-token]').attr('content')
223
+ $gcloud_fields.remove();
224
+ this.$gcloud_upload_form.prepend("<input type='hidden' name='authenticity_token' value='" + $csrf_token + "'>")
225
+ new thin_man.AjaxFormSubmission(this.$gcloud_upload_form);
226
+ },
227
+ fireOnlyFile: function(){
228
+ var file = this.$file_fields[0].files[0]
229
+ new thin_man.googleCloudUploadOnly(file,this);
230
+ },
231
+ fireMultipleFiles: function(){
232
+ this.ajax_queue_length = 0;
233
+ this.file_queue = [];
234
+ var gcloud_upload = this
235
+ this.$file_fields.each(function(){
236
+ $.each(this.files, function(index,file){
237
+ gcloud_upload.file_queue.push(file);
238
+ })
239
+ })
240
+ var i = -1;
241
+ while(++i < 3){ //Start off 3 uploads. The others will be chained as these complete.
242
+ if(this.file_queue.length > 0){
243
+ gcloud_upload.fireOne(this.file_queue.shift());
244
+ }
245
+ }
246
+
247
+ },
248
+ fireOne: function(file){
249
+ new thin_man.googleCloudUploadSingle(file,this);
250
+ this.ajax_queue_length += 1;
251
+ },
252
+ completeOne: function(){
253
+ this.ajax_queue_length -= 1;
254
+ if(this.ajax_queue_length < 3){
255
+ if(this.file_queue.length > 0){
256
+ try{ // This could fail due to a race condition emptying the array. If so, we're done, don't throw an error
257
+ var next_file = this.file_queue.shift();
258
+ this.fireOne(next_file);
259
+ } catch(e){}
260
+ }
261
+ }
262
+ }
263
+ })
264
+ thin_man.googleCloudUploadOnly = thin_man.AjaxFormSubmission.extend({
265
+ init: function(file,gcloud_upload){
266
+ this.gcloud_upload = gcloud_upload;
267
+ this.presigned = gcloud_upload.presigned_posts[file.name]
268
+ this.$form = $('<form>')
269
+ this.$form.attr('action',this.presigned.url)
270
+ this.file = file
271
+ this._super(this.$form);
272
+ },
273
+ getData: function(){
274
+ var form_data = new FormData();
275
+ $.each(this.presigned.fields, function(name,value){
276
+ form_data.append(name, value);
277
+ })
278
+ form_data.append('file',this.file);
279
+ return form_data;
280
+ },
281
+ ajaxSuccess: function(data,textStatus,jqXHR){
282
+ this.$form = this.gcloud_upload.$gcloud_upload_form
283
+ var $new_file_uniq_id = $('<input type="hidden" name="location_photo[uuid]" value="' + this.presigned.uuid + '">')
284
+ var $new_file_name = $('<input type="hidden" name="new_file_name" value="' + this.file.name + '">')
285
+ var $csrf_token = $('meta[name=csrf-token]').attr('content')
286
+ this.$form.append($new_file_uniq_id)
287
+ this.$form.append($new_file_name)
288
+ this.$form.prepend("<input type='hidden' name='authenticity_token' value='" + $csrf_token + "'>")
289
+ new thin_man.AjaxFormSubmission(this.$form);
290
+ },
291
+ ajaxError: function(jqXHR){
292
+ jqXHR
293
+ }
294
+ })
295
+ thin_man.googleCloudUploadSingle = thin_man.AjaxFormSubmission.extend({
296
+ init: function(file,gcloud_upload){
297
+ this.gcloud_upload = gcloud_upload;
298
+ this.presigned = gcloud_upload.presigned_posts[file.name]
299
+ this.$form = $('<form>')
300
+ this.$form.attr('action',this.presigned.url)
301
+ this.file = file;
302
+ this.initProgressBars()
303
+ this._super(this.$form);
304
+ },
305
+ initProgressBars: function(){
306
+ this.base_target = this.$form.data('progress-target');
307
+ this.$base_target = $(this.base_target);
308
+ this.actual_progress_target_id = this.base_target + this.file.name;
309
+ if(this.actual_progress_target_id.substr(0,1) == '#'){ this.actual_progress_target_id = this.actual_progress_target_id.slice(1)}
310
+ this.actual_progress_target_id = this.actual_progress_target_id.substr(0,this.actual_progress_target_id.indexOf('.'));
311
+ this.$actual_progress_target = $('<div class="ih-row" id="' + this.actual_progress_target_id + '">' + this.file.name + ' <progress max="1" value="0"></progress></div>');
312
+ this.$base_target.append(this.$actual_progress_target);
313
+ this.$form.data('progress-target', '#' + this.actual_progress_target_id );
314
+ },
315
+ getData: function(){
316
+ var form_data = new FormData();
317
+ $.each(this.presigned.fields, function(name,value){
318
+ form_data.append(name, value);
319
+ })
320
+ form_data.append('file',this.file);
321
+ return form_data;
322
+ },
323
+ ajaxSuccess: function(data,textStatus,jqXHR){
324
+ this.$form = this.gcloud_upload.$gcloud_upload_form
325
+ var $new_file_uniq_id = $('<input type="hidden" name="location_photo[uuid]" value="' + this.presigned.uuid + '">')
326
+ var $new_file_name = $('<input type="hidden" name="new_file_name" value="' + this.file.name + '">')
327
+ var $csrf_token = $('meta[name=csrf-token]').attr('content')
328
+ this.$form.append($new_file_uniq_id)
329
+ this.$form.append($new_file_name)
330
+ this.$form.prepend("<input type='hidden' name='authenticity_token' value='" + $csrf_token + "'>")
331
+ new thin_man.AjaxFormSubmission(this.$form);
332
+ this.gcloud_upload.completeOne();
333
+ }//,
334
+ // customXHR: function(){
335
+ // var xhr = new window.XMLHttpRequest();
336
+ // if(xhr.upload){
337
+ // var thin_man_obj = this.thin_man_obj;
338
+ // xhr.upload.addEventListener('progress',
339
+ // function(e){
340
+ // if(e.lengthComputable){
341
+ // var progress_bar = thin_man_obj.progress_target.find('progress');
342
+ // progress_bar.attr('max',e.total);
343
+ // progress_bar.attr('value',e.loaded);
344
+ // }
345
+ // },
346
+ // false);
347
+ // xhr.upload.addEventListener('load',
348
+ // function(e){
349
+ // thin_man_obj.progress_target.remove();
350
+ // }
351
+ // );
352
+ // xhr.upload.addEventListener('abort',
353
+ // function(e){
354
+ // thin_man_obj.progress_target.remove();
355
+ // }
356
+ // );
357
+ // xhr.upload.addEventListener('error',
358
+ // function(e){
359
+ // thin_man_obj.progress_target.html("There was an error upoading this file.");
360
+ // }
361
+ // );
362
+ // }
363
+ // return xhr;
364
+ // }
365
+ })
366
+ */
@@ -212,8 +212,6 @@ var initThinMan = function() {
212
212
  } else {
213
213
  this.insertHtml(data.html)
214
214
  }
215
- } else if (this.target && typeof(this.target.empty) == 'function') {
216
- this.target.empty()
217
215
  }
218
216
  if (typeof data.class_triggers != 'undefined') {
219
217
  $.each(data.class_triggers, function(class_name, params) {
@@ -1,3 +1,3 @@
1
1
  module ThinMan
2
- VERSION = "0.19.14"
2
+ VERSION = "0.19.15"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thin_man
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.19.14
4
+ version: 0.19.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Draut, Adam Bialek
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-07-09 00:00:00.000000000 Z
11
+ date: 2018-10-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -86,10 +86,10 @@ executables: []
86
86
  extensions: []
87
87
  extra_rdoc_files: []
88
88
  files:
89
- - MIT-LICENSE
90
89
  - Rakefile
91
90
  - app/assets/javascripts/debug_logger.js
92
- - app/assets/javascripts/simple_inheritance.hs
91
+ - app/assets/javascripts/experimental_uploaders.js
92
+ - app/assets/javascripts/simple_inheritance.js
93
93
  - app/assets/javascripts/thin_man.js
94
94
  - lib/tasks/thin_man_tasks.rake
95
95
  - lib/thin_man.rb
@@ -128,7 +128,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
128
128
  version: '0'
129
129
  requirements: []
130
130
  rubyforge_project:
131
- rubygems_version: 2.6.13
131
+ rubygems_version: 2.7.7
132
132
  signing_key:
133
133
  specification_version: 4
134
134
  summary: A Rails library that makes web apps lively while keeping all the logic on
@@ -139,9 +139,9 @@ test_files:
139
139
  - test/dummy/README.rdoc
140
140
  - test/javascript/spec/thinManSpec.js
141
141
  - test/javascript/jasmine-fixture.js
142
- - test/javascript/jquery.js
143
- - test/javascript/karma.conf.js
144
142
  - test/javascript/package.json
143
+ - test/javascript/karma.conf.js
145
144
  - test/javascript/test-main.js
146
- - test/test_helper.rb
145
+ - test/javascript/jquery.js
147
146
  - test/thin_man_test.rb
147
+ - test/test_helper.rb
@@ -1,20 +0,0 @@
1
- Copyright 2014 YOURNAME
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.