Skip to content

Commit

Permalink
Added PDF upload message
Browse files Browse the repository at this point in the history
Signed-off-by: Mishel Shaji <[email protected]>
  • Loading branch information
gpsrenewablesit committed Jul 20, 2023
1 parent bdbb60f commit 07f2d25
Show file tree
Hide file tree
Showing 9 changed files with 18,713 additions and 16 deletions.
6 changes: 6 additions & 0 deletions css/viewer.css
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,9 @@
.pdfViewer.disabledTextSelection .textLayer * {
cursor: default;
}

#save-progress{
text-align: center;
padding: 5px 0;
display: none;
}
3,180 changes: 3,177 additions & 3 deletions js/files_pdfviewer-main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/files_pdfviewer-main.js.map

Large diffs are not rendered by default.

5,558 changes: 5,555 additions & 3 deletions js/files_pdfviewer-public.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/files_pdfviewer-public.js.map

Large diffs are not rendered by default.

9,957 changes: 9,955 additions & 2 deletions js/files_pdfviewer-workersrc.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/files_pdfviewer-workersrc.js.map

Large diffs are not rendered by default.

21 changes: 16 additions & 5 deletions src/workersrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,12 @@ redirectIfNotIframe()
const queryString = window.location.search
const urlParams = new URLSearchParams(queryString)
const canDownload = urlParams.get('canDownload')
let isUploading = false
let uploadProgressMessage = null

function initializeCustomPDFViewerApplication() {
const head = document.getElementsByTagName('head')[0]
uploadProgressMessage = document.getElementById('save-progress')

// Preferences override options, so they must be disabled for
// "externalLinkTarget" to take effect.
Expand Down Expand Up @@ -86,23 +89,28 @@ function initializeCustomPDFViewerApplication() {
logger.info('Download and print available')

PDFViewerApplication.download = function() {
PDFViewerApplication.pdfDocument.getData().then(function(data) {
savePdf(data)
})
alert('Please make some changes and click save.')
}

PDFViewerApplication.save = function() {
logger.info('PDF Document with annotation is being saved.')
PDFViewerApplication.pdfDocument.saveDocument().then(function(data) {
savePdf(data)
if (isUploading) {
alert('Please wait for the upload to complete.')
return
}

savePdf(data, PDFViewerApplication)
})
}
}

logger.debug('Initialized files_pdfviewer', PDFViewerApplicationOptions.getAll())
}

function savePdf(data) {
function savePdf(data, pdfAppication) {
isUploading = true
uploadProgressMessage.style.display = 'block'
const blob = new Blob([data], { type: 'application/pdf' })

// Create a URL object and obtain file query parameter.
Expand All @@ -122,8 +130,11 @@ function savePdf(data) {
},
}).then(function() {
logger.log('File uploaded successfully')
isUploading = false
uploadProgressMessage.style.display = 'none'
}).catch(function(error) {
logger.error('Error uploading file:', error)
isUploading = false
})
}

Expand Down
1 change: 1 addition & 0 deletions templates/viewer.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
</div> <!-- sidebarContainer -->

<div id="mainContainer">
<div id="save-progress">Saving document</div>
<div class="findbar hidden doorHanger" id="findbar">
<div id="findbarInputContainer">
<input id="findInput" class="toolbarField" title="Find" placeholder="Find in document…" tabindex="91" data-l10n-id="find_input" aria-invalid="false">
Expand Down

0 comments on commit 07f2d25

Please sign in to comment.