feat: safeguard against mistakenly cancelling uploading.

This commit is contained in:
Terry Geng
2020-05-16 22:24:10 +08:00
parent b827ada7a8
commit b050546e39
2 changed files with 24 additions and 9 deletions

View File

@ -754,7 +754,7 @@ let volume_popover_show = false;
volume_popover_btn.addEventListener('click', function(e){ e.stopPropagation(); }) volume_popover_btn.addEventListener('click', function(e){ e.stopPropagation(); })
function toggleVolumePopover(){ function toggleVolumePopover(){
if (volume_popover_show){ if (!volume_popover_show){
volume_popover_instance = new Popper(volume_popover_btn, volume_popover_div, { volume_popover_instance = new Popper(volume_popover_btn, volume_popover_div, {
placement: 'top', placement: 'top',
modifiers: { modifiers: {
@ -776,6 +776,7 @@ function toggleVolumePopover(){
if (volume_popover_instance){ if (volume_popover_instance){
volume_popover_instance.destroy(); volume_popover_instance.destroy();
volume_popover_instance = null; volume_popover_instance = null;
volume_popover_show = !volume_popover_show;
} }
}, { once: true } ); }, { once: true } );
} }
@ -809,13 +810,18 @@ let filesToProceed = [];
let filesProgressItem = {}; let filesProgressItem = {};
let runningXHR = null; let runningXHR = null;
uploadSubmitBtn.addEventListener("click", uploadStart) let areYouSureToCancelUploading = false;
uploadSubmitBtn.addEventListener("click", uploadStart);
uploadCancelBtn.addEventListener("click", uploadCancel)
function uploadStart(){ function uploadStart(){
uploadModalList.textContent = ''; uploadModalList.textContent = '';
uploadSuccessAlert.style.display = 'none'; uploadSuccessAlert.style.display = 'none';
uploadCancelBtn.style.display = 'none'; uploadCancelBtn.style.display = 'none';
uploadCloseBtn.style.display = 'block'; uploadCloseBtn.style.display = 'block';
areYouSureToCancelUploading = false;
$(uploadCancelBtn).tooltip('hide');
const file_list = uploadFileInput.files; const file_list = uploadFileInput.files;
if (file_list.length) { if (file_list.length) {
@ -928,12 +934,19 @@ function uploadNextFile(){
} }
function uploadCancel(){ function uploadCancel(){
runningXHR.abort() if (!areYouSureToCancelUploading){
filesToProceed = []; $(uploadCancelBtn).tooltip('show');
uploadModal.modal('hide'); } else {
uploadFileInput.value = ''; $(uploadCancelBtn).tooltip('hide');
request('post', {action : 'rescan'}); uploadModal.modal('hide');
updateResults(); runningXHR.abort()
filesToProceed = [];
uploadFileInput.value = '';
request('post', {action : 'rescan'});
updateResults();
}
areYouSureToCancelUploading = !areYouSureToCancelUploading;
} }
themeInit(); themeInit();

View File

@ -488,7 +488,9 @@
<div class="modal-footer"> <div class="modal-footer">
<button type="button" id="uploadClose" class="btn btn-success" data-dismiss="modal"> <button type="button" id="uploadClose" class="btn btn-success" data-dismiss="modal">
<i class="fas fa-times mr-1"></i> Close</button> <i class="fas fa-times mr-1"></i> Close</button>
<button type="button" id="uploadCancel" class="btn btn-danger"> <button type="button" id="uploadCancel" class="btn btn-danger" data-toggle="tooltip"
data-html="true"
title="<strong>Are you really sure?</strong> <br /> Click again to abort uploading.">
<i class="fas fa-trash-alt mr-1" aria-hidden="true"></i> Cancel</button> <i class="fas fa-trash-alt mr-1" aria-hidden="true"></i> Cancel</button>
</div> </div>
</div> </div>