Mercurial > gemma
annotate client/src/components/systemconfiguration/PDFTemplates.vue @ 2684:c4da269238a4
client: waterlevel diagram: visualize data gaps
author | Markus Kottlaender <markus@intevation.de> |
---|---|
date | Fri, 15 Mar 2019 12:43:30 +0100 |
parents | 4bcb26542767 |
children | add2d47c2567 |
rev | line source |
---|---|
2213 | 1 <template> |
2290
92649a0537fa
client: admin: style adjustments
Markus Kottlaender <markus@intevation.de>
parents:
2289
diff
changeset
|
2 <div class="d-flex flex-column"> |
2213 | 3 <div class="d-flex flex-row justify-content-between"> |
4 <h5><translate>PDF-Templates</translate></h5> | |
5 <input | |
2384
c06b001dc26b
client: improved popup implementation
Markus Kottlaender <markus@intevation.de>
parents:
2357
diff
changeset
|
6 @change="uploadTemplate" |
2257
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
7 id="uploadTemplate" |
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
8 ref="uploadTemplate" |
2213 | 9 type="file" |
10 style="visibility:hidden" | |
11 /> | |
12 </div> | |
2290
92649a0537fa
client: admin: style adjustments
Markus Kottlaender <markus@intevation.de>
parents:
2289
diff
changeset
|
13 <div class="mt-1 border-bottom pb-4"> |
2462
9ae2a2f758bb
client: make use of new table header/body components
Markus Kottlaender <markus@intevation.de>
parents:
2459
diff
changeset
|
14 <UITableHeader |
9ae2a2f758bb
client: make use of new table header/body components
Markus Kottlaender <markus@intevation.de>
parents:
2459
diff
changeset
|
15 :columns="[ |
9ae2a2f758bb
client: make use of new table header/body components
Markus Kottlaender <markus@intevation.de>
parents:
2459
diff
changeset
|
16 { id: 'name', title: 'Name', class: 'col-4' }, |
9ae2a2f758bb
client: make use of new table header/body components
Markus Kottlaender <markus@intevation.de>
parents:
2459
diff
changeset
|
17 { id: 'date', title: 'Date', class: 'col-4' }, |
9ae2a2f758bb
client: make use of new table header/body components
Markus Kottlaender <markus@intevation.de>
parents:
2459
diff
changeset
|
18 { id: 'country', title: 'Country', class: 'col-2' } |
9ae2a2f758bb
client: make use of new table header/body components
Markus Kottlaender <markus@intevation.de>
parents:
2459
diff
changeset
|
19 ]" |
9ae2a2f758bb
client: make use of new table header/body components
Markus Kottlaender <markus@intevation.de>
parents:
2459
diff
changeset
|
20 :sortable="false" |
9ae2a2f758bb
client: make use of new table header/body components
Markus Kottlaender <markus@intevation.de>
parents:
2459
diff
changeset
|
21 /> |
9ae2a2f758bb
client: make use of new table header/body components
Markus Kottlaender <markus@intevation.de>
parents:
2459
diff
changeset
|
22 <UITableBody :data="templates" v-slot="{ item: template }"> |
2640
4bcb26542767
client: use new btn-xs class in tables
Markus Kottlaender <markus@intevation.de>
parents:
2531
diff
changeset
|
23 <div class="py-1 col-4">{{ template.name }}</div> |
4bcb26542767
client: use new btn-xs class in tables
Markus Kottlaender <markus@intevation.de>
parents:
2531
diff
changeset
|
24 <div class="py-1 col-4">{{ template.time }}</div> |
4bcb26542767
client: use new btn-xs class in tables
Markus Kottlaender <markus@intevation.de>
parents:
2531
diff
changeset
|
25 <div class="py-1 col-2" v-if="template.country"> |
2462
9ae2a2f758bb
client: make use of new table header/body components
Markus Kottlaender <markus@intevation.de>
parents:
2459
diff
changeset
|
26 {{ template.country }} |
9ae2a2f758bb
client: make use of new table header/body components
Markus Kottlaender <markus@intevation.de>
parents:
2459
diff
changeset
|
27 </div> |
2640
4bcb26542767
client: use new btn-xs class in tables
Markus Kottlaender <markus@intevation.de>
parents:
2531
diff
changeset
|
28 <div class="py-1 col-2" v-else><i>global</i></div> |
4bcb26542767
client: use new btn-xs class in tables
Markus Kottlaender <markus@intevation.de>
parents:
2531
diff
changeset
|
29 <div class="col py-1 text-right"> |
2527
1a6553da9078
client:pdf-gen : add download-template functionality
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2522
diff
changeset
|
30 <button |
2640
4bcb26542767
client: use new btn-xs class in tables
Markus Kottlaender <markus@intevation.de>
parents:
2531
diff
changeset
|
31 class="btn btn-xs btn-info mr-1" |
2527
1a6553da9078
client:pdf-gen : add download-template functionality
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2522
diff
changeset
|
32 ref="downloadTemplate" |
1a6553da9078
client:pdf-gen : add download-template functionality
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2522
diff
changeset
|
33 @click="downloadTemplate(template)" |
1a6553da9078
client:pdf-gen : add download-template functionality
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2522
diff
changeset
|
34 > |
2640
4bcb26542767
client: use new btn-xs class in tables
Markus Kottlaender <markus@intevation.de>
parents:
2531
diff
changeset
|
35 <font-awesome-icon icon="download" fixed-width /> |
2527
1a6553da9078
client:pdf-gen : add download-template functionality
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2522
diff
changeset
|
36 </button> |
2640
4bcb26542767
client: use new btn-xs class in tables
Markus Kottlaender <markus@intevation.de>
parents:
2531
diff
changeset
|
37 <button class="btn btn-xs btn-dark" @click="deleteTemplate(template)"> |
4bcb26542767
client: use new btn-xs class in tables
Markus Kottlaender <markus@intevation.de>
parents:
2531
diff
changeset
|
38 <font-awesome-icon icon="trash" fixed-width /> |
2462
9ae2a2f758bb
client: make use of new table header/body components
Markus Kottlaender <markus@intevation.de>
parents:
2459
diff
changeset
|
39 </button> |
9ae2a2f758bb
client: make use of new table header/body components
Markus Kottlaender <markus@intevation.de>
parents:
2459
diff
changeset
|
40 </div> |
9ae2a2f758bb
client: make use of new table header/body components
Markus Kottlaender <markus@intevation.de>
parents:
2459
diff
changeset
|
41 </UITableBody> |
2459
408e0f4d4008
clinet:pdf-gen template:unifiy feedback messages for template
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2448
diff
changeset
|
42 <button class="btn btn-info mt-2" @click="$refs.uploadTemplate.click()"> |
2247
e6fba449aa3c
merged pdf-export in default
Markus Kottlaender <markus@intevation.de>
parents:
2216
diff
changeset
|
43 <font-awesome-icon |
e6fba449aa3c
merged pdf-export in default
Markus Kottlaender <markus@intevation.de>
parents:
2216
diff
changeset
|
44 icon="spinner" |
e6fba449aa3c
merged pdf-export in default
Markus Kottlaender <markus@intevation.de>
parents:
2216
diff
changeset
|
45 class="fa-spin fa-fw" |
e6fba449aa3c
merged pdf-export in default
Markus Kottlaender <markus@intevation.de>
parents:
2216
diff
changeset
|
46 v-if="uploading" |
e6fba449aa3c
merged pdf-export in default
Markus Kottlaender <markus@intevation.de>
parents:
2216
diff
changeset
|
47 /> |
e6fba449aa3c
merged pdf-export in default
Markus Kottlaender <markus@intevation.de>
parents:
2216
diff
changeset
|
48 <font-awesome-icon icon="upload" class="fa-fw" v-else /> |
e6fba449aa3c
merged pdf-export in default
Markus Kottlaender <markus@intevation.de>
parents:
2216
diff
changeset
|
49 <translate>Upload new template</translate> |
e6fba449aa3c
merged pdf-export in default
Markus Kottlaender <markus@intevation.de>
parents:
2216
diff
changeset
|
50 </button> |
2213 | 51 </div> |
52 </div> | |
53 </template> | |
54 | |
2323
5b53be76080c
client: adjusted table and delete button styles
Markus Kottlaender <markus@intevation.de>
parents:
2290
diff
changeset
|
55 <style lang="scss" scoped> |
5b53be76080c
client: adjusted table and delete button styles
Markus Kottlaender <markus@intevation.de>
parents:
2290
diff
changeset
|
56 .table th, |
5b53be76080c
client: adjusted table and delete button styles
Markus Kottlaender <markus@intevation.de>
parents:
2290
diff
changeset
|
57 td { |
5b53be76080c
client: adjusted table and delete button styles
Markus Kottlaender <markus@intevation.de>
parents:
2290
diff
changeset
|
58 font-size: $smaller; |
5b53be76080c
client: adjusted table and delete button styles
Markus Kottlaender <markus@intevation.de>
parents:
2290
diff
changeset
|
59 border-top: 0px !important; |
5b53be76080c
client: adjusted table and delete button styles
Markus Kottlaender <markus@intevation.de>
parents:
2290
diff
changeset
|
60 text-align: left; |
5b53be76080c
client: adjusted table and delete button styles
Markus Kottlaender <markus@intevation.de>
parents:
2290
diff
changeset
|
61 padding: $small-offset !important; |
5b53be76080c
client: adjusted table and delete button styles
Markus Kottlaender <markus@intevation.de>
parents:
2290
diff
changeset
|
62 } |
5b53be76080c
client: adjusted table and delete button styles
Markus Kottlaender <markus@intevation.de>
parents:
2290
diff
changeset
|
63 </style> |
5b53be76080c
client: adjusted table and delete button styles
Markus Kottlaender <markus@intevation.de>
parents:
2290
diff
changeset
|
64 |
2213 | 65 <script> |
66 /* This is Free Software under GNU Affero General Public License v >= 3.0 | |
67 * without warranty, see README.md and license for details. | |
68 * | |
69 * SPDX-License-Identifier: AGPL-3.0-or-later | |
70 * License-Filename: LICENSES/AGPL-3.0.txt | |
71 * | |
2527
1a6553da9078
client:pdf-gen : add download-template functionality
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2522
diff
changeset
|
72 * Copyright (C) 2018, 2019 by via donau |
2213 | 73 * – Österreichische Wasserstraßen-Gesellschaft mbH |
74 * Software engineering by Intevation GmbH | |
75 * | |
76 * Author(s): | |
77 * Markus Kottländer <markus@intevation.de> | |
2527
1a6553da9078
client:pdf-gen : add download-template functionality
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2522
diff
changeset
|
78 * Fadi Abbud <fadi.abbud@intevation.de> |
2213 | 79 */ |
2257
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
80 import { HTTP } from "@/lib/http"; |
2459
408e0f4d4008
clinet:pdf-gen template:unifiy feedback messages for template
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2448
diff
changeset
|
81 import { displayError, displayInfo } from "@/lib/errors.js"; |
2213 | 82 |
83 export default { | |
84 name: "pdftemplates", | |
2216
585373d33f8f
prepared pdf template administration
Markus Kottlaender <markus@intevation.de>
parents:
2213
diff
changeset
|
85 data() { |
585373d33f8f
prepared pdf template administration
Markus Kottlaender <markus@intevation.de>
parents:
2213
diff
changeset
|
86 return { |
2257
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
87 templates: [], |
2459
408e0f4d4008
clinet:pdf-gen template:unifiy feedback messages for template
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2448
diff
changeset
|
88 uploading: false |
2216
585373d33f8f
prepared pdf template administration
Markus Kottlaender <markus@intevation.de>
parents:
2213
diff
changeset
|
89 }; |
585373d33f8f
prepared pdf template administration
Markus Kottlaender <markus@intevation.de>
parents:
2213
diff
changeset
|
90 }, |
585373d33f8f
prepared pdf template administration
Markus Kottlaender <markus@intevation.de>
parents:
2213
diff
changeset
|
91 methods: { |
2527
1a6553da9078
client:pdf-gen : add download-template functionality
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2522
diff
changeset
|
92 downloadTemplate(template) { |
1a6553da9078
client:pdf-gen : add download-template functionality
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2522
diff
changeset
|
93 if (template) { |
1a6553da9078
client:pdf-gen : add download-template functionality
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2522
diff
changeset
|
94 var templateData = ""; |
1a6553da9078
client:pdf-gen : add download-template functionality
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2522
diff
changeset
|
95 var element = document.createElement("a"); |
1a6553da9078
client:pdf-gen : add download-template functionality
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2522
diff
changeset
|
96 element.style.display = "none"; |
1a6553da9078
client:pdf-gen : add download-template functionality
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2522
diff
changeset
|
97 element.setAttribute("download", template.name + ".json"); |
1a6553da9078
client:pdf-gen : add download-template functionality
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2522
diff
changeset
|
98 document.body.appendChild(element); |
1a6553da9078
client:pdf-gen : add download-template functionality
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2522
diff
changeset
|
99 HTTP.get("/templates/print/" + template.name, { |
1a6553da9078
client:pdf-gen : add download-template functionality
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2522
diff
changeset
|
100 headers: { |
1a6553da9078
client:pdf-gen : add download-template functionality
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2522
diff
changeset
|
101 "X-Gemma-Auth": localStorage.getItem("token"), |
1a6553da9078
client:pdf-gen : add download-template functionality
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2522
diff
changeset
|
102 "Content-type": "text/xml; charset=UTF-8" |
1a6553da9078
client:pdf-gen : add download-template functionality
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2522
diff
changeset
|
103 } |
1a6553da9078
client:pdf-gen : add download-template functionality
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2522
diff
changeset
|
104 }) |
1a6553da9078
client:pdf-gen : add download-template functionality
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2522
diff
changeset
|
105 .then(response => { |
1a6553da9078
client:pdf-gen : add download-template functionality
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2522
diff
changeset
|
106 templateData = response.data.template_data; |
1a6553da9078
client:pdf-gen : add download-template functionality
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2522
diff
changeset
|
107 element.setAttribute( |
1a6553da9078
client:pdf-gen : add download-template functionality
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2522
diff
changeset
|
108 "href", |
1a6553da9078
client:pdf-gen : add download-template functionality
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2522
diff
changeset
|
109 "data:text/json;charset=utf-8," + |
1a6553da9078
client:pdf-gen : add download-template functionality
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2522
diff
changeset
|
110 encodeURIComponent( |
2531
47b9a4f9a05c
client:pdf-gen: change the formatting of the downloaded json file
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2527
diff
changeset
|
111 JSON.stringify( |
47b9a4f9a05c
client:pdf-gen: change the formatting of the downloaded json file
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2527
diff
changeset
|
112 { |
47b9a4f9a05c
client:pdf-gen: change the formatting of the downloaded json file
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2527
diff
changeset
|
113 name: templateData.name, |
47b9a4f9a05c
client:pdf-gen: change the formatting of the downloaded json file
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2527
diff
changeset
|
114 properties: templateData.properties, |
47b9a4f9a05c
client:pdf-gen: change the formatting of the downloaded json file
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2527
diff
changeset
|
115 elements: templateData.elements |
47b9a4f9a05c
client:pdf-gen: change the formatting of the downloaded json file
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2527
diff
changeset
|
116 }, |
47b9a4f9a05c
client:pdf-gen: change the formatting of the downloaded json file
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2527
diff
changeset
|
117 null, |
47b9a4f9a05c
client:pdf-gen: change the formatting of the downloaded json file
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2527
diff
changeset
|
118 2 |
47b9a4f9a05c
client:pdf-gen: change the formatting of the downloaded json file
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2527
diff
changeset
|
119 ) |
2527
1a6553da9078
client:pdf-gen : add download-template functionality
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2522
diff
changeset
|
120 ) |
1a6553da9078
client:pdf-gen : add download-template functionality
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2522
diff
changeset
|
121 ); |
1a6553da9078
client:pdf-gen : add download-template functionality
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2522
diff
changeset
|
122 element.click(); |
1a6553da9078
client:pdf-gen : add download-template functionality
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2522
diff
changeset
|
123 }) |
1a6553da9078
client:pdf-gen : add download-template functionality
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2522
diff
changeset
|
124 .catch(e => { |
1a6553da9078
client:pdf-gen : add download-template functionality
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2522
diff
changeset
|
125 const { status, data } = e.response; |
1a6553da9078
client:pdf-gen : add download-template functionality
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2522
diff
changeset
|
126 displayError({ |
1a6553da9078
client:pdf-gen : add download-template functionality
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2522
diff
changeset
|
127 title: this.$gettext("Backend Error"), |
1a6553da9078
client:pdf-gen : add download-template functionality
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2522
diff
changeset
|
128 message: `${status}: ${data.message || data}` |
1a6553da9078
client:pdf-gen : add download-template functionality
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2522
diff
changeset
|
129 }); |
1a6553da9078
client:pdf-gen : add download-template functionality
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2522
diff
changeset
|
130 }) |
1a6553da9078
client:pdf-gen : add download-template functionality
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2522
diff
changeset
|
131 .finally(() => { |
1a6553da9078
client:pdf-gen : add download-template functionality
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2522
diff
changeset
|
132 document.body.removeChild(element); |
1a6553da9078
client:pdf-gen : add download-template functionality
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2522
diff
changeset
|
133 }); |
1a6553da9078
client:pdf-gen : add download-template functionality
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2522
diff
changeset
|
134 } |
1a6553da9078
client:pdf-gen : add download-template functionality
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2522
diff
changeset
|
135 }, |
2384
c06b001dc26b
client: improved popup implementation
Markus Kottlaender <markus@intevation.de>
parents:
2357
diff
changeset
|
136 uploadTemplate() { |
2257
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
137 const reader = new FileReader(); |
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
138 reader.onload = event => { |
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
139 let template; |
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
140 try { |
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
141 template = JSON.parse(event.target.result); |
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
142 } catch (e) { |
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
143 displayError({ |
2284
9f327f197ddd
client: translation: mark some strings for translations
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2257
diff
changeset
|
144 title: this.$gettext("Format Error"), |
9f327f197ddd
client: translation: mark some strings for translations
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2257
diff
changeset
|
145 message: this.$gettext( |
9f327f197ddd
client: translation: mark some strings for translations
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2257
diff
changeset
|
146 "Uploaded file does not contain valid json data." |
9f327f197ddd
client: translation: mark some strings for translations
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2257
diff
changeset
|
147 ) |
2257
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
148 }); |
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
149 } |
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
150 if (template.name) { |
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
151 this.uploading = true; |
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
152 HTTP.post( |
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
153 "/templates/print/" + template.name, |
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
154 { |
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
155 template_name: template.name, |
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
156 template_data: template |
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
157 }, |
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
158 { |
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
159 headers: { |
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
160 "X-Gemma-Auth": localStorage.getItem("token"), |
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
161 "Content-type": "text/xml; charset=UTF-8" |
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
162 } |
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
163 } |
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
164 ) |
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
165 .then(() => { |
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
166 this.loadTemplates(); |
2459
408e0f4d4008
clinet:pdf-gen template:unifiy feedback messages for template
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2448
diff
changeset
|
167 displayInfo({ |
408e0f4d4008
clinet:pdf-gen template:unifiy feedback messages for template
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2448
diff
changeset
|
168 message: |
408e0f4d4008
clinet:pdf-gen template:unifiy feedback messages for template
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2448
diff
changeset
|
169 template.name + " " + this.$gettext("uploaded successfully") |
408e0f4d4008
clinet:pdf-gen template:unifiy feedback messages for template
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2448
diff
changeset
|
170 }); |
2257
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
171 }) |
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
172 .catch(e => { |
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
173 const { status, data } = e.response; |
2522
24bab584f0a1
client: improved error message format for pdf-template uploads
Markus Kottlaender <markus@intevation.de>
parents:
2462
diff
changeset
|
174 if (status === 400) { |
24bab584f0a1
client: improved error message format for pdf-template uploads
Markus Kottlaender <markus@intevation.de>
parents:
2462
diff
changeset
|
175 displayError({ |
24bab584f0a1
client: improved error message format for pdf-template uploads
Markus Kottlaender <markus@intevation.de>
parents:
2462
diff
changeset
|
176 title: this.$gettext("Error"), |
24bab584f0a1
client: improved error message format for pdf-template uploads
Markus Kottlaender <markus@intevation.de>
parents:
2462
diff
changeset
|
177 message: `${data.message || data}` |
24bab584f0a1
client: improved error message format for pdf-template uploads
Markus Kottlaender <markus@intevation.de>
parents:
2462
diff
changeset
|
178 }); |
24bab584f0a1
client: improved error message format for pdf-template uploads
Markus Kottlaender <markus@intevation.de>
parents:
2462
diff
changeset
|
179 } else { |
24bab584f0a1
client: improved error message format for pdf-template uploads
Markus Kottlaender <markus@intevation.de>
parents:
2462
diff
changeset
|
180 displayError({ |
24bab584f0a1
client: improved error message format for pdf-template uploads
Markus Kottlaender <markus@intevation.de>
parents:
2462
diff
changeset
|
181 title: this.$gettext("Backend Error"), |
24bab584f0a1
client: improved error message format for pdf-template uploads
Markus Kottlaender <markus@intevation.de>
parents:
2462
diff
changeset
|
182 message: `${status}: ${data.message || data}` |
24bab584f0a1
client: improved error message format for pdf-template uploads
Markus Kottlaender <markus@intevation.de>
parents:
2462
diff
changeset
|
183 }); |
24bab584f0a1
client: improved error message format for pdf-template uploads
Markus Kottlaender <markus@intevation.de>
parents:
2462
diff
changeset
|
184 } |
2257
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
185 }) |
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
186 .finally(() => { |
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
187 this.uploading = false; |
2448
8044e379d8ee
client:pdf-gen template: give feedback after uploading template
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2384
diff
changeset
|
188 this.$refs.uploadTemplate.value = null; |
2257
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
189 }); |
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
190 } else { |
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
191 displayError({ |
2284
9f327f197ddd
client: translation: mark some strings for translations
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2257
diff
changeset
|
192 title: this.$gettext("Format Error"), |
9f327f197ddd
client: translation: mark some strings for translations
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2257
diff
changeset
|
193 message: this.$gettext( |
9f327f197ddd
client: translation: mark some strings for translations
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2257
diff
changeset
|
194 "The provided template has no name property." |
9f327f197ddd
client: translation: mark some strings for translations
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2257
diff
changeset
|
195 ) |
2257
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
196 }); |
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
197 } |
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
198 }; |
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
199 reader.onerror = error => console.log(error); |
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
200 reader.readAsText(this.$refs.uploadTemplate.files[0]); |
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
201 }, |
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
202 loadTemplates() { |
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
203 HTTP.get("/templates/print", { |
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
204 headers: { |
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
205 "X-Gemma-Auth": localStorage.getItem("token"), |
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
206 "Content-type": "text/xml; charset=UTF-8" |
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
207 } |
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
208 }) |
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
209 .then(response => { |
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
210 this.templates = response.data; |
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
211 }) |
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
212 .catch(e => { |
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
213 const { status, data } = e.response; |
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
214 displayError({ |
2284
9f327f197ddd
client: translation: mark some strings for translations
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2257
diff
changeset
|
215 title: this.$gettext("Backend Error"), |
2257
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
216 message: `${status}: ${data.message || data}` |
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
217 }); |
2216
585373d33f8f
prepared pdf template administration
Markus Kottlaender <markus@intevation.de>
parents:
2213
diff
changeset
|
218 }); |
585373d33f8f
prepared pdf template administration
Markus Kottlaender <markus@intevation.de>
parents:
2213
diff
changeset
|
219 }, |
2384
c06b001dc26b
client: improved popup implementation
Markus Kottlaender <markus@intevation.de>
parents:
2357
diff
changeset
|
220 deleteTemplate(template) { |
c06b001dc26b
client: improved popup implementation
Markus Kottlaender <markus@intevation.de>
parents:
2357
diff
changeset
|
221 this.$store.commit("application/popup", { |
c06b001dc26b
client: improved popup implementation
Markus Kottlaender <markus@intevation.de>
parents:
2357
diff
changeset
|
222 icon: "trash", |
c06b001dc26b
client: improved popup implementation
Markus Kottlaender <markus@intevation.de>
parents:
2357
diff
changeset
|
223 title: this.$gettext("Delete Template"), |
c06b001dc26b
client: improved popup implementation
Markus Kottlaender <markus@intevation.de>
parents:
2357
diff
changeset
|
224 content: |
c06b001dc26b
client: improved popup implementation
Markus Kottlaender <markus@intevation.de>
parents:
2357
diff
changeset
|
225 this.$gettext( |
c06b001dc26b
client: improved popup implementation
Markus Kottlaender <markus@intevation.de>
parents:
2357
diff
changeset
|
226 "Do you really want to delete the following template:" |
c06b001dc26b
client: improved popup implementation
Markus Kottlaender <markus@intevation.de>
parents:
2357
diff
changeset
|
227 ) + |
c06b001dc26b
client: improved popup implementation
Markus Kottlaender <markus@intevation.de>
parents:
2357
diff
changeset
|
228 `<br> |
c06b001dc26b
client: improved popup implementation
Markus Kottlaender <markus@intevation.de>
parents:
2357
diff
changeset
|
229 <b>${template.name}</b>`, |
c06b001dc26b
client: improved popup implementation
Markus Kottlaender <markus@intevation.de>
parents:
2357
diff
changeset
|
230 confirm: { |
c06b001dc26b
client: improved popup implementation
Markus Kottlaender <markus@intevation.de>
parents:
2357
diff
changeset
|
231 label: this.$gettext("Delete"), |
c06b001dc26b
client: improved popup implementation
Markus Kottlaender <markus@intevation.de>
parents:
2357
diff
changeset
|
232 icon: "trash", |
c06b001dc26b
client: improved popup implementation
Markus Kottlaender <markus@intevation.de>
parents:
2357
diff
changeset
|
233 callback: () => { |
c06b001dc26b
client: improved popup implementation
Markus Kottlaender <markus@intevation.de>
parents:
2357
diff
changeset
|
234 HTTP.delete("/templates/print/" + template.name, { |
c06b001dc26b
client: improved popup implementation
Markus Kottlaender <markus@intevation.de>
parents:
2357
diff
changeset
|
235 headers: { |
c06b001dc26b
client: improved popup implementation
Markus Kottlaender <markus@intevation.de>
parents:
2357
diff
changeset
|
236 "X-Gemma-Auth": localStorage.getItem("token"), |
c06b001dc26b
client: improved popup implementation
Markus Kottlaender <markus@intevation.de>
parents:
2357
diff
changeset
|
237 "Content-type": "text/xml; charset=UTF-8" |
c06b001dc26b
client: improved popup implementation
Markus Kottlaender <markus@intevation.de>
parents:
2357
diff
changeset
|
238 } |
c06b001dc26b
client: improved popup implementation
Markus Kottlaender <markus@intevation.de>
parents:
2357
diff
changeset
|
239 }).then(() => { |
c06b001dc26b
client: improved popup implementation
Markus Kottlaender <markus@intevation.de>
parents:
2357
diff
changeset
|
240 let removeIndex = this.templates.findIndex( |
c06b001dc26b
client: improved popup implementation
Markus Kottlaender <markus@intevation.de>
parents:
2357
diff
changeset
|
241 t => t.name === template.name |
c06b001dc26b
client: improved popup implementation
Markus Kottlaender <markus@intevation.de>
parents:
2357
diff
changeset
|
242 ); |
c06b001dc26b
client: improved popup implementation
Markus Kottlaender <markus@intevation.de>
parents:
2357
diff
changeset
|
243 if (removeIndex !== -1) { |
c06b001dc26b
client: improved popup implementation
Markus Kottlaender <markus@intevation.de>
parents:
2357
diff
changeset
|
244 this.templates.splice(removeIndex, 1); |
2459
408e0f4d4008
clinet:pdf-gen template:unifiy feedback messages for template
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2448
diff
changeset
|
245 displayInfo({ |
408e0f4d4008
clinet:pdf-gen template:unifiy feedback messages for template
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2448
diff
changeset
|
246 message: |
408e0f4d4008
clinet:pdf-gen template:unifiy feedback messages for template
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2448
diff
changeset
|
247 template.name + " " + this.$gettext("deleted successfully") |
408e0f4d4008
clinet:pdf-gen template:unifiy feedback messages for template
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2448
diff
changeset
|
248 }); |
2384
c06b001dc26b
client: improved popup implementation
Markus Kottlaender <markus@intevation.de>
parents:
2357
diff
changeset
|
249 } |
c06b001dc26b
client: improved popup implementation
Markus Kottlaender <markus@intevation.de>
parents:
2357
diff
changeset
|
250 }); |
c06b001dc26b
client: improved popup implementation
Markus Kottlaender <markus@intevation.de>
parents:
2357
diff
changeset
|
251 } |
c06b001dc26b
client: improved popup implementation
Markus Kottlaender <markus@intevation.de>
parents:
2357
diff
changeset
|
252 }, |
c06b001dc26b
client: improved popup implementation
Markus Kottlaender <markus@intevation.de>
parents:
2357
diff
changeset
|
253 cancel: { |
c06b001dc26b
client: improved popup implementation
Markus Kottlaender <markus@intevation.de>
parents:
2357
diff
changeset
|
254 label: this.$gettext("Cancel"), |
c06b001dc26b
client: improved popup implementation
Markus Kottlaender <markus@intevation.de>
parents:
2357
diff
changeset
|
255 icon: "times" |
2257
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
256 } |
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
257 }); |
2216
585373d33f8f
prepared pdf template administration
Markus Kottlaender <markus@intevation.de>
parents:
2213
diff
changeset
|
258 } |
2247
e6fba449aa3c
merged pdf-export in default
Markus Kottlaender <markus@intevation.de>
parents:
2216
diff
changeset
|
259 }, |
e6fba449aa3c
merged pdf-export in default
Markus Kottlaender <markus@intevation.de>
parents:
2216
diff
changeset
|
260 mounted() { |
2257
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
261 this.loadTemplates(); |
2213 | 262 } |
263 }; | |
264 </script> |