Skip to content
Snippets Groups Projects
Unverified Commit 803c8ddf authored by Roeland Jago Douma's avatar Roeland Jago Douma Committed by GitHub
Browse files

Merge pull request #16984 from nextcloud/bugfix/noid/warn-during-upload-drop

Warn user before closing when uploading a file on a upload only link
parents 1a7310f4 f12a99e5
No related branches found
No related tags found
No related merge requests found
...@@ -13,11 +13,14 @@ ...@@ -13,11 +13,14 @@
var Drop = { var Drop = {
/** @type {Function} **/ /** @type {Function} **/
_template: undefined, _template: undefined,
/** @type {bool} */
_uploading: false,
addFileToUpload: function(e, data) { addFileToUpload: function(e, data) {
var errors = []; var errors = [];
var output = this.template(); var output = this.template();
var filesClient = new OC.Files.Client({ var filesClient = new OC.Files.Client({
host: OC.getHost(), host: OC.getHost(),
port: OC.getPort(), port: OC.getPort(),
...@@ -27,7 +30,7 @@ ...@@ -27,7 +30,7 @@
root: OC.getRootPath() + '/public.php/webdav', root: OC.getRootPath() + '/public.php/webdav',
useHTTPS: OC.getProtocol() === 'https' useHTTPS: OC.getProtocol() === 'https'
}); });
// We only process one file at a time 🤷‍♀️ // We only process one file at a time 🤷‍♀️
var name = data.files[0].name; var name = data.files[0].name;
// removing unwanted characters // removing unwanted characters
...@@ -43,13 +46,13 @@ ...@@ -43,13 +46,13 @@
} }
var base = OC.getProtocol() + '://' + OC.getHost(); var base = OC.getProtocol() + '://' + OC.getHost();
data.url = base + OC.getRootPath() + '/public.php/webdav/' + encodeURI(name); data.url = base + OC.getRootPath() + '/public.php/webdav/' + encodeURI(name);
data.multipart = false; data.multipart = false;
if (!data.headers) { if (!data.headers) {
data.headers = {}; data.headers = {};
} }
var userName = filesClient.getUserName(); var userName = filesClient.getUserName();
var password = filesClient.getPassword(); var password = filesClient.getPassword();
if (userName) { if (userName) {
...@@ -57,32 +60,39 @@ ...@@ -57,32 +60,39 @@
data.headers['Authorization'] = data.headers['Authorization'] =
'Basic ' + btoa(userName + ':' + (password || '')); 'Basic ' + btoa(userName + ':' + (password || ''));
} }
$('#drop-upload-done-indicator').addClass('hidden'); $('#drop-upload-done-indicator').addClass('hidden');
$('#drop-upload-progress-indicator').removeClass('hidden'); $('#drop-upload-progress-indicator').removeClass('hidden');
$('#drop-uploaded-files').append(output({isUploading: true, name: data.files[0].name})); $('#drop-uploaded-files').append(output({isUploading: true, name: data.files[0].name}));
$('[data-toggle="tooltip"]').tooltip(); $('[data-toggle="tooltip"]').tooltip();
data.submit(); data.submit();
return true; return true;
}, },
updateFileItem: function (fileName, fileItem) { updateFileItem: function (fileName, fileItem) {
$('#drop-uploaded-files li[data-name="' + fileName + '"]').replaceWith(fileItem); $('#drop-uploaded-files li[data-name="' + fileName + '"]').replaceWith(fileItem);
$('[data-toggle="tooltip"]').tooltip(); $('[data-toggle="tooltip"]').tooltip();
}, },
initialize: function () { initialize: function () {
$(document).bind('drop dragover', function (e) { $(document).bind('drop dragover', function (e) {
// Prevent the default browser drop action: // Prevent the default browser drop action:
e.preventDefault(); e.preventDefault();
}); });
var output = this.template(); var output = this.template();
var self = this;
$('#public-upload').fileupload({ $('#public-upload').fileupload({
type: 'PUT', type: 'PUT',
dropZone: $('#public-upload'), dropZone: $('#public-upload'),
sequentialUploads: true, sequentialUploads: true,
start: function(e) {
self._uploading = true;
},
stop: function(e) {
self._uploading = false;
},
add: function(e, data) { add: function(e, data) {
Drop.addFileToUpload(e, data); Drop.addFileToUpload(e, data);
//we return true to keep trying to upload next file even //we return true to keep trying to upload next file even
...@@ -120,6 +130,9 @@ ...@@ -120,6 +130,9 @@
e.preventDefault(); e.preventDefault();
$('#public-upload #emptycontent input').focus().trigger('click'); $('#public-upload #emptycontent input').focus().trigger('click');
}); });
window.onbeforeunload = function() {
return self.confirmBeforeUnload();
}
}, },
/** /**
...@@ -128,7 +141,13 @@ ...@@ -128,7 +141,13 @@
*/ */
template: function () { template: function () {
return OCA.Sharing.Templates['files_drop']; return OCA.Sharing.Templates['files_drop'];
} },
confirmBeforeUnload: function() {
if (this._uploading) {
return t('files', 'This will stop your current uploads.')
}
},
}; };
OCA.FilesSharingDrop = Drop; OCA.FilesSharingDrop = Drop;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment