MDL-53577 repository: Added maxbytes error message

Changing the error message that is displayed to users when they
upload a file that is greater than the maximum upload size. Does not
include all upload cases; focuses on those most used by students.
This commit is contained in:
Ben Tindell 2015-05-04 12:29:32 -05:00 committed by Joseph Inhofer
parent fed66ad9e2
commit a2fb838e82
8 changed files with 54 additions and 9 deletions

View file

@ -589,7 +589,11 @@ M.form_dndupload.init = function(Y, options) {
for (i=0; i<files.length; i++) {
if (this.options.maxbytes > 0 && files[i].size > this.options.maxbytes) {
// Check filesize before attempting to upload.
this.print_msg(M.util.get_string('maxbytesforfile', 'moodle', files[i].name), 'error');
var maxbytesdisplay = this.display_size(this.options.maxbytes);
this.print_msg(M.util.get_string('maxbytesfile', 'error', {
file: files[i].name,
size: maxbytesdisplay
}), 'error');
this.uploadqueue = []; // No uploads if one file is too big.
return;
}
@ -606,6 +610,31 @@ M.form_dndupload.init = function(Y, options) {
return true;
},
/**
* Generate the display for file size
* @param int size The size to convert to human readable form
* @return string
*/
display_size: function(size) {
// This is snippet of code (with some changes) is from the display_size function in moodlelib.
var gb = M.util.get_string('sizegb'),
mb = M.util.get_string('sizemb'),
kb = M.util.get_string('sizekb'),
b = M.util.get_string('sizeb');
if (size >= 1073741824) {
size = Math.round(size / 1073741824 * 10) / 10 + gb;
} else if (size >= 1048576) {
size = Math.round(size / 1048576 * 10) / 10 + mb;
} else if (size >= 1024) {
size = Math.round(size / 1024 * 10) / 10 + kb;
} else {
size = parseInt(size, 10) + ' ' + b;
}
return size;
},
/**
* Add a single file to the uploadqueue, whilst checking the maxfiles limit
* @param File file - the file to add