Add support `null` for maxFiles
authorJoshua Rüsweg <josh@bastelstu.be>
Mon, 14 Jan 2019 21:32:58 +0000 (22:32 +0100)
committerJoshua Rüsweg <josh@bastelstu.be>
Mon, 14 Jan 2019 21:32:58 +0000 (22:32 +0100)
See #2825

com.woltlab.wcf/templates/uploadFieldComponent.tpl
wcfsetup/install/files/js/WoltLabSuite/Core/Ui/File/Upload.js
wcfsetup/install/files/lib/action/AJAXFileUploadAction.class.php

index 1045b2878adab620e02044bff1bbfce2d1836de0..5654a1733e9d06fe36e105c1d9a5b0c34bac56b4 100644 (file)
@@ -40,7 +40,7 @@
        require(['WoltLabSuite/Core/Ui/File/Upload', 'Language'], function(Upload, Language) {
                new Upload("{$uploadFieldId}UploadButtonDiv", "{$uploadFieldId}uploadFileList", {
                        internalId: '{$uploadField->getInternalId()}',
-                       maxFiles: {$uploadField->getMaxFiles()},
+                       {if $uploadField->getMaxFiles()}maxFiles: {$uploadField->getMaxFiles()},{/if}
                        imagePreview: {if !$uploadField->supportMultipleFiles() && $uploadField->isImageOnly()}true{else}false{/if}
                });
                
index 7bed3ff290ecf6f9832ae71ebed1d09bba69e340..fae2649eac854fcd7125bb827e1f54f304f42f21 100644 (file)
@@ -22,8 +22,6 @@ define(['Core', 'Language', 'Dom/Util', 'WoltLabSuite/Core/Ui/File/Delete', 'Upl
                
                // set default options
                this._options = Core.extend({
-                       // is true if multiple files can be uploaded at once
-                       multiple: options.maxFiles > 1,
                        // name if the upload field
                        name: '__files[]',
                        // is true if every file from a multi-file selection is uploaded in its own request
@@ -31,9 +29,13 @@ define(['Core', 'Language', 'Dom/Util', 'WoltLabSuite/Core/Ui/File/Delete', 'Upl
                        // url for uploading file
                        url: 'index.php?ajax-file-upload/&t=' + SECURITY_TOKEN,
                        // image preview
-                       imagePreview: false
+                       imagePreview: false,
+                       // max files
+                       maxFiles: null
                }, options);
                
+               this._options.multiple = this._options.maxFiles === null || this._options.maxFiles > 1; 
+               
                this._options.url = Core.convertLegacyUrl(this._options.url);
                if (this._options.url.indexOf('index.php') === 0) {
                        this._options.url = WSC_API_URL + this._options.url;
@@ -185,7 +187,7 @@ define(['Core', 'Language', 'Dom/Util', 'WoltLabSuite/Core/Ui/File/Delete', 'Upl
                },
                
                validateUpload: function(files) {
-                       if (files.length + this.countFiles() <= this._options.maxFiles) {
+                       if (this._options.maxFiles === null || files.length + this.countFiles() <= this._options.maxFiles) {
                                return true;
                        }
                        else {
@@ -221,7 +223,7 @@ define(['Core', 'Language', 'Dom/Util', 'WoltLabSuite/Core/Ui/File/Delete', 'Upl
                 * Checks the maximum number of files and enables or disables the upload button.
                 */
                checkMaxFiles: function() {
-                       if (this.countFiles() >= this._options.maxFiles) {
+                       if (this._options.maxFiles !== null && this.countFiles() >= this._options.maxFiles) {
                                elHide(this._button);
                        }
                        else {
index d827cc0ed68a5636ecb6bbdd51e3b4826daee8a5..01fe196857abfc2108b5b0d2e7a7ee5a22424682 100644 (file)
@@ -66,7 +66,7 @@ class AJAXFileUploadAction extends AbstractSecureAction {
                        throw new UserInputException('files', 'failed');
                }
                
-               if (UploadHandler::getInstance()->getFieldForInternalId($this->internalId)->getMaxFiles() < UploadHandler::getInstance()->getFilesCountForInternalId($this->internalId) + count($_FILES['__files']['tmp_name'])) {
+               if (UploadHandler::getInstance()->getFieldForInternalId($this->internalId)->getMaxFiles() !== null && UploadHandler::getInstance()->getFieldForInternalId($this->internalId)->getMaxFiles() < UploadHandler::getInstance()->getFilesCountForInternalId($this->internalId) + count($_FILES['__files']['tmp_name'])) {
                        throw new UserInputException('files', 'reachedRemainingLimit');
                }
        }