Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add check for -1 maxbytes value in JS. #68

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Add check for -1 maxbytes value in JS.
  • Loading branch information
troywilliams committed Nov 1, 2019
commit 3f276ebc6296a28ca4ecd26a4f6b985cbb0d9e7b
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