Mercurial > gemma
changeset 2527:1a6553da9078
client:pdf-gen : add download-template functionality
* add the ability to download the already uploaded templates
author | Fadi Abbud <fadi.abbud@intevation.de> |
---|---|
date | Wed, 06 Mar 2019 16:19:16 +0100 |
parents | 6498267096ae |
children | 113912129481 |
files | client/src/components/systemconfiguration/PDFTemplates.vue |
diffstat | 1 files changed, 49 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- 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 @@ </div> <div class="py-2 col-2" v-else><i>global</i></div> <div class="col py-2 text-right"> + <button + class="btn btn-sm btn-info m-1" + ref="downloadTemplate" + @click="downloadTemplate(template)" + > + <font-awesome-icon icon="download" /> + </button> <button class="btn btn-sm btn-dark" @click="deleteTemplate(template)"> <font-awesome-icon icon="trash" /> </button> @@ -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 <markus@intevation.de> + * Fadi Abbud <fadi.abbud@intevation.de> */ 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 => {