# HG changeset patch # User Thomas Junk # Date 1562587879 -7200 # Node ID 387f239018c7fa82134e64f9a4783cee2f3ba860 # Parent 03e8e6cc0b790016f6d6fec9568e0c6655b19bfb pdf_tool: retain default template, when custom template is uploaded diff -r 03e8e6cc0b79 -r 387f239018c7 client/src/components/Pdftool.vue --- a/client/src/components/Pdftool.vue Mon Jul 08 12:34:10 2019 +0200 +++ b/client/src/components/Pdftool.vue Mon Jul 08 14:11:19 2019 +0200 @@ -108,12 +108,14 @@ import { displayError } from "@/lib/errors"; import { pdfgen, templateLoader } from "@/lib/mixins"; -var paperSizes = { +const paperSizes = { // in millimeter, landscape [width, height] a3: [420, 297], a4: [297, 210] }; +const DEFAULT_TEMPLATE = "Default"; + export default { mixins: [pdfgen, templateLoader], name: "pdftool", @@ -128,7 +130,7 @@ }, templates: [ { - name: "Default", + name: DEFAULT_TEMPLATE, properties: { format: "landscape", paperSize: "a4", @@ -150,7 +152,7 @@ }, { type: "northarrow", - position: "topright", + position: "topleft", offset: { x: 6, y: 4 }, size: 2 } @@ -210,20 +212,17 @@ // When a template is chosen from the dropdown, its propoerties are // applied to the rest of the form. applyTemplateToForm() { - if (this.form.template) { + if (this.form.template && this.form.template.name !== DEFAULT_TEMPLATE) { this.loadTemplates( `/templates/${this.form.template.type}/${this.form.template.name}` ) .then(response => { this.prepareImages(response.data.template_data.elements).then( values => { - this.templateData = response.data.template_data; values.forEach(v => { response.data.template_data.elements[v.index].url = v.url; }); - this.form.format = this.templateData.properties.format; - this.form.paperSize = this.templateData.properties.paperSize; - this.form.resolution = this.templateData.properties.resolution; + this.setTemplate(response.data.template_data); } ); }) @@ -234,8 +233,16 @@ message: `${status}: ${data.message || data}` }); }); + } else { + this.setTemplate(this.templates[0]); } }, + setTemplate(template) { + this.templateData = template; + this.form.format = this.templateData.properties.format; + this.form.paperSize = this.templateData.properties.paperSize; + this.form.resolution = this.templateData.properties.resolution; + }, download() { // disable button while working on it this.readyToGenerate = false; @@ -803,8 +810,8 @@ }) .then(response => { if (response.data.length) { - this.templates = response.data; - this.form.template = this.templates[0]; + this.templates = [...this.templates, ...response.data]; + this.form.template = this.templates[1]; this.applyTemplateToForm(); } else { this.form.template = this.templates[0];