From 4069ae323d3122b046c9c020fa48294052aa2b27 Mon Sep 17 00:00:00 2001 From: Davo Smith Date: Sat, 14 Jan 2012 17:17:50 +0000 Subject: [PATCH] MDL-31110 Filemanager drag and drop upload - always hide spinner, even when errors occur --- lang/en/error.php | 1 + lib/form/dndupload.js | 41 +++++++++++++++++++++------------------- lib/form/filemanager.php | 2 +- 3 files changed, 24 insertions(+), 20 deletions(-) diff --git a/lang/en/error.php b/lang/en/error.php index ee10b9bdc71..bd54f12a7de 100644 --- a/lang/en/error.php +++ b/lang/en/error.php @@ -435,6 +435,7 @@ $string['rpcerror'] = 'Ooops! Your MNET communication has failed! Here\'s that e $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.
Wait for your current requests to finish and try again later.'; $string['sessioncookiesdisable'] = 'Incorrect use of require_key_login() - session cookies must be disabled!'; diff --git a/lib/form/dndupload.js b/lib/form/dndupload.js index df0fb1919d7..fae2b87424a 100644 --- a/lib/form/dndupload.js +++ b/lib/form/dndupload.js @@ -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(); } }, @@ -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; } @@ -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')); } } }; diff --git a/lib/form/filemanager.php b/lib/form/filemanager.php index 774a509d7ad..937d8cb8c4a 100644 --- a/lib/form/filemanager.php +++ b/lib/form/filemanager.php @@ -315,7 +315,7 @@ FMHTML; 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);