mirror of
https://github.com/moodle/moodle.git
synced 2025-01-19 14:27:22 +01:00
Merge branch 'MDL-60427_dnd_folder_improved' of git://github.com/davosmith/moodle
This commit is contained in:
commit
1b9fcbf7a7
@ -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['feedback'] = 'Feedback';
|
||||
$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';
|
||||
|
Loading…
x
Reference in New Issue
Block a user