Skip to content

Commit

Permalink
Merge pull request #68 from learningworks/issue-67_dnduploadbreaks
Browse files Browse the repository at this point in the history
Add check for -1 maxbytes value in JS.
  • Loading branch information
mrblippy authored Nov 4, 2019
2 parents 699c2e9 + 3f276eb commit 4f7e2ef
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
11 changes: 8 additions & 3 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
));
Expand Down
14 changes: 7 additions & 7 deletions yui/dndupload/dndupload.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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
};
Expand Down

0 comments on commit 4f7e2ef

Please sign in to comment.