Permalink
Browse files

Merge branch 'MDL-60427_dnd_folder_improved' of git://github.com/davo…

…smith/moodle
  • Loading branch information...
dmonllao committed Jan 8, 2018
2 parents cba780d + 4e737cf commit 1b9fcbf7a723094bf11f3d461da2cd162909d1c3
Showing with 25 additions and 6 deletions.
  1. +23 −6 course/dndupload.js
  2. +1 −0 course/dnduploadlib.php
  3. +1 −0 lang/en/moodle.php
@@ -410,12 +410,12 @@ M.course_dndupload = {
* @return false to prevent the event from continuing to be processed
*/
drop: function(e) {
this.hide_preview_element();
if (!(type = this.check_drag(e))) {
return false;
}
this.hide_preview_element();
// Work out the number of the section we are on (from its id)
var section = this.get_section(e.currentTarget);
var sectionnumber = this.get_section_number(section);
@@ -792,16 +792,33 @@ M.course_dndupload = {
// Prepare the data to send
var formData = new FormData();
formData.append('repo_upload_file', file);
try {
formData.append('repo_upload_file', file);
} catch (e) {
// Edge throws an error at this point if we try to upload a folder.
resel.parent.removeChild(resel.li);
new M.core.alert({message: M.util.get_string('filereaderror', 'moodle', file.name)});
return;
}
formData.append('sesskey', M.cfg.sesskey);
formData.append('course', this.courseid);
formData.append('section', sectionnumber);
formData.append('module', module);
formData.append('type', 'Files');
// Send the AJAX call
xhr.open("POST", this.url, true);
xhr.send(formData);
// Try reading the file to check it is not a folder, before sending it to the server.
var reader = new FileReader();
reader.onload = function() {
// File was read OK - send it to the server.
xhr.open("POST", self.url, true);
xhr.send(formData);
};
reader.onerror = function() {
// Unable to read the file (it is probably a folder) - display an error message.
resel.parent.removeChild(resel.li);
new M.core.alert({message: M.util.get_string('filereaderror', 'moodle', file.name)});
};
reader.readAsText(file.slice(0, 5)); // Try reading the first few bytes of the file.
},
/**
@@ -64,6 +64,7 @@ function dndupload_add_to_course($course, $modnames) {
array('namedfiletoolarge', 'moodle'),
array('actionchoice', 'moodle'),
array('servererror', 'moodle'),
array('filereaderror', 'moodle'),
array('upload', 'moodle'),
array('cancel', 'moodle')
),
@@ -799,6 +799,7 @@
$string['file'] = 'File';
$string['fileexists'] = 'There is already a file called {$a}';
$string['filemissing'] = '{$a} is missing';
$string['filereaderror'] = 'Unable to read the file \'{$a}\' - please check this really is a file and not a folder';
$string['files'] = 'Files';
$string['filesanduploads'] = 'Files and uploads';
$string['filesfolders'] = 'Files/folders';

0 comments on commit 1b9fcbf

Please sign in to comment.