From a793b1027c6fdf0cade31bf84cf64d378f2727b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Molakvo=C3=A6=20=28skjnldsv=29?= Date: Mon, 5 Nov 2018 09:24:25 +0100 Subject: [PATCH] Ask before cancelling an ongoing upload MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ (skjnldsv) --- apps/files/js/file-upload.js | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/apps/files/js/file-upload.js b/apps/files/js/file-upload.js index 9c1e2df53a095..8d18761acc86b 100644 --- a/apps/files/js/file-upload.js +++ b/apps/files/js/file-upload.js @@ -408,6 +408,13 @@ OC.Uploader.prototype = _.extend({ */ _pendingUploadDoneCount: 0, + /** + * Is it currently uploading? + * + * @type boolean + */ + _uploading: false, + /** * List of directories known to exist. * @@ -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(); } }