From: Joshua Rüsweg Date: Mon, 14 Jan 2019 21:32:58 +0000 (+0100) Subject: Add support `null` for maxFiles X-Git-Tag: 5.2.0_Alpha_1~296^2~38 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=81d33df3b803a1bdd9be8d355c06fc5a8ebe09e8;p=GitHub%2FWoltLab%2FWCF.git Add support `null` for maxFiles See #2825 --- diff --git a/com.woltlab.wcf/templates/uploadFieldComponent.tpl b/com.woltlab.wcf/templates/uploadFieldComponent.tpl index 1045b2878a..5654a1733e 100644 --- a/com.woltlab.wcf/templates/uploadFieldComponent.tpl +++ b/com.woltlab.wcf/templates/uploadFieldComponent.tpl @@ -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} }); diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/File/Upload.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/File/Upload.js index 7bed3ff290..fae2649eac 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/File/Upload.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/File/Upload.js @@ -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 { diff --git a/wcfsetup/install/files/lib/action/AJAXFileUploadAction.class.php b/wcfsetup/install/files/lib/action/AJAXFileUploadAction.class.php index d827cc0ed6..01fe196857 100644 --- a/wcfsetup/install/files/lib/action/AJAXFileUploadAction.class.php +++ b/wcfsetup/install/files/lib/action/AJAXFileUploadAction.class.php @@ -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'); } }