splitt api functions in seperate .js file
This commit is contained in:
parent
fad9f38422
commit
b8a34dd2a7
4 changed files with 49 additions and 34 deletions
41
static/js/pdf_api_wrapper.js
Normal file
41
static/js/pdf_api_wrapper.js
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
/* eslint-disable camelcase */
|
||||
/* eslint-disable no-console */
|
||||
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
class pdf_api_wrapper {
|
||||
constructor(project_uuid) {
|
||||
this.uuid = project_uuid;
|
||||
}
|
||||
|
||||
downloadURI(uri, name) {
|
||||
const link = document.createElement('a');
|
||||
link.download = name;
|
||||
link.href = uri;
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
document.body.removeChild(link);
|
||||
// delete link;
|
||||
}
|
||||
|
||||
download_pdf() {
|
||||
console.debug('download_pdf triggered');
|
||||
this.downloadURI(`/projects/${this.uuid}/complete.pdf`, 'complete_project.pdf');
|
||||
}
|
||||
|
||||
download_split_pdf() {
|
||||
fetch(`/get_single_pages_archive/${this.uuid}/`, {
|
||||
method: 'GET',
|
||||
})
|
||||
.then((response) => response.json())
|
||||
.then((data) => {
|
||||
console.debug('data from Backend: ', data);
|
||||
if (data.status === 200) {
|
||||
this.downloadURI(`/projects/${this.uuid}/pdf_splitted.zip`, 'splitted_pdfs.zip');
|
||||
console.info('Archive with single Pages-PDFs created');
|
||||
} else {
|
||||
console.error('Project could not be created');
|
||||
}
|
||||
})
|
||||
.catch((error) => console.error(error));
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue