Skip to content

Commit

Permalink
MDL-31110 Filemanager drag and drop upload - always hide spinner, eve…
Browse files Browse the repository at this point in the history
…n when errors occur
  • Loading branch information
davosmith committed Jan 19, 2012
1 parent f6b4ec2 commit 4069ae3
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 20 deletions.
1 change: 1 addition & 0 deletions lang/en/error.php
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,7 @@
$string['secretalreadyused'] = 'Change password confirmation link was already used, password was not changed';
$string['sectionnotexist'] = 'This section does not exist';
$string['sendmessage'] = 'Send message';
$string['serverconnection'] = 'Error connecting to the server';
$string['servicedonotexist'] = 'The service does not exist';
$string['sessionwaiterr'] = 'Timed out while waiting for session lock.<br />Wait for your current requests to finish and try again later.';
$string['sessioncookiesdisable'] = 'Incorrect use of require_key_login() - session cookies must be disabled!';
Expand Down
41 changes: 22 additions & 19 deletions lib/form/dndupload.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,6 @@ M.form_dndupload = {
update_filemanager: function() {
if (this.filemanager) {
// update the filemanager that we've uploaded the files
this.hide_progress_spinner();
this.filemanager.filepicker_callback();
}
},
Expand All @@ -335,6 +334,7 @@ M.form_dndupload = {
upload_file: function(file) {
if (file.size > this.maxbytes && this.maxbytes > 0) {
// Check filesize before attempting to upload
this.hide_progress_spinner();
alert(M.util.get_string('uploadformlimit', 'moodle')+"\n'"+file.name+"'");
return false;
}
Expand All @@ -348,26 +348,29 @@ M.form_dndupload = {
var xhr = new XMLHttpRequest();
var self = this;
xhr.onreadystatechange = function() { // Process the server response
if (xhr.readyState == 4 && xhr.status == 200) {
var result = JSON.parse(xhr.responseText);
if (result) {
if (result.error) {
self.hide_progress_spinner();
alert(result.error);
} else if (self.callback) {
// Only update the filepicker if there were no errors
self.hide_progress_spinner();
if (result.event == 'fileexists') {
// Do not worry about this, as we only care about the last
// file uploaded, with the filepicker
result.file = result.newfile.filename;
result.url = result.newfile.url;
if (xhr.readyState == 4) {
self.hide_progress_spinner();
if (xhr.status == 200) {
var result = JSON.parse(xhr.responseText);
if (result) {
if (result.error) {
alert(result.error);
} else if (self.callback) {
// Only update the filepicker if there were no errors
if (result.event == 'fileexists') {
// Do not worry about this, as we only care about the last
// file uploaded, with the filepicker
result.file = result.newfile.filename;
result.url = result.newfile.url;
}
result.client_id = self.clientid;
self.callback(result);
} else {
self.update_filemanager();
}
result.client_id = self.clientid;
self.callback(result);
} else {
self.update_filemanager();
}
} else {
alert(M.util.get_string('serverconnection', 'error'));
}
}
};
Expand Down
2 changes: 1 addition & 1 deletion lib/form/filemanager.php
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ function form_filemanager_render($options) {
array('cannotdeletefile', 'error'), array('confirmdeletefile', 'repository'),
array('nopathselected', 'repository'), array('popupblockeddownload', 'repository'),
array('draftareanofiles', 'repository'), array('path', 'moodle'), array('setmainfile', 'repository'),
array('moving', 'repository'), array('files', 'moodle')
array('moving', 'repository'), array('files', 'moodle'), array('serverconnection', 'error')
)
);
$PAGE->requires->js_module($module);
Expand Down

0 comments on commit 4069ae3

Please sign in to comment.