From 3f276ebc6296a28ca4ecd26a4f6b985cbb0d9e7b Mon Sep 17 00:00:00 2001 From: Troy Williams Date: Fri, 1 Nov 2019 14:41:03 +1300 Subject: [PATCH] Add check for -1 maxbytes value in JS. --- lib.php | 11 ++++++++--- yui/dndupload/dndupload.js | 14 +++++++------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/lib.php b/lib.php index a211df0..98f8643 100644 --- a/lib.php +++ b/lib.php @@ -400,9 +400,14 @@ function equella_dndupload_register() { */ if (isset($CFG->equella_intercept_files) && (int)$CFG->equella_intercept_files == EQUELLA_CONFIG_INTERCEPT_META) { function equella_dndupload_register() { - global $PAGE; - $PAGE->requires->yui_module('moodle-mod_equella-dndupload', 'M.mod_equella.dndupload.init'); - //$PAGE->requires->strings_for_js(array('dndupload_resource', 'dndupload_equella', 'copyright', 'description', 'keyword'), 'mod_equella'); + global $PAGE, $CFG, $COURSE; + $config = [ + [ + 'courseid' => $COURSE->id, + 'maxbytes' => get_user_max_upload_file_size($PAGE->context, $CFG->maxbytes, $COURSE->maxbytes) + ] + ]; + $PAGE->requires->yui_module('moodle-mod_equella-dndupload', 'M.mod_equella.dndupload.init', $config); return array('files' => array( array('extension' => '*', 'message' => get_string('dnduploadresourcemetadata', 'mod_equella')) )); diff --git a/yui/dndupload/dndupload.js b/yui/dndupload/dndupload.js index 93bd53b..7889d94 100644 --- a/yui/dndupload/dndupload.js +++ b/yui/dndupload/dndupload.js @@ -9,7 +9,6 @@ YUI.add('moodle-mod_equella-dndupload', function (Y) { hasOverriddenDndUpload: false, initializer: function (config) { var self = this; - // Horribly nasty hack, since nothing in the dndupload chain fires any events we can listen for. // Since the dndupload module isn't there when we initialise, override its add_editing function // when we first see a "drop" on a section. @@ -139,6 +138,12 @@ YUI.add('moodle-mod_equella-dndupload', function (Y) { return; } + // A -1 maxbytes value indicates unlimited. + if (file.size > this.maxbytes && this.maxbytes != -1) { + alert('The file ' + file.name + ' is too large and cannot be uploaded'); + return; + } + if (!module) { return; } @@ -170,11 +175,6 @@ YUI.add('moodle-mod_equella-dndupload', function (Y) { var xhr = new XMLHttpRequest(); var self = this; - if (file.size > this.maxbytes) { - alert("'" + file.name + "' " + M.util.get_string('filetoolarge', 'moodle')); - return; - } - // Add the file to the display var resel = M.course_dndupload.add_resource_element(file.name, section, module); @@ -247,7 +247,7 @@ YUI.add('moodle-mod_equella-dndupload', function (Y) { M.mod_equella = M.mod_equella || {}; M.mod_equella.dndupload = M.mod_equella.dndupload || {}; //M.mod_equella.dndupload.upload_file_with_meta = DndUpload.prototype.upload_file_with_meta; - M.mod_equella.dndupload.init = function (config) { // 'config' contains the parameter values + M.mod_equella.dndupload.init = function (config) { //console.log('I am in the javascript module, Yeah!'); return new DndUpload(config); // 'config' contains the parameter values };