Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Warn user when closing page during multiple file upload
Browse files Browse the repository at this point in the history
This adds a modal dialog when a user is currently uploading source
files and they attempt to close or navigate away from the page.
  • Loading branch information
davidmason committed Jul 30, 2014
1 parent e39be2a commit cddd1bd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
Expand Up @@ -663,6 +663,7 @@
.text('Uploading...');
dropZone.addClass('is-hidden');
options.container.on('hide.zanata.modal', options.confirmCancelUpload);
$(window).on('beforeunload', options.confirmLeavePage);
// TODO change upload progress message
options.updateUploadCountIndicator(options);
filesList.find('.cancel').addClass('is-hidden');
Expand Down
Expand Up @@ -76,6 +76,7 @@ $(function () {
doneButton.removeClass('is-hidden').prop('disabled', false);
cancelButton.addClass('is-hidden').prop('disabled', true);
container.off('hide.zanata.modal', confirmCancelUpload);
$(window).off('beforeunload', confirmLeavePage);
}
});

Expand All @@ -92,14 +93,19 @@ $(function () {
refreshStatistics();
})

function confirmCancelUpload (e) {
function confirmCancelUpload () {
var confirmCancel = confirm('Do you really want to stop uploading files?');
if (confirmCancel) {
container.off('hide.zanata.modal', confirmCancelUpload);
$(window).off('beforeunload', confirmLeavePage);
}
return confirmCancel;
}

function confirmLeavePage () {
return 'Do you really want to interrupt your uploading files by leaving this page?';
}

// prevent default file drop behaviour on the page
$doc.bind('drop dragover', function (e) {
e.preventDefault();
Expand Down Expand Up @@ -140,6 +146,7 @@ $(function () {
url: url,
container: container,
confirmCancelUpload: confirmCancelUpload,
confirmLeavePage: confirmLeavePage,
sequentialUploads: true,
maxFileSize: 200*1024*1024,
maxNumberOfFiles: maxFiles,
Expand Down

0 comments on commit cddd1bd

Please sign in to comment.