# HG changeset patch # User Fadi Abbud # Date 1551885556 -3600 # Node ID 1a6553da9078cd8f3c8fc8f68ebe131dbaecacf2 # Parent 6498267096ae39415c3b6701ba9a7ae0dea6580e client:pdf-gen : add download-template functionality * add the ability to download the already uploaded templates diff -r 6498267096ae -r 1a6553da9078 client/src/components/systemconfiguration/PDFTemplates.vue --- a/client/src/components/systemconfiguration/PDFTemplates.vue Wed Mar 06 15:39:59 2019 +0100 +++ b/client/src/components/systemconfiguration/PDFTemplates.vue Wed Mar 06 16:19:16 2019 +0100 @@ -27,6 +27,13 @@
global
+ @@ -62,12 +69,13 @@ * SPDX-License-Identifier: AGPL-3.0-or-later * License-Filename: LICENSES/AGPL-3.0.txt * - * Copyright (C) 2018 by via donau + * Copyright (C) 2018, 2019 by via donau * – Österreichische Wasserstraßen-Gesellschaft mbH * Software engineering by Intevation GmbH * * Author(s): * Markus Kottländer + * Fadi Abbud */ import { HTTP } from "@/lib/http"; import { displayError, displayInfo } from "@/lib/errors.js"; @@ -81,6 +89,46 @@ }; }, methods: { + downloadTemplate(template) { + if (template) { + var templateData = ""; + var element = document.createElement("a"); + element.style.display = "none"; + element.setAttribute("download", template.name + ".json"); + document.body.appendChild(element); + HTTP.get("/templates/print/" + template.name, { + headers: { + "X-Gemma-Auth": localStorage.getItem("token"), + "Content-type": "text/xml; charset=UTF-8" + } + }) + .then(response => { + templateData = response.data.template_data; + element.setAttribute( + "href", + "data:text/json;charset=utf-8," + + encodeURIComponent( + JSON.stringify({ + name: templateData.name, + properties: templateData.properties, + elements: templateData.elements + }) + ) + ); + element.click(); + }) + .catch(e => { + const { status, data } = e.response; + displayError({ + title: this.$gettext("Backend Error"), + message: `${status}: ${data.message || data}` + }); + }) + .finally(() => { + document.body.removeChild(element); + }); + } + }, uploadTemplate() { const reader = new FileReader(); reader.onload = event => {