tessa 6.0.0 → 6.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/javascripts/tessa.esm.js +173 -212
- data/app/assets/javascripts/tessa.js +167 -206
- data/lib/tessa/simple_form/asset_input.rb +2 -2
- data/lib/tessa/version.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 97d04730151300a62dbd1abc5a52d0fa768ff9170b08f3fb1e3ac40aea74278e
|
4
|
+
data.tar.gz: 0fcd8e364428394587b86af49e2042bdcb14574c7c9f499164c62d235114977b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 44ee62a0b0fe6b810559e85c9032929b16f3ea22ac0cd2b41045a86614ad60c9e0b1aedc86e3884e51fe923d9e44ed0e5514b615af3dc99700c26ec1400a1dd3
|
7
|
+
data.tar.gz: f869838f12e587ee6ced568125dca1ffd44973955a276f5d37fb5b4711829cc09b85c6b1f69f780de2bb1e83ecaf5994738a796f48fec623083efdbcb59aebe6
|
@@ -1,34 +1,3 @@
|
|
1
|
-
var extendStatics = function(d, b) {
|
2
|
-
extendStatics = Object.setPrototypeOf || {
|
3
|
-
__proto__: []
|
4
|
-
} instanceof Array && function(d, b) {
|
5
|
-
d.__proto__ = b;
|
6
|
-
} || function(d, b) {
|
7
|
-
for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p];
|
8
|
-
};
|
9
|
-
return extendStatics(d, b);
|
10
|
-
};
|
11
|
-
|
12
|
-
function __extends(d, b) {
|
13
|
-
if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
14
|
-
extendStatics(d, b);
|
15
|
-
function __() {
|
16
|
-
this.constructor = d;
|
17
|
-
}
|
18
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __);
|
19
|
-
}
|
20
|
-
|
21
|
-
var __assign = function() {
|
22
|
-
__assign = Object.assign || function __assign(t) {
|
23
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
24
|
-
s = arguments[i];
|
25
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
26
|
-
}
|
27
|
-
return t;
|
28
|
-
};
|
29
|
-
return __assign.apply(this, arguments);
|
30
|
-
};
|
31
|
-
|
32
1
|
var sparkMd5 = {
|
33
2
|
exports: {}
|
34
3
|
};
|
@@ -441,269 +410,261 @@ var sparkMd5 = {
|
|
441
410
|
}));
|
442
411
|
})(sparkMd5);
|
443
412
|
|
444
|
-
var
|
413
|
+
var SparkMD5 = sparkMd5.exports;
|
445
414
|
|
446
|
-
|
447
|
-
|
415
|
+
const fileSlice = File.prototype.slice || File.prototype.mozSlice || File.prototype.webkitSlice;
|
416
|
+
|
417
|
+
class FileChecksum {
|
418
|
+
static create(file, callback) {
|
419
|
+
const instance = new FileChecksum(file);
|
420
|
+
instance.create(callback);
|
421
|
+
}
|
422
|
+
constructor(file) {
|
448
423
|
this.file = file;
|
449
424
|
this.chunkSize = 2097152;
|
450
425
|
this.chunkCount = Math.ceil(this.file.size / this.chunkSize);
|
451
426
|
this.chunkIndex = 0;
|
452
427
|
}
|
453
|
-
|
454
|
-
var instance = new FileChecksum(file);
|
455
|
-
instance.create(callback);
|
456
|
-
};
|
457
|
-
FileChecksum.prototype.create = function(callback) {
|
458
|
-
var _this = this;
|
428
|
+
create(callback) {
|
459
429
|
this.callback = callback;
|
460
|
-
this.md5Buffer = new
|
430
|
+
this.md5Buffer = new SparkMD5.ArrayBuffer;
|
461
431
|
this.fileReader = new FileReader;
|
462
|
-
this.fileReader.addEventListener("load", (
|
463
|
-
|
464
|
-
}));
|
465
|
-
this.fileReader.addEventListener("error", (function(event) {
|
466
|
-
return _this.fileReaderDidError(event);
|
467
|
-
}));
|
432
|
+
this.fileReader.addEventListener("load", (event => this.fileReaderDidLoad(event)));
|
433
|
+
this.fileReader.addEventListener("error", (event => this.fileReaderDidError(event)));
|
468
434
|
this.readNextChunk();
|
469
|
-
}
|
470
|
-
|
471
|
-
var _a;
|
472
|
-
if (!this.md5Buffer || !this.fileReader) {
|
473
|
-
throw new Error("FileChecksum: fileReaderDidLoad called before create");
|
474
|
-
}
|
475
|
-
if (!((_a = event.target) === null || _a === void 0 ? void 0 : _a.result)) {
|
476
|
-
return;
|
477
|
-
}
|
435
|
+
}
|
436
|
+
fileReaderDidLoad(event) {
|
478
437
|
this.md5Buffer.append(event.target.result);
|
479
438
|
if (!this.readNextChunk()) {
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
this.callback(null, base64digest);
|
484
|
-
}
|
485
|
-
}
|
486
|
-
};
|
487
|
-
FileChecksum.prototype.fileReaderDidError = function(event) {
|
488
|
-
if (this.callback) {
|
489
|
-
this.callback("Error reading ".concat(this.file.name));
|
490
|
-
}
|
491
|
-
};
|
492
|
-
FileChecksum.prototype.readNextChunk = function() {
|
493
|
-
if (!this.fileReader) {
|
494
|
-
throw new Error("FileChecksum: readNextChunk called before create");
|
439
|
+
const binaryDigest = this.md5Buffer.end(true);
|
440
|
+
const base64digest = btoa(binaryDigest);
|
441
|
+
this.callback(null, base64digest);
|
495
442
|
}
|
443
|
+
}
|
444
|
+
fileReaderDidError(event) {
|
445
|
+
this.callback(`Error reading ${this.file.name}`);
|
446
|
+
}
|
447
|
+
readNextChunk() {
|
496
448
|
if (this.chunkIndex < this.chunkCount || this.chunkIndex == 0 && this.chunkCount == 0) {
|
497
|
-
|
498
|
-
|
499
|
-
|
449
|
+
const start = this.chunkIndex * this.chunkSize;
|
450
|
+
const end = Math.min(start + this.chunkSize, this.file.size);
|
451
|
+
const bytes = fileSlice.call(this.file, start, end);
|
500
452
|
this.fileReader.readAsArrayBuffer(bytes);
|
501
453
|
this.chunkIndex++;
|
502
454
|
return true;
|
503
455
|
} else {
|
504
456
|
return false;
|
505
457
|
}
|
506
|
-
}
|
507
|
-
|
508
|
-
}();
|
458
|
+
}
|
459
|
+
}
|
509
460
|
|
510
|
-
|
461
|
+
var $;
|
511
462
|
|
512
|
-
|
463
|
+
window.WCC || (window.WCC = {});
|
513
464
|
|
514
|
-
|
465
|
+
$ = window.jQuery;
|
515
466
|
|
516
|
-
|
467
|
+
Dropzone.autoDiscover = false;
|
517
468
|
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
}
|
523
|
-
WCCDropzone.prototype.uploadFile = function(file) {
|
524
|
-
var _this = this;
|
525
|
-
var _a;
|
526
|
-
var xhr = new XMLHttpRequest;
|
469
|
+
window.WCC.Dropzone = class Dropzone extends window.Dropzone {
|
470
|
+
uploadFile(file) {
|
471
|
+
var handleError, headerName, headerValue, headers, progressObj, ref, response, updateProgress, xhr;
|
472
|
+
xhr = new XMLHttpRequest;
|
527
473
|
file.xhr = xhr;
|
528
474
|
xhr.open(file.uploadMethod, file.uploadURL, true);
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
var updateProgress = function(e) {
|
535
|
-
var _a;
|
536
|
-
var progress;
|
537
|
-
if (e) {
|
475
|
+
response = null;
|
476
|
+
handleError = () => this._errorProcessing([ file ], response || this.options.dictResponseError.replace("{{statusCode}}", xhr.status), xhr);
|
477
|
+
updateProgress = e => {
|
478
|
+
var allFilesFinished, progress;
|
479
|
+
if (e != null) {
|
538
480
|
progress = 100 * e.loaded / e.total;
|
539
|
-
file.upload =
|
481
|
+
file.upload = {
|
540
482
|
progress: progress,
|
541
483
|
total: e.total,
|
542
484
|
bytesSent: e.loaded
|
543
|
-
}
|
485
|
+
};
|
544
486
|
} else {
|
487
|
+
allFilesFinished = true;
|
545
488
|
progress = 100;
|
546
|
-
|
547
|
-
|
548
|
-
allFilesFinished = true;
|
489
|
+
if (!(file.upload.progress === 100 && file.upload.bytesSent === file.upload.total)) {
|
490
|
+
allFilesFinished = false;
|
549
491
|
}
|
550
492
|
file.upload.progress = progress;
|
551
|
-
file.upload.bytesSent =
|
493
|
+
file.upload.bytesSent = file.upload.total;
|
552
494
|
if (allFilesFinished) {
|
553
495
|
return;
|
554
496
|
}
|
555
497
|
}
|
556
|
-
|
498
|
+
return this.emit("uploadprogress", file, progress, file.upload.bytesSent);
|
557
499
|
};
|
558
|
-
xhr.onload =
|
559
|
-
|
500
|
+
xhr.onload = e => {
|
501
|
+
var ref;
|
502
|
+
if (file.status === WCC.Dropzone.CANCELED) {
|
560
503
|
return;
|
561
504
|
}
|
562
|
-
if (xhr.readyState
|
505
|
+
if (xhr.readyState !== 4) {
|
563
506
|
return;
|
564
507
|
}
|
565
508
|
response = xhr.responseText;
|
566
|
-
if (xhr.getResponseHeader("content-type") && xhr.getResponseHeader("content-type").indexOf("application/json")
|
509
|
+
if (xhr.getResponseHeader("content-type") && ~xhr.getResponseHeader("content-type").indexOf("application/json")) {
|
567
510
|
try {
|
568
511
|
response = JSON.parse(response);
|
569
|
-
} catch (
|
512
|
+
} catch (error1) {
|
513
|
+
e = error1;
|
570
514
|
response = "Invalid JSON response from server.";
|
571
515
|
}
|
572
516
|
}
|
573
517
|
updateProgress();
|
574
|
-
if (
|
575
|
-
|
518
|
+
if (!(200 <= (ref = xhr.status) && ref < 300)) {
|
519
|
+
return handleError();
|
520
|
+
} else {
|
521
|
+
return this._finished([ file ], response, e);
|
576
522
|
}
|
577
523
|
};
|
578
|
-
xhr.onerror =
|
579
|
-
if (file.status
|
524
|
+
xhr.onerror = () => {
|
525
|
+
if (file.status === WCC.Dropzone.CANCELED) {
|
580
526
|
return;
|
581
527
|
}
|
582
|
-
handleError();
|
528
|
+
return handleError();
|
583
529
|
};
|
584
|
-
|
530
|
+
progressObj = (ref = xhr.upload) != null ? ref : xhr;
|
585
531
|
progressObj.onprogress = updateProgress;
|
586
|
-
|
532
|
+
headers = {
|
587
533
|
Accept: "application/json",
|
588
534
|
"Cache-Control": "no-cache",
|
589
535
|
"X-Requested-With": "XMLHttpRequest"
|
590
536
|
};
|
591
537
|
if (this.options.headers) {
|
592
|
-
|
538
|
+
$.extend(headers, this.options.headers);
|
593
539
|
}
|
594
540
|
if (file.uploadHeaders) {
|
595
|
-
|
541
|
+
$.extend(headers, file.uploadHeaders);
|
596
542
|
}
|
597
|
-
for (
|
598
|
-
|
543
|
+
for (headerName in headers) {
|
544
|
+
headerValue = headers[headerName];
|
599
545
|
xhr.setRequestHeader(headerName, headerValue);
|
600
546
|
}
|
601
547
|
this.emit("sending", file, xhr);
|
602
|
-
xhr.send(file);
|
603
|
-
}
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
548
|
+
return xhr.send(file);
|
549
|
+
}
|
550
|
+
uploadFiles(files) {
|
551
|
+
var file, l, len, results;
|
552
|
+
results = [];
|
553
|
+
for (l = 0, len = files.length; l < len; l++) {
|
554
|
+
file = files[l];
|
555
|
+
results.push(this.uploadFile(file));
|
608
556
|
}
|
609
|
-
|
610
|
-
|
611
|
-
}
|
557
|
+
return results;
|
558
|
+
}
|
559
|
+
};
|
612
560
|
|
613
|
-
|
561
|
+
WCC.Dropzone.uploadPendingWarning = "File uploads have not yet completed. If you submit the form now they will not be saved. Are you sure you want to continue?";
|
614
562
|
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
563
|
+
WCC.Dropzone.prototype.defaultOptions.url = "UNUSED";
|
564
|
+
|
565
|
+
WCC.Dropzone.prototype.defaultOptions.dictDefaultMessage = "Drop files or click to upload.";
|
566
|
+
|
567
|
+
WCC.Dropzone.prototype.defaultOptions.accept = function(file, done) {
|
568
|
+
var dz, postData, tessaParams;
|
569
|
+
dz = $(file._removeLink).closest(".tessa-upload").first();
|
570
|
+
tessaParams = dz.data("tessa-params") || {};
|
571
|
+
postData = {
|
572
|
+
name: file.name,
|
573
|
+
size: file.size,
|
574
|
+
mime_type: file.type
|
575
|
+
};
|
576
|
+
postData = $.extend(postData, tessaParams);
|
577
|
+
return FileChecksum.create(file, (function(error, checksum) {
|
578
|
+
if (error) {
|
579
|
+
return done(error);
|
630
580
|
}
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
|
644
|
-
|
645
|
-
|
646
|
-
dropzone.on("success", (function(file) {
|
647
|
-
$('input[name="'.concat(inputName, '"]')).val(file.signedID);
|
648
|
-
}));
|
649
|
-
dropzone.on("removedfile", (function(file) {
|
650
|
-
$item.find('input[name="'.concat(inputName, '"]')).val("");
|
651
|
-
}));
|
581
|
+
postData["checksum"] = checksum;
|
582
|
+
return $.ajax("/tessa/uploads", {
|
583
|
+
type: "POST",
|
584
|
+
data: postData,
|
585
|
+
success: function(response) {
|
586
|
+
file.uploadURL = response.upload_url;
|
587
|
+
file.uploadMethod = response.upload_method;
|
588
|
+
file.uploadHeaders = response.upload_headers;
|
589
|
+
file.assetID = response.asset_id;
|
590
|
+
return done();
|
591
|
+
},
|
592
|
+
error: function(response) {
|
593
|
+
return done("Failed to initiate the upload process!");
|
594
|
+
}
|
595
|
+
});
|
652
596
|
}));
|
653
|
-
|
654
|
-
|
655
|
-
|
656
|
-
|
597
|
+
};
|
598
|
+
|
599
|
+
window.WCC.tessaInit = function(sel) {
|
600
|
+
sel = sel || "form:has(.tessa-upload)";
|
601
|
+
$(sel).each((function(i, form) {
|
602
|
+
var $form;
|
603
|
+
$form = $(form);
|
604
|
+
return $form.bind("submit", (function(event) {
|
605
|
+
var safeToSubmit;
|
606
|
+
safeToSubmit = true;
|
657
607
|
$form.find(".tessa-upload").each((function(j, dropzoneElement) {
|
658
|
-
dropzoneElement.dropzone.files.
|
659
|
-
if (file.status && file.status
|
660
|
-
safeToSubmit = false;
|
608
|
+
return $(dropzoneElement.dropzone.files).each((function(k, file) {
|
609
|
+
if (file.status != null && file.status !== WCC.Dropzone.SUCCESS) {
|
610
|
+
return safeToSubmit = false;
|
661
611
|
}
|
662
612
|
}));
|
663
613
|
}));
|
664
|
-
if (!safeToSubmit && !confirm(uploadPendingWarning)) {
|
614
|
+
if (!safeToSubmit && !confirm(WCC.Dropzone.uploadPendingWarning)) {
|
665
615
|
return false;
|
666
616
|
}
|
667
617
|
}));
|
668
618
|
}));
|
669
|
-
|
670
|
-
|
671
|
-
|
672
|
-
|
673
|
-
|
674
|
-
|
675
|
-
blob: {
|
676
|
-
filename: file.name,
|
677
|
-
byte_size: file.size,
|
678
|
-
content_type: file.type,
|
679
|
-
checksum: ""
|
680
|
-
}
|
619
|
+
return $(".tessa-upload", sel).each((function(i, item) {
|
620
|
+
var $item, args, dropzone, inputPrefix, updateAction;
|
621
|
+
$item = $(item);
|
622
|
+
args = {
|
623
|
+
maxFiles: 1,
|
624
|
+
addRemoveLinks: true
|
681
625
|
};
|
682
|
-
|
683
|
-
|
684
|
-
|
626
|
+
$.extend(args, $item.data("dropzone-options"));
|
627
|
+
if ($item.hasClass("multiple")) {
|
628
|
+
args.maxFiles = null;
|
629
|
+
}
|
630
|
+
inputPrefix = $item.data("asset-field-prefix");
|
631
|
+
dropzone = new WCC.Dropzone(item, args);
|
632
|
+
$item.find('input[type="hidden"]').each((function(j, input) {
|
633
|
+
var $input, mockFile;
|
634
|
+
$input = $(input);
|
635
|
+
mockFile = $input.data("meta");
|
636
|
+
mockFile.accepted = true;
|
637
|
+
dropzone.options.addedfile.call(dropzone, mockFile);
|
638
|
+
dropzone.options.thumbnail.call(dropzone, mockFile, mockFile.url);
|
639
|
+
dropzone.emit("complete", mockFile);
|
640
|
+
return dropzone.files.push(mockFile);
|
641
|
+
}));
|
642
|
+
updateAction = function(file) {
|
643
|
+
var actionInput, inputID;
|
644
|
+
if (file.assetID == null) {
|
645
|
+
return;
|
685
646
|
}
|
686
|
-
|
687
|
-
|
647
|
+
inputID = `#tessa_asset_action_${file.assetID}`;
|
648
|
+
actionInput = $(inputID);
|
649
|
+
if (!actionInput.length) {
|
650
|
+
actionInput = $('<input type="hidden">').attr({
|
651
|
+
id: inputID,
|
652
|
+
name: `${inputPrefix}[${file.assetID}][action]`
|
653
|
+
}).appendTo(item);
|
688
654
|
}
|
689
|
-
|
690
|
-
|
691
|
-
|
692
|
-
|
693
|
-
|
694
|
-
file.uploadURL = response.direct_upload.url;
|
695
|
-
file.uploadMethod = "PUT";
|
696
|
-
file.uploadHeaders = response.direct_upload.headers;
|
697
|
-
file.signedID = response.signed_id;
|
698
|
-
done();
|
699
|
-
},
|
700
|
-
error: function(response) {
|
701
|
-
console.error(response);
|
702
|
-
done("Failed to initiate the upload process!");
|
703
|
-
}
|
704
|
-
});
|
655
|
+
return actionInput.val(file.action);
|
656
|
+
};
|
657
|
+
dropzone.on("success", (function(file) {
|
658
|
+
file.action = "add";
|
659
|
+
return updateAction(file);
|
705
660
|
}));
|
706
|
-
|
707
|
-
|
661
|
+
return dropzone.on("removedfile", (function(file) {
|
662
|
+
file.action = "remove";
|
663
|
+
return updateAction(file);
|
664
|
+
}));
|
665
|
+
}));
|
666
|
+
};
|
708
667
|
|
709
|
-
$(
|
668
|
+
$((function() {
|
669
|
+
return window.WCC.tessaInit();
|
670
|
+
}));
|
@@ -2,34 +2,6 @@
|
|
2
2
|
typeof define === "function" && define.amd ? define(factory) : factory();
|
3
3
|
})((function() {
|
4
4
|
"use strict";
|
5
|
-
var extendStatics = function(d, b) {
|
6
|
-
extendStatics = Object.setPrototypeOf || {
|
7
|
-
__proto__: []
|
8
|
-
} instanceof Array && function(d, b) {
|
9
|
-
d.__proto__ = b;
|
10
|
-
} || function(d, b) {
|
11
|
-
for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p];
|
12
|
-
};
|
13
|
-
return extendStatics(d, b);
|
14
|
-
};
|
15
|
-
function __extends(d, b) {
|
16
|
-
if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
17
|
-
extendStatics(d, b);
|
18
|
-
function __() {
|
19
|
-
this.constructor = d;
|
20
|
-
}
|
21
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __);
|
22
|
-
}
|
23
|
-
var __assign = function() {
|
24
|
-
__assign = Object.assign || function __assign(t) {
|
25
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
26
|
-
s = arguments[i];
|
27
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
28
|
-
}
|
29
|
-
return t;
|
30
|
-
};
|
31
|
-
return __assign.apply(this, arguments);
|
32
|
-
};
|
33
5
|
var sparkMd5 = {
|
34
6
|
exports: {}
|
35
7
|
};
|
@@ -440,260 +412,249 @@
|
|
440
412
|
return SparkMD5;
|
441
413
|
}));
|
442
414
|
})(sparkMd5);
|
443
|
-
var
|
444
|
-
|
445
|
-
|
415
|
+
var SparkMD5 = sparkMd5.exports;
|
416
|
+
const fileSlice = File.prototype.slice || File.prototype.mozSlice || File.prototype.webkitSlice;
|
417
|
+
class FileChecksum {
|
418
|
+
static create(file, callback) {
|
419
|
+
const instance = new FileChecksum(file);
|
420
|
+
instance.create(callback);
|
421
|
+
}
|
422
|
+
constructor(file) {
|
446
423
|
this.file = file;
|
447
424
|
this.chunkSize = 2097152;
|
448
425
|
this.chunkCount = Math.ceil(this.file.size / this.chunkSize);
|
449
426
|
this.chunkIndex = 0;
|
450
427
|
}
|
451
|
-
|
452
|
-
var instance = new FileChecksum(file);
|
453
|
-
instance.create(callback);
|
454
|
-
};
|
455
|
-
FileChecksum.prototype.create = function(callback) {
|
456
|
-
var _this = this;
|
428
|
+
create(callback) {
|
457
429
|
this.callback = callback;
|
458
|
-
this.md5Buffer = new
|
430
|
+
this.md5Buffer = new SparkMD5.ArrayBuffer;
|
459
431
|
this.fileReader = new FileReader;
|
460
|
-
this.fileReader.addEventListener("load", (
|
461
|
-
|
462
|
-
}));
|
463
|
-
this.fileReader.addEventListener("error", (function(event) {
|
464
|
-
return _this.fileReaderDidError(event);
|
465
|
-
}));
|
432
|
+
this.fileReader.addEventListener("load", (event => this.fileReaderDidLoad(event)));
|
433
|
+
this.fileReader.addEventListener("error", (event => this.fileReaderDidError(event)));
|
466
434
|
this.readNextChunk();
|
467
|
-
}
|
468
|
-
|
469
|
-
var _a;
|
470
|
-
if (!this.md5Buffer || !this.fileReader) {
|
471
|
-
throw new Error("FileChecksum: fileReaderDidLoad called before create");
|
472
|
-
}
|
473
|
-
if (!((_a = event.target) === null || _a === void 0 ? void 0 : _a.result)) {
|
474
|
-
return;
|
475
|
-
}
|
435
|
+
}
|
436
|
+
fileReaderDidLoad(event) {
|
476
437
|
this.md5Buffer.append(event.target.result);
|
477
438
|
if (!this.readNextChunk()) {
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
this.callback(null, base64digest);
|
482
|
-
}
|
483
|
-
}
|
484
|
-
};
|
485
|
-
FileChecksum.prototype.fileReaderDidError = function(event) {
|
486
|
-
if (this.callback) {
|
487
|
-
this.callback("Error reading ".concat(this.file.name));
|
488
|
-
}
|
489
|
-
};
|
490
|
-
FileChecksum.prototype.readNextChunk = function() {
|
491
|
-
if (!this.fileReader) {
|
492
|
-
throw new Error("FileChecksum: readNextChunk called before create");
|
439
|
+
const binaryDigest = this.md5Buffer.end(true);
|
440
|
+
const base64digest = btoa(binaryDigest);
|
441
|
+
this.callback(null, base64digest);
|
493
442
|
}
|
443
|
+
}
|
444
|
+
fileReaderDidError(event) {
|
445
|
+
this.callback(`Error reading ${this.file.name}`);
|
446
|
+
}
|
447
|
+
readNextChunk() {
|
494
448
|
if (this.chunkIndex < this.chunkCount || this.chunkIndex == 0 && this.chunkCount == 0) {
|
495
|
-
|
496
|
-
|
497
|
-
|
449
|
+
const start = this.chunkIndex * this.chunkSize;
|
450
|
+
const end = Math.min(start + this.chunkSize, this.file.size);
|
451
|
+
const bytes = fileSlice.call(this.file, start, end);
|
498
452
|
this.fileReader.readAsArrayBuffer(bytes);
|
499
453
|
this.chunkIndex++;
|
500
454
|
return true;
|
501
455
|
} else {
|
502
456
|
return false;
|
503
457
|
}
|
504
|
-
};
|
505
|
-
return FileChecksum;
|
506
|
-
}();
|
507
|
-
window.WCC || (window.WCC = {});
|
508
|
-
var $ = window.jQuery;
|
509
|
-
window.Dropzone.autoDiscover = false;
|
510
|
-
var BaseDropzone = window.Dropzone;
|
511
|
-
var WCCDropzone = function(_super) {
|
512
|
-
__extends(WCCDropzone, _super);
|
513
|
-
function WCCDropzone() {
|
514
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
515
458
|
}
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
459
|
+
}
|
460
|
+
var $;
|
461
|
+
window.WCC || (window.WCC = {});
|
462
|
+
$ = window.jQuery;
|
463
|
+
Dropzone.autoDiscover = false;
|
464
|
+
window.WCC.Dropzone = class Dropzone extends window.Dropzone {
|
465
|
+
uploadFile(file) {
|
466
|
+
var handleError, headerName, headerValue, headers, progressObj, ref, response, updateProgress, xhr;
|
467
|
+
xhr = new XMLHttpRequest;
|
520
468
|
file.xhr = xhr;
|
521
469
|
xhr.open(file.uploadMethod, file.uploadURL, true);
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
var updateProgress = function(e) {
|
528
|
-
var _a;
|
529
|
-
var progress;
|
530
|
-
if (e) {
|
470
|
+
response = null;
|
471
|
+
handleError = () => this._errorProcessing([ file ], response || this.options.dictResponseError.replace("{{statusCode}}", xhr.status), xhr);
|
472
|
+
updateProgress = e => {
|
473
|
+
var allFilesFinished, progress;
|
474
|
+
if (e != null) {
|
531
475
|
progress = 100 * e.loaded / e.total;
|
532
|
-
file.upload =
|
476
|
+
file.upload = {
|
533
477
|
progress: progress,
|
534
478
|
total: e.total,
|
535
479
|
bytesSent: e.loaded
|
536
|
-
}
|
480
|
+
};
|
537
481
|
} else {
|
482
|
+
allFilesFinished = true;
|
538
483
|
progress = 100;
|
539
|
-
|
540
|
-
|
541
|
-
allFilesFinished = true;
|
484
|
+
if (!(file.upload.progress === 100 && file.upload.bytesSent === file.upload.total)) {
|
485
|
+
allFilesFinished = false;
|
542
486
|
}
|
543
487
|
file.upload.progress = progress;
|
544
|
-
file.upload.bytesSent =
|
488
|
+
file.upload.bytesSent = file.upload.total;
|
545
489
|
if (allFilesFinished) {
|
546
490
|
return;
|
547
491
|
}
|
548
492
|
}
|
549
|
-
|
493
|
+
return this.emit("uploadprogress", file, progress, file.upload.bytesSent);
|
550
494
|
};
|
551
|
-
xhr.onload =
|
552
|
-
|
495
|
+
xhr.onload = e => {
|
496
|
+
var ref;
|
497
|
+
if (file.status === WCC.Dropzone.CANCELED) {
|
553
498
|
return;
|
554
499
|
}
|
555
|
-
if (xhr.readyState
|
500
|
+
if (xhr.readyState !== 4) {
|
556
501
|
return;
|
557
502
|
}
|
558
503
|
response = xhr.responseText;
|
559
|
-
if (xhr.getResponseHeader("content-type") && xhr.getResponseHeader("content-type").indexOf("application/json")
|
504
|
+
if (xhr.getResponseHeader("content-type") && ~xhr.getResponseHeader("content-type").indexOf("application/json")) {
|
560
505
|
try {
|
561
506
|
response = JSON.parse(response);
|
562
|
-
} catch (
|
507
|
+
} catch (error1) {
|
508
|
+
e = error1;
|
563
509
|
response = "Invalid JSON response from server.";
|
564
510
|
}
|
565
511
|
}
|
566
512
|
updateProgress();
|
567
|
-
if (
|
568
|
-
|
513
|
+
if (!(200 <= (ref = xhr.status) && ref < 300)) {
|
514
|
+
return handleError();
|
515
|
+
} else {
|
516
|
+
return this._finished([ file ], response, e);
|
569
517
|
}
|
570
518
|
};
|
571
|
-
xhr.onerror =
|
572
|
-
if (file.status
|
519
|
+
xhr.onerror = () => {
|
520
|
+
if (file.status === WCC.Dropzone.CANCELED) {
|
573
521
|
return;
|
574
522
|
}
|
575
|
-
handleError();
|
523
|
+
return handleError();
|
576
524
|
};
|
577
|
-
|
525
|
+
progressObj = (ref = xhr.upload) != null ? ref : xhr;
|
578
526
|
progressObj.onprogress = updateProgress;
|
579
|
-
|
527
|
+
headers = {
|
580
528
|
Accept: "application/json",
|
581
529
|
"Cache-Control": "no-cache",
|
582
530
|
"X-Requested-With": "XMLHttpRequest"
|
583
531
|
};
|
584
532
|
if (this.options.headers) {
|
585
|
-
|
533
|
+
$.extend(headers, this.options.headers);
|
586
534
|
}
|
587
535
|
if (file.uploadHeaders) {
|
588
|
-
|
536
|
+
$.extend(headers, file.uploadHeaders);
|
589
537
|
}
|
590
|
-
for (
|
591
|
-
|
538
|
+
for (headerName in headers) {
|
539
|
+
headerValue = headers[headerName];
|
592
540
|
xhr.setRequestHeader(headerName, headerValue);
|
593
541
|
}
|
594
542
|
this.emit("sending", file, xhr);
|
595
|
-
xhr.send(file);
|
596
|
-
}
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
543
|
+
return xhr.send(file);
|
544
|
+
}
|
545
|
+
uploadFiles(files) {
|
546
|
+
var file, l, len, results;
|
547
|
+
results = [];
|
548
|
+
for (l = 0, len = files.length; l < len; l++) {
|
549
|
+
file = files[l];
|
550
|
+
results.push(this.uploadFile(file));
|
601
551
|
}
|
552
|
+
return results;
|
553
|
+
}
|
554
|
+
};
|
555
|
+
WCC.Dropzone.uploadPendingWarning = "File uploads have not yet completed. If you submit the form now they will not be saved. Are you sure you want to continue?";
|
556
|
+
WCC.Dropzone.prototype.defaultOptions.url = "UNUSED";
|
557
|
+
WCC.Dropzone.prototype.defaultOptions.dictDefaultMessage = "Drop files or click to upload.";
|
558
|
+
WCC.Dropzone.prototype.defaultOptions.accept = function(file, done) {
|
559
|
+
var dz, postData, tessaParams;
|
560
|
+
dz = $(file._removeLink).closest(".tessa-upload").first();
|
561
|
+
tessaParams = dz.data("tessa-params") || {};
|
562
|
+
postData = {
|
563
|
+
name: file.name,
|
564
|
+
size: file.size,
|
565
|
+
mime_type: file.type
|
602
566
|
};
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
$(".tessa-upload").each((function(i, item) {
|
608
|
-
var $item = $(item);
|
609
|
-
var directUploadURL = $item.data("direct-upload-url") || "/rails/active_storage/direct_uploads";
|
610
|
-
var options = __assign({
|
611
|
-
maxFiles: 1,
|
612
|
-
addRemoveLinks: true,
|
613
|
-
url: "UNUSED",
|
614
|
-
dictDefaultMessage: "Drop files or click to upload.",
|
615
|
-
accept: createAcceptFn({
|
616
|
-
directUploadURL: directUploadURL
|
617
|
-
})
|
618
|
-
}, $item.data("dropzone-options"));
|
619
|
-
if ($item.hasClass("multiple")) {
|
620
|
-
options.maxFiles = undefined;
|
567
|
+
postData = $.extend(postData, tessaParams);
|
568
|
+
return FileChecksum.create(file, (function(error, checksum) {
|
569
|
+
if (error) {
|
570
|
+
return done(error);
|
621
571
|
}
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
dropzone.on("success", (function(file) {
|
638
|
-
$('input[name="'.concat(inputName, '"]')).val(file.signedID);
|
639
|
-
}));
|
640
|
-
dropzone.on("removedfile", (function(file) {
|
641
|
-
$item.find('input[name="'.concat(inputName, '"]')).val("");
|
642
|
-
}));
|
572
|
+
postData["checksum"] = checksum;
|
573
|
+
return $.ajax("/tessa/uploads", {
|
574
|
+
type: "POST",
|
575
|
+
data: postData,
|
576
|
+
success: function(response) {
|
577
|
+
file.uploadURL = response.upload_url;
|
578
|
+
file.uploadMethod = response.upload_method;
|
579
|
+
file.uploadHeaders = response.upload_headers;
|
580
|
+
file.assetID = response.asset_id;
|
581
|
+
return done();
|
582
|
+
},
|
583
|
+
error: function(response) {
|
584
|
+
return done("Failed to initiate the upload process!");
|
585
|
+
}
|
586
|
+
});
|
643
587
|
}));
|
644
|
-
|
645
|
-
|
646
|
-
|
647
|
-
|
588
|
+
};
|
589
|
+
window.WCC.tessaInit = function(sel) {
|
590
|
+
sel = sel || "form:has(.tessa-upload)";
|
591
|
+
$(sel).each((function(i, form) {
|
592
|
+
var $form;
|
593
|
+
$form = $(form);
|
594
|
+
return $form.bind("submit", (function(event) {
|
595
|
+
var safeToSubmit;
|
596
|
+
safeToSubmit = true;
|
648
597
|
$form.find(".tessa-upload").each((function(j, dropzoneElement) {
|
649
|
-
dropzoneElement.dropzone.files.
|
650
|
-
if (file.status && file.status
|
651
|
-
safeToSubmit = false;
|
598
|
+
return $(dropzoneElement.dropzone.files).each((function(k, file) {
|
599
|
+
if (file.status != null && file.status !== WCC.Dropzone.SUCCESS) {
|
600
|
+
return safeToSubmit = false;
|
652
601
|
}
|
653
602
|
}));
|
654
603
|
}));
|
655
|
-
if (!safeToSubmit && !confirm(uploadPendingWarning)) {
|
604
|
+
if (!safeToSubmit && !confirm(WCC.Dropzone.uploadPendingWarning)) {
|
656
605
|
return false;
|
657
606
|
}
|
658
607
|
}));
|
659
608
|
}));
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
|
664
|
-
|
665
|
-
|
666
|
-
filename: file.name,
|
667
|
-
byte_size: file.size,
|
668
|
-
content_type: file.type,
|
669
|
-
checksum: ""
|
670
|
-
}
|
609
|
+
return $(".tessa-upload", sel).each((function(i, item) {
|
610
|
+
var $item, args, dropzone, inputPrefix, updateAction;
|
611
|
+
$item = $(item);
|
612
|
+
args = {
|
613
|
+
maxFiles: 1,
|
614
|
+
addRemoveLinks: true
|
671
615
|
};
|
672
|
-
|
673
|
-
|
674
|
-
|
616
|
+
$.extend(args, $item.data("dropzone-options"));
|
617
|
+
if ($item.hasClass("multiple")) {
|
618
|
+
args.maxFiles = null;
|
619
|
+
}
|
620
|
+
inputPrefix = $item.data("asset-field-prefix");
|
621
|
+
dropzone = new WCC.Dropzone(item, args);
|
622
|
+
$item.find('input[type="hidden"]').each((function(j, input) {
|
623
|
+
var $input, mockFile;
|
624
|
+
$input = $(input);
|
625
|
+
mockFile = $input.data("meta");
|
626
|
+
mockFile.accepted = true;
|
627
|
+
dropzone.options.addedfile.call(dropzone, mockFile);
|
628
|
+
dropzone.options.thumbnail.call(dropzone, mockFile, mockFile.url);
|
629
|
+
dropzone.emit("complete", mockFile);
|
630
|
+
return dropzone.files.push(mockFile);
|
631
|
+
}));
|
632
|
+
updateAction = function(file) {
|
633
|
+
var actionInput, inputID;
|
634
|
+
if (file.assetID == null) {
|
635
|
+
return;
|
675
636
|
}
|
676
|
-
|
677
|
-
|
637
|
+
inputID = `#tessa_asset_action_${file.assetID}`;
|
638
|
+
actionInput = $(inputID);
|
639
|
+
if (!actionInput.length) {
|
640
|
+
actionInput = $('<input type="hidden">').attr({
|
641
|
+
id: inputID,
|
642
|
+
name: `${inputPrefix}[${file.assetID}][action]`
|
643
|
+
}).appendTo(item);
|
678
644
|
}
|
679
|
-
|
680
|
-
|
681
|
-
|
682
|
-
|
683
|
-
|
684
|
-
file.uploadURL = response.direct_upload.url;
|
685
|
-
file.uploadMethod = "PUT";
|
686
|
-
file.uploadHeaders = response.direct_upload.headers;
|
687
|
-
file.signedID = response.signed_id;
|
688
|
-
done();
|
689
|
-
},
|
690
|
-
error: function(response) {
|
691
|
-
console.error(response);
|
692
|
-
done("Failed to initiate the upload process!");
|
693
|
-
}
|
694
|
-
});
|
645
|
+
return actionInput.val(file.action);
|
646
|
+
};
|
647
|
+
dropzone.on("success", (function(file) {
|
648
|
+
file.action = "add";
|
649
|
+
return updateAction(file);
|
695
650
|
}));
|
696
|
-
|
697
|
-
|
698
|
-
|
651
|
+
return dropzone.on("removedfile", (function(file) {
|
652
|
+
file.action = "remove";
|
653
|
+
return updateAction(file);
|
654
|
+
}));
|
655
|
+
}));
|
656
|
+
};
|
657
|
+
$((function() {
|
658
|
+
return window.WCC.tessaInit();
|
659
|
+
}));
|
699
660
|
}));
|
@@ -25,11 +25,11 @@ module Tessa
|
|
25
25
|
|
26
26
|
if asset&.key.present?
|
27
27
|
return @builder.hidden_field("#{attribute_name}", {
|
28
|
-
value: asset.
|
28
|
+
value: asset.signed_id,
|
29
29
|
data: {
|
30
30
|
meta: meta_for_blob(asset).merge({
|
31
31
|
# this allows us to find the hidden HTML input to remove it if we remove the asset
|
32
|
-
"signedID" => asset.
|
32
|
+
"signedID" => asset.signed_id,
|
33
33
|
})
|
34
34
|
}
|
35
35
|
})
|
data/lib/tessa/version.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tessa
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 6.0.
|
4
|
+
version: 6.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin Powell
|
8
8
|
- Travis Petticrew
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2023-08-
|
12
|
+
date: 2023-08-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -218,7 +218,7 @@ homepage: https://github.com/watermarkchurch/tessa-client
|
|
218
218
|
licenses:
|
219
219
|
- MIT
|
220
220
|
metadata: {}
|
221
|
-
post_install_message:
|
221
|
+
post_install_message:
|
222
222
|
rdoc_options: []
|
223
223
|
require_paths:
|
224
224
|
- lib
|
@@ -234,7 +234,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
234
234
|
version: '0'
|
235
235
|
requirements: []
|
236
236
|
rubygems_version: 3.0.3.1
|
237
|
-
signing_key:
|
237
|
+
signing_key:
|
238
238
|
specification_version: 4
|
239
239
|
summary: Manage your assets.
|
240
240
|
test_files:
|