Fix download button waiting if document has started but not completed downloading

This commit is contained in:
aib 2014-03-14 05:23:47 +02:00
parent 432af8b36e
commit 2870a6108c

View File

@ -571,6 +571,8 @@ var PDFView = {
this.pdfDocument = null; this.pdfDocument = null;
var self = this; var self = this;
self.loading = true; self.loading = true;
self.downloadComplete = false;
var passwordNeeded = function passwordNeeded(updatePassword, reason) { var passwordNeeded = function passwordNeeded(updatePassword, reason) {
PasswordPrompt.updatePassword = updatePassword; PasswordPrompt.updatePassword = updatePassword;
PasswordPrompt.reason = reason; PasswordPrompt.reason = reason;
@ -622,7 +624,7 @@ var PDFView = {
}, },
download: function pdfViewDownload() { download: function pdfViewDownload() {
function noData() { function downloadByUrl() {
downloadManager.downloadUrl(url, filename); downloadManager.downloadUrl(url, filename);
} }
@ -636,7 +638,12 @@ var PDFView = {
}; };
if (!this.pdfDocument) { // the PDF is not ready yet if (!this.pdfDocument) { // the PDF is not ready yet
noData(); downloadByUrl();
return;
}
if (!this.downloadComplete) { // the PDF is still downloading
downloadByUrl();
return; return;
} }
@ -645,8 +652,8 @@ var PDFView = {
var blob = PDFJS.createBlob(data, 'application/pdf'); var blob = PDFJS.createBlob(data, 'application/pdf');
downloadManager.download(blob, url, filename); downloadManager.download(blob, url, filename);
}, },
noData // Error occurred try downloading with just the url. downloadByUrl // Error occurred try downloading with just the url.
).then(null, noData); ).then(null, downloadByUrl);
}, },
fallback: function pdfViewFallback(featureId) { fallback: function pdfViewFallback(featureId) {
@ -864,6 +871,7 @@ var PDFView = {
errorWrapper.setAttribute('hidden', 'true'); errorWrapper.setAttribute('hidden', 'true');
pdfDocument.getDownloadInfo().then(function() { pdfDocument.getDownloadInfo().then(function() {
self.downloadComplete = true;
PDFView.loadingBar.hide(); PDFView.loadingBar.hide();
var outerContainer = document.getElementById('outerContainer'); var outerContainer = document.getElementById('outerContainer');
outerContainer.classList.remove('loadingInProgress'); outerContainer.classList.remove('loadingInProgress');