diff --git a/static/css/project_styles.css b/static/css/project.css similarity index 100% rename from static/css/project_styles.css rename to static/css/project.css diff --git a/static/js/pdf_api_wrapper.js b/static/js/pdf_api_wrapper.js new file mode 100644 index 0000000..7cd712c --- /dev/null +++ b/static/js/pdf_api_wrapper.js @@ -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)); + } +} diff --git a/static/js/project_functions.js b/static/js/project.js similarity index 86% rename from static/js/project_functions.js rename to static/js/project.js index 38c01de..6825d0a 100644 --- a/static/js/project_functions.js +++ b/static/js/project.js @@ -1,7 +1,10 @@ +/* eslint-disable new-cap */ /* eslint-disable camelcase */ /* eslint-disable no-console */ + let uuid; let pdf_uploaded = false; +import('./pdf_api_wrapper'); // eslint-disable-next-line no-undef, no-unused-vars const vueInstance = new Vue({ @@ -17,35 +20,6 @@ const vueInstance = new Vue({ window.addEventListener('resize', () => this.scale_page_view()); }, methods: { - 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.project_uuid}/complete.pdf`, 'complete_project.pdf'); - }, - download_split_pdf() { - fetch(`/get_single_pages_archive/${this.project_uuid}/`, { - method: 'GET', - }) - .then((response) => response.json()) - .then((data) => { - console.debug('data from Backend: ', data); - if (data.status === 200) { - this.downloadURI(`/projects/${this.project_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)); - }, move_page(from_page, to_page) { console.debug('trying to move page: ', from_page, to_page); fetch(`/move_page/${this.project_uuid}/${from_page}/${to_page}`, { @@ -132,9 +106,8 @@ const vueInstance = new Vue({ console.debug('div_overview', div_overview); }, side_loaded() { - document.getElementById('btn_download_complete').addEventListener('click', () => this.download_pdf()); - document.getElementById('btn_download_singel_pages').addEventListener('click', () => this.download_split_pdf()); - const self = this; + document.getElementById('btn_download_complete').addEventListener('click', () => new pdf_api_wrapper(`${uuid}`).download_pdf()); + document.getElementById('btn_download_singel_pages').addEventListener('click', () => new pdf_api_wrapper(`${uuid}`).download_split_pdf()); this.scale_page_view(); fetch('/init_project/', { diff --git a/templates/partials/project.html b/templates/partials/project.html index 1c1dfa9..d1cb1e4 100644 --- a/templates/partials/project.html +++ b/templates/partials/project.html @@ -20,8 +20,9 @@ - - + + +