/* * This file is part of the TYPO3 CMS project. * * It is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License, either version 2 * of the License, or any later version. * * For the full copyright and license information, please read the * LICENSE.txt file that was distributed with this source code. * * The TYPO3 project - inspiring people to share! */ /** * Module: TYPO3/CMS/Backend/DragUploader */ import {SeverityEnum} from './Enum/Severity'; import * as $ from 'jquery'; import moment = require('moment'); import NProgress = require('nprogress'); import Modal = require('./Modal'); import Notification = require('./Notification'); import {MessageUtility} from './Utility/MessageUtility'; /** * Possible actions for conflicts w/ existing files */ enum Action { OVERRIDE = 'replace', RENAME = 'rename', SKIP = 'cancel', USE_EXISTING = 'useExisting', } /** * Properties of a file as returned from the AJAX action; essential, this is a serialized instance of * \TYPO3\CMS\Core\Resource\File plus some extra properties (see FileController::flattenResultDataValue()) */ interface UploadedFile { name: string; id: number; uid: number; icon: string; extension: string; permissions: { read: boolean; write: boolean }; size: number; // formatted as ddmmyy date: string; mtime: Date; thumbUrl: string; type: string; } interface InternalFile extends File { lastModified: any; } interface DragUploaderOptions { /** * CSS selector for the element where generated messages are inserted. (required) */ outputSelector: string; /** * Color of the message text. (optional) */ outputColor?: string; } class DragUploaderPlugin { public irreObjectUid: number; public $fileList: JQuery; public fileListColumnCount: number; public filesExtensionsAllowed: string; public fileDenyPattern: RegExp | null; public maxFileSize: number; public $trigger: JQuery; public target: string; /** * Array of files which are asked for being overridden */ private askForOverride: Array<{ original: UploadedFile, uploaded: InternalFile, action: Action }> = []; private percentagePerFile: number = 1; private $body: JQuery; private $element: JQuery; private $dropzone: JQuery; private $dropzoneMask: JQuery; private fileInput: HTMLInputElement; private browserCapabilities: { fileReader: boolean; DnD: boolean; Progress: boolean }; private dropZoneInsertBefore: boolean; private queueLength: number; constructor(element: HTMLElement) { this.$body = $('body'); this.$element = $(element); const hasTrigger = this.$element.data('dropzoneTrigger') !== undefined; this.$trigger = $(this.$element.data('dropzoneTrigger')); this.$dropzone = $('
').addClass('dropzone').hide(); this.irreObjectUid = this.$element.data('fileIrreObject'); const dropZoneEscapedTarget = this.$element.data('dropzoneTarget'); if (this.irreObjectUid && this.$element.nextAll(dropZoneEscapedTarget).length !== 0) { this.dropZoneInsertBefore = true; this.$dropzone.insertBefore(dropZoneEscapedTarget); } else { this.dropZoneInsertBefore = false; this.$dropzone.insertAfter(dropZoneEscapedTarget); } this.$dropzoneMask = $('').addClass('dropzone-mask').appendTo(this.$dropzone); this.fileInput =