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}
});
// 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
// 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;
},
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 {
* 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 {
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');
}
}