2020-03-30 15:34:56 +02:00
|
|
|
import AutoUploadsControllers from './auto-uploads-controllers.js';
|
|
|
|
import { delegate } from '@utils';
|
|
|
|
|
|
|
|
// Create a controller responsible for managing several concurrent uploads.
|
|
|
|
const autoUploadsControllers = new AutoUploadsControllers();
|
|
|
|
|
|
|
|
function startUpload(input) {
|
2020-04-30 15:42:29 +02:00
|
|
|
Array.from(input.files).forEach((file) => {
|
2020-03-30 15:34:56 +02:00
|
|
|
autoUploadsControllers.upload(input, file);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
const fileInputSelector = `input[type=file][data-direct-upload-url][data-auto-attach-url]:not([disabled])`;
|
2020-04-30 15:42:29 +02:00
|
|
|
delegate('change', fileInputSelector, (event) => {
|
2020-03-30 15:34:56 +02:00
|
|
|
startUpload(event.target);
|
|
|
|
});
|
|
|
|
|
|
|
|
const retryButtonSelector = `button.attachment-error-retry`;
|
2020-04-30 15:42:29 +02:00
|
|
|
delegate('click', retryButtonSelector, function () {
|
2020-04-08 12:41:02 +02:00
|
|
|
const inputSelector = this.dataset.inputTarget;
|
2020-03-30 15:34:56 +02:00
|
|
|
const input = document.querySelector(inputSelector);
|
|
|
|
startUpload(input);
|
|
|
|
});
|