Commit 34f4ceeb authored by Dmitrii Metelkin's avatar Dmitrii Metelkin
Browse files

Bug 1605072: add a friendly error message when dropzone fails upload a folder

behatnotneeded

Change-Id: Icaafe3e7f3ee77aaece9f891fda1db40d5a235fe
parent 18579931
......@@ -35,6 +35,7 @@ jQuery(document).ready(function() {
previewsContainer: 'div#fileDropzone',
maxFilesize: (upload_max_filesize / 1048576),
dictFileTooBig: strings.maxuploadsize + ' ' + (upload_max_filesize / 1048576) + 'mb',
dictFileIsFolder: strings.fileisfolder,
maxThumbnailFilesize: 1,
clickable: false,
createImageThumbnails: false,
......
......@@ -99,6 +99,7 @@ $string['files'] = 'files';
$string['Files'] = 'Files';
$string['fileexists'] = 'File exists';
$string['fileexistsoverwritecancel'] = 'A file with that name already exists. You can try a different name or overwrite the existing file.';
$string['fileisfolder'] = '"{{filename}}" is a folder. To upload a folder, please create a zip archive, upload that, then use the decompress option below.';
$string['filelistloaded'] = 'File list loaded';
$string['filemoved'] = 'File moved successfully';
$string['filenamefieldisrequired'] = 'The file field is required.';
......
......@@ -186,6 +186,7 @@ class PluginArtefactFile extends PluginArtefact {
'foldernamerequired',
'foldernotempty',
'maxuploadsize',
'fileisfolder',
'nametoolong',
'namefieldisrequired',
'upload',
......
......@@ -6,4 +6,4 @@ Version: 4.3.0
Modifications:
- none
\ No newline at end of file
- modified accept function to display proper error message if dropped file is folder. More info: https://bugs.launchpad.net/mahara/+bug/1605072
\ No newline at end of file
......@@ -150,6 +150,7 @@
dictRemoveFile: "Remove file",
dictRemoveFileConfirmation: null,
dictMaxFilesExceeded: "You can not upload any more files.",
dictFileIsFolder: "{{filename}} is a folder.",
accept: function(file, done) {
return done();
},
......@@ -963,15 +964,19 @@
};
Dropzone.prototype.accept = function(file, done) {
if (file.size > this.options.maxFilesize * 1024 * 1024) {
return done(this.options.dictFileTooBig.replace("{{filesize}}", Math.round(file.size / 1024 / 10.24) / 100).replace("{{maxFilesize}}", this.options.maxFilesize));
} else if (!Dropzone.isValidFile(file, this.options.acceptedFiles)) {
return done(this.options.dictInvalidFileType);
} else if ((this.options.maxFiles != null) && this.getAcceptedFiles().length >= this.options.maxFiles) {
done(this.options.dictMaxFilesExceeded.replace("{{maxFiles}}", this.options.maxFiles));
return this.emit("maxfilesexceeded", file);
if ((file.size) || (file.type) || (file.fullPath)) {
if (file.size > this.options.maxFilesize * 1024 * 1024) {
return done(this.options.dictFileTooBig.replace("{{filesize}}", Math.round(file.size / 1024 / 10.24) / 100).replace("{{maxFilesize}}", this.options.maxFilesize));
} else if (!Dropzone.isValidFile(file, this.options.acceptedFiles)) {
return done(this.options.dictInvalidFileType);
} else if ((this.options.maxFiles != null) && this.getAcceptedFiles().length >= this.options.maxFiles) {
done(this.options.dictMaxFilesExceeded.replace("{{maxFiles}}", this.options.maxFiles));
return this.emit("maxfilesexceeded", file);
} else {
return this.options.accept.call(this, file, done);
}
} else {
return this.options.accept.call(this, file, done);
return done(this.options.dictFileIsFolder.replace("{{filename}}", file.name));
}
};
......
This diff is collapsed.
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment