summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2018-11-05 12:28:32 +0100
committerGitHub <noreply@github.com>2018-11-05 12:28:32 +0100
commit04774eaf68d282fd23ae9579389a5f86186a2154 (patch)
treedf52aea7e05ea726a326670dbce1fb4c78a45fe9
parentcba3883410f958305673f75950c5b6227c571f16 (diff)
parenta793b1027c6fdf0cade31bf84cf64d378f2727b4 (diff)
downloadnextcloud-server-04774eaf68d282fd23ae9579389a5f86186a2154.tar.gz
nextcloud-server-04774eaf68d282fd23ae9579389a5f86186a2154.zip
Merge pull request #12271 from nextcloud/prevent-upload-cancel
Ask before cancelling an ongoing upload
-rw-r--r--apps/files/js/file-upload.js29
1 files changed, 24 insertions, 5 deletions
diff --git a/apps/files/js/file-upload.js b/apps/files/js/file-upload.js
index 9c1e2df53a0..8d18761acc8 100644
--- a/apps/files/js/file-upload.js
+++ b/apps/files/js/file-upload.js
@@ -409,6 +409,13 @@ OC.Uploader.prototype = _.extend({
_pendingUploadDoneCount: 0,
/**
+ * Is it currently uploading?
+ *
+ * @type boolean
+ */
+ _uploading: false,
+
+ /**
* List of directories known to exist.
*
* Key is the fullpath and value is boolean, true meaning that the directory
@@ -544,6 +551,12 @@ OC.Uploader.prototype = _.extend({
});
},
+ confirmBeforeUnload: function() {
+ if (this._uploading) {
+ return t('files', 'This will stop your current uploads.')
+ }
+ },
+
/**
* Show conflict for the given file object
*
@@ -681,8 +694,8 @@ OC.Uploader.prototype = _.extend({
// resubmit upload
this.submitUploads([upload]);
},
- _trace:false, //TODO implement log handler for JS per class?
- log:function(caption, e, data) {
+ _trace: false, //TODO implement log handler for JS per class?
+ log: function(caption, e, data) {
if (this._trace) {
console.log(caption);
console.log(data);
@@ -990,6 +1003,7 @@ OC.Uploader.prototype = _.extend({
self.log('start', e, null);
//hide the tooltip otherwise it covers the progress bar
$('#upload').tooltip('hide');
+ self._uploading = true;
},
fail: function(e, data) {
var upload = self.getUpload(data);
@@ -1016,10 +1030,12 @@ OC.Uploader.prototype = _.extend({
self.cancelUploads();
} else {
// HTTP connection problem or other error
- var message = '';
+ var message = t('files', 'An unknown error has occurred');
if (upload) {
var response = upload.getResponse();
- message = response.message;
+ if (response) {
+ message = response.message;
+ }
}
OC.Notification.show(message || data.errorThrown, {type: 'error'});
}
@@ -1055,6 +1071,7 @@ OC.Uploader.prototype = _.extend({
*/
stop: function(e, data) {
self.log('stop', e, data);
+ self._uploading = false;
}
};
@@ -1263,7 +1280,9 @@ OC.Uploader.prototype = _.extend({
return false;
}
});
-
+ }
+ window.onbeforeunload = function() {
+ return self.confirmBeforeUnload();
}
}