Mercurial > gemma
annotate client/src/components/systemconfiguration/PDFTemplates.vue @ 5588:94ef43fac0eb surveysperbottleneckid
Make BN for overview distinguishable
author | Thomas Junk <thomas.junk@intevation.de> |
---|---|
date | Tue, 05 Apr 2022 10:15:37 +0200 |
parents | 6b054b91d9b2 |
children | 7768f14f6535 |
rev | line source |
---|---|
2213 | 1 <template> |
3889
851c0ccba59b
client: configuration: separated sections in tabs
Markus Kottlaender <markus@intevation.de>
parents:
3608
diff
changeset
|
2 <div class="d-flex flex-column pb-4"> |
3597
d1bbfb9635ca
client: configuration: unified styles of different config components
Markus Kottlaender <markus@intevation.de>
parents:
3594
diff
changeset
|
3 <input |
d1bbfb9635ca
client: configuration: unified styles of different config components
Markus Kottlaender <markus@intevation.de>
parents:
3594
diff
changeset
|
4 @change="uploadTemplate" |
d1bbfb9635ca
client: configuration: unified styles of different config components
Markus Kottlaender <markus@intevation.de>
parents:
3594
diff
changeset
|
5 id="uploadTemplate" |
d1bbfb9635ca
client: configuration: unified styles of different config components
Markus Kottlaender <markus@intevation.de>
parents:
3594
diff
changeset
|
6 ref="uploadTemplate" |
d1bbfb9635ca
client: configuration: unified styles of different config components
Markus Kottlaender <markus@intevation.de>
parents:
3594
diff
changeset
|
7 type="file" |
d1bbfb9635ca
client: configuration: unified styles of different config components
Markus Kottlaender <markus@intevation.de>
parents:
3594
diff
changeset
|
8 style="visibility: hidden; position: absolute;" |
d1bbfb9635ca
client: configuration: unified styles of different config components
Markus Kottlaender <markus@intevation.de>
parents:
3594
diff
changeset
|
9 /> |
d1bbfb9635ca
client: configuration: unified styles of different config components
Markus Kottlaender <markus@intevation.de>
parents:
3594
diff
changeset
|
10 <UITableHeader |
d1bbfb9635ca
client: configuration: unified styles of different config components
Markus Kottlaender <markus@intevation.de>
parents:
3594
diff
changeset
|
11 :columns="[ |
d1bbfb9635ca
client: configuration: unified styles of different config components
Markus Kottlaender <markus@intevation.de>
parents:
3594
diff
changeset
|
12 { id: 'name', title: `${nameLabel}`, class: 'col-3' }, |
d1bbfb9635ca
client: configuration: unified styles of different config components
Markus Kottlaender <markus@intevation.de>
parents:
3594
diff
changeset
|
13 { id: 'time', title: `${dateLabel}`, class: 'col-3' }, |
d1bbfb9635ca
client: configuration: unified styles of different config components
Markus Kottlaender <markus@intevation.de>
parents:
3594
diff
changeset
|
14 { id: 'type', title: `${typeLabel}`, class: 'col-2' }, |
d1bbfb9635ca
client: configuration: unified styles of different config components
Markus Kottlaender <markus@intevation.de>
parents:
3594
diff
changeset
|
15 { id: 'country', title: `${countryLabel}`, class: 'col-2' } |
d1bbfb9635ca
client: configuration: unified styles of different config components
Markus Kottlaender <markus@intevation.de>
parents:
3594
diff
changeset
|
16 ]" |
d1bbfb9635ca
client: configuration: unified styles of different config components
Markus Kottlaender <markus@intevation.de>
parents:
3594
diff
changeset
|
17 /> |
d1bbfb9635ca
client: configuration: unified styles of different config components
Markus Kottlaender <markus@intevation.de>
parents:
3594
diff
changeset
|
18 <UITableBody :data="templates | sortTable(sortColumn, sortDirection)"> |
d1bbfb9635ca
client: configuration: unified styles of different config components
Markus Kottlaender <markus@intevation.de>
parents:
3594
diff
changeset
|
19 <template v-slot:row="{ item: template }"> |
d1bbfb9635ca
client: configuration: unified styles of different config components
Markus Kottlaender <markus@intevation.de>
parents:
3594
diff
changeset
|
20 <div class="py-1 col-3">{{ template.name }}</div> |
d1bbfb9635ca
client: configuration: unified styles of different config components
Markus Kottlaender <markus@intevation.de>
parents:
3594
diff
changeset
|
21 <div class="py-1 col-3">{{ template.time }}</div> |
d1bbfb9635ca
client: configuration: unified styles of different config components
Markus Kottlaender <markus@intevation.de>
parents:
3594
diff
changeset
|
22 <div class="py-1 col-2">{{ template.type }}</div> |
d1bbfb9635ca
client: configuration: unified styles of different config components
Markus Kottlaender <markus@intevation.de>
parents:
3594
diff
changeset
|
23 <div class="py-1 col-2" v-if="template.country"> |
d1bbfb9635ca
client: configuration: unified styles of different config components
Markus Kottlaender <markus@intevation.de>
parents:
3594
diff
changeset
|
24 {{ template.country }} |
d1bbfb9635ca
client: configuration: unified styles of different config components
Markus Kottlaender <markus@intevation.de>
parents:
3594
diff
changeset
|
25 </div> |
d1bbfb9635ca
client: configuration: unified styles of different config components
Markus Kottlaender <markus@intevation.de>
parents:
3594
diff
changeset
|
26 <div class="py-1 col-2" v-else><i>global</i></div> |
d1bbfb9635ca
client: configuration: unified styles of different config components
Markus Kottlaender <markus@intevation.de>
parents:
3594
diff
changeset
|
27 <div class="col py-1 text-right"> |
d1bbfb9635ca
client: configuration: unified styles of different config components
Markus Kottlaender <markus@intevation.de>
parents:
3594
diff
changeset
|
28 <button |
d1bbfb9635ca
client: configuration: unified styles of different config components
Markus Kottlaender <markus@intevation.de>
parents:
3594
diff
changeset
|
29 class="btn btn-xs btn-info mr-1" |
d1bbfb9635ca
client: configuration: unified styles of different config components
Markus Kottlaender <markus@intevation.de>
parents:
3594
diff
changeset
|
30 ref="downloadTemplate" |
d1bbfb9635ca
client: configuration: unified styles of different config components
Markus Kottlaender <markus@intevation.de>
parents:
3594
diff
changeset
|
31 @click="downloadTemplate(template)" |
d1bbfb9635ca
client: configuration: unified styles of different config components
Markus Kottlaender <markus@intevation.de>
parents:
3594
diff
changeset
|
32 > |
d1bbfb9635ca
client: configuration: unified styles of different config components
Markus Kottlaender <markus@intevation.de>
parents:
3594
diff
changeset
|
33 <font-awesome-icon icon="download" fixed-width /> |
d1bbfb9635ca
client: configuration: unified styles of different config components
Markus Kottlaender <markus@intevation.de>
parents:
3594
diff
changeset
|
34 </button> |
d1bbfb9635ca
client: configuration: unified styles of different config components
Markus Kottlaender <markus@intevation.de>
parents:
3594
diff
changeset
|
35 <button class="btn btn-xs btn-dark" @click="deleteTemplate(template)"> |
d1bbfb9635ca
client: configuration: unified styles of different config components
Markus Kottlaender <markus@intevation.de>
parents:
3594
diff
changeset
|
36 <font-awesome-icon icon="trash" fixed-width /> |
d1bbfb9635ca
client: configuration: unified styles of different config components
Markus Kottlaender <markus@intevation.de>
parents:
3594
diff
changeset
|
37 </button> |
d1bbfb9635ca
client: configuration: unified styles of different config components
Markus Kottlaender <markus@intevation.de>
parents:
3594
diff
changeset
|
38 </div> |
d1bbfb9635ca
client: configuration: unified styles of different config components
Markus Kottlaender <markus@intevation.de>
parents:
3594
diff
changeset
|
39 </template> |
d1bbfb9635ca
client: configuration: unified styles of different config components
Markus Kottlaender <markus@intevation.de>
parents:
3594
diff
changeset
|
40 </UITableBody> |
3889
851c0ccba59b
client: configuration: separated sections in tabs
Markus Kottlaender <markus@intevation.de>
parents:
3608
diff
changeset
|
41 <div class="p-3 border-top"> |
3597
d1bbfb9635ca
client: configuration: unified styles of different config components
Markus Kottlaender <markus@intevation.de>
parents:
3594
diff
changeset
|
42 <button |
d1bbfb9635ca
client: configuration: unified styles of different config components
Markus Kottlaender <markus@intevation.de>
parents:
3594
diff
changeset
|
43 class="btn btn-info btn-sm mr-2" |
d1bbfb9635ca
client: configuration: unified styles of different config components
Markus Kottlaender <markus@intevation.de>
parents:
3594
diff
changeset
|
44 @click=" |
d1bbfb9635ca
client: configuration: unified styles of different config components
Markus Kottlaender <markus@intevation.de>
parents:
3594
diff
changeset
|
45 type = 'map'; |
d1bbfb9635ca
client: configuration: unified styles of different config components
Markus Kottlaender <markus@intevation.de>
parents:
3594
diff
changeset
|
46 $refs.uploadTemplate.click(); |
d1bbfb9635ca
client: configuration: unified styles of different config components
Markus Kottlaender <markus@intevation.de>
parents:
3594
diff
changeset
|
47 " |
d1bbfb9635ca
client: configuration: unified styles of different config components
Markus Kottlaender <markus@intevation.de>
parents:
3594
diff
changeset
|
48 > |
d1bbfb9635ca
client: configuration: unified styles of different config components
Markus Kottlaender <markus@intevation.de>
parents:
3594
diff
changeset
|
49 <font-awesome-icon |
d1bbfb9635ca
client: configuration: unified styles of different config components
Markus Kottlaender <markus@intevation.de>
parents:
3594
diff
changeset
|
50 icon="spinner" |
d1bbfb9635ca
client: configuration: unified styles of different config components
Markus Kottlaender <markus@intevation.de>
parents:
3594
diff
changeset
|
51 class="fa-spin fa-fw" |
d1bbfb9635ca
client: configuration: unified styles of different config components
Markus Kottlaender <markus@intevation.de>
parents:
3594
diff
changeset
|
52 v-if="uploading" |
d1bbfb9635ca
client: configuration: unified styles of different config components
Markus Kottlaender <markus@intevation.de>
parents:
3594
diff
changeset
|
53 /> |
d1bbfb9635ca
client: configuration: unified styles of different config components
Markus Kottlaender <markus@intevation.de>
parents:
3594
diff
changeset
|
54 <font-awesome-icon icon="upload" class="fa-fw" v-else /> |
d1bbfb9635ca
client: configuration: unified styles of different config components
Markus Kottlaender <markus@intevation.de>
parents:
3594
diff
changeset
|
55 <translate>Upload new map template</translate> |
d1bbfb9635ca
client: configuration: unified styles of different config components
Markus Kottlaender <markus@intevation.de>
parents:
3594
diff
changeset
|
56 </button> |
d1bbfb9635ca
client: configuration: unified styles of different config components
Markus Kottlaender <markus@intevation.de>
parents:
3594
diff
changeset
|
57 <button |
d1bbfb9635ca
client: configuration: unified styles of different config components
Markus Kottlaender <markus@intevation.de>
parents:
3594
diff
changeset
|
58 class="btn btn-info btn-sm" |
d1bbfb9635ca
client: configuration: unified styles of different config components
Markus Kottlaender <markus@intevation.de>
parents:
3594
diff
changeset
|
59 @click=" |
d1bbfb9635ca
client: configuration: unified styles of different config components
Markus Kottlaender <markus@intevation.de>
parents:
3594
diff
changeset
|
60 type = 'diagram'; |
d1bbfb9635ca
client: configuration: unified styles of different config components
Markus Kottlaender <markus@intevation.de>
parents:
3594
diff
changeset
|
61 $refs.uploadTemplate.click(); |
d1bbfb9635ca
client: configuration: unified styles of different config components
Markus Kottlaender <markus@intevation.de>
parents:
3594
diff
changeset
|
62 " |
d1bbfb9635ca
client: configuration: unified styles of different config components
Markus Kottlaender <markus@intevation.de>
parents:
3594
diff
changeset
|
63 > |
d1bbfb9635ca
client: configuration: unified styles of different config components
Markus Kottlaender <markus@intevation.de>
parents:
3594
diff
changeset
|
64 <font-awesome-icon |
d1bbfb9635ca
client: configuration: unified styles of different config components
Markus Kottlaender <markus@intevation.de>
parents:
3594
diff
changeset
|
65 icon="spinner" |
d1bbfb9635ca
client: configuration: unified styles of different config components
Markus Kottlaender <markus@intevation.de>
parents:
3594
diff
changeset
|
66 class="fa-spin fa-fw" |
d1bbfb9635ca
client: configuration: unified styles of different config components
Markus Kottlaender <markus@intevation.de>
parents:
3594
diff
changeset
|
67 v-if="uploading" |
d1bbfb9635ca
client: configuration: unified styles of different config components
Markus Kottlaender <markus@intevation.de>
parents:
3594
diff
changeset
|
68 /> |
d1bbfb9635ca
client: configuration: unified styles of different config components
Markus Kottlaender <markus@intevation.de>
parents:
3594
diff
changeset
|
69 <font-awesome-icon icon="upload" class="fa-fw" v-else /> |
d1bbfb9635ca
client: configuration: unified styles of different config components
Markus Kottlaender <markus@intevation.de>
parents:
3594
diff
changeset
|
70 <translate>Upload new diagram template</translate> |
d1bbfb9635ca
client: configuration: unified styles of different config components
Markus Kottlaender <markus@intevation.de>
parents:
3594
diff
changeset
|
71 </button> |
2213 | 72 </div> |
73 </div> | |
74 </template> | |
75 | |
2323
5b53be76080c
client: adjusted table and delete button styles
Markus Kottlaender <markus@intevation.de>
parents:
2290
diff
changeset
|
76 <style lang="scss" scoped> |
5b53be76080c
client: adjusted table and delete button styles
Markus Kottlaender <markus@intevation.de>
parents:
2290
diff
changeset
|
77 .table th, |
5b53be76080c
client: adjusted table and delete button styles
Markus Kottlaender <markus@intevation.de>
parents:
2290
diff
changeset
|
78 td { |
5b53be76080c
client: adjusted table and delete button styles
Markus Kottlaender <markus@intevation.de>
parents:
2290
diff
changeset
|
79 font-size: $smaller; |
5b53be76080c
client: adjusted table and delete button styles
Markus Kottlaender <markus@intevation.de>
parents:
2290
diff
changeset
|
80 border-top: 0px !important; |
5b53be76080c
client: adjusted table and delete button styles
Markus Kottlaender <markus@intevation.de>
parents:
2290
diff
changeset
|
81 text-align: left; |
5b53be76080c
client: adjusted table and delete button styles
Markus Kottlaender <markus@intevation.de>
parents:
2290
diff
changeset
|
82 padding: $small-offset !important; |
5b53be76080c
client: adjusted table and delete button styles
Markus Kottlaender <markus@intevation.de>
parents:
2290
diff
changeset
|
83 } |
5b53be76080c
client: adjusted table and delete button styles
Markus Kottlaender <markus@intevation.de>
parents:
2290
diff
changeset
|
84 </style> |
5b53be76080c
client: adjusted table and delete button styles
Markus Kottlaender <markus@intevation.de>
parents:
2290
diff
changeset
|
85 |
2213 | 86 <script> |
87 /* This is Free Software under GNU Affero General Public License v >= 3.0 | |
88 * without warranty, see README.md and license for details. | |
89 * | |
90 * SPDX-License-Identifier: AGPL-3.0-or-later | |
91 * License-Filename: LICENSES/AGPL-3.0.txt | |
92 * | |
2527
1a6553da9078
client:pdf-gen : add download-template functionality
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2522
diff
changeset
|
93 * Copyright (C) 2018, 2019 by via donau |
2213 | 94 * – Österreichische Wasserstraßen-Gesellschaft mbH |
95 * Software engineering by Intevation GmbH | |
96 * | |
97 * Author(s): | |
98 * 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
|
99 * Fadi Abbud <fadi.abbud@intevation.de> |
2213 | 100 */ |
2257
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
101 import { HTTP } from "@/lib/http"; |
2738
add2d47c2567
client: tables: implemented simple default sorting
Markus Kottlaender <markus@intevation.de>
parents:
2640
diff
changeset
|
102 import { displayError, displayInfo } from "@/lib/errors"; |
add2d47c2567
client: tables: implemented simple default sorting
Markus Kottlaender <markus@intevation.de>
parents:
2640
diff
changeset
|
103 import { sortTable } from "@/lib/mixins"; |
2213 | 104 |
105 export default { | |
106 name: "pdftemplates", | |
2738
add2d47c2567
client: tables: implemented simple default sorting
Markus Kottlaender <markus@intevation.de>
parents:
2640
diff
changeset
|
107 mixins: [sortTable], |
2216
585373d33f8f
prepared pdf template administration
Markus Kottlaender <markus@intevation.de>
parents:
2213
diff
changeset
|
108 data() { |
585373d33f8f
prepared pdf template administration
Markus Kottlaender <markus@intevation.de>
parents:
2213
diff
changeset
|
109 return { |
2257
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
110 templates: [], |
3227
6d4d8e7ef881
client: adjust route for pdftemplate,pdftool and add check type to uploaded templates
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3222
diff
changeset
|
111 uploading: false, |
3243
e9c143436432
client: diagram-template: improve Pdf-templates systemconfiguration
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3234
diff
changeset
|
112 type: null |
2216
585373d33f8f
prepared pdf template administration
Markus Kottlaender <markus@intevation.de>
parents:
2213
diff
changeset
|
113 }; |
585373d33f8f
prepared pdf template administration
Markus Kottlaender <markus@intevation.de>
parents:
2213
diff
changeset
|
114 }, |
2782
615b0a9b8098
Client: correct strings marking for translations
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2738
diff
changeset
|
115 computed: { |
615b0a9b8098
Client: correct strings marking for translations
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2738
diff
changeset
|
116 nameLabel() { |
615b0a9b8098
Client: correct strings marking for translations
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2738
diff
changeset
|
117 return this.$gettext("Name"); |
615b0a9b8098
Client: correct strings marking for translations
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2738
diff
changeset
|
118 }, |
615b0a9b8098
Client: correct strings marking for translations
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2738
diff
changeset
|
119 dateLabel() { |
615b0a9b8098
Client: correct strings marking for translations
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2738
diff
changeset
|
120 return this.$gettext("Date"); |
615b0a9b8098
Client: correct strings marking for translations
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2738
diff
changeset
|
121 }, |
615b0a9b8098
Client: correct strings marking for translations
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2738
diff
changeset
|
122 countryLabel() { |
615b0a9b8098
Client: correct strings marking for translations
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2738
diff
changeset
|
123 return this.$gettext("Country"); |
3232
86231e847762
client: add type field for pdf-templates configuration
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3230
diff
changeset
|
124 }, |
86231e847762
client: add type field for pdf-templates configuration
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3230
diff
changeset
|
125 typeLabel() { |
3234 | 126 return this.$gettext("Type"); |
2782
615b0a9b8098
Client: correct strings marking for translations
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2738
diff
changeset
|
127 } |
615b0a9b8098
Client: correct strings marking for translations
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2738
diff
changeset
|
128 }, |
2216
585373d33f8f
prepared pdf template administration
Markus Kottlaender <markus@intevation.de>
parents:
2213
diff
changeset
|
129 methods: { |
2527
1a6553da9078
client:pdf-gen : add download-template functionality
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2522
diff
changeset
|
130 downloadTemplate(template) { |
1a6553da9078
client:pdf-gen : add download-template functionality
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2522
diff
changeset
|
131 if (template) { |
1a6553da9078
client:pdf-gen : add download-template functionality
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2522
diff
changeset
|
132 var templateData = ""; |
1a6553da9078
client:pdf-gen : add download-template functionality
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2522
diff
changeset
|
133 var element = document.createElement("a"); |
1a6553da9078
client:pdf-gen : add download-template functionality
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2522
diff
changeset
|
134 element.style.display = "none"; |
1a6553da9078
client:pdf-gen : add download-template functionality
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2522
diff
changeset
|
135 element.setAttribute("download", template.name + ".json"); |
1a6553da9078
client:pdf-gen : add download-template functionality
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2522
diff
changeset
|
136 document.body.appendChild(element); |
4632
2e47b32a389d
client: encode strings in url paths
Fadi Abbud <fadi.abbud@intevation.de>
parents:
4454
diff
changeset
|
137 HTTP.get( |
2e47b32a389d
client: encode strings in url paths
Fadi Abbud <fadi.abbud@intevation.de>
parents:
4454
diff
changeset
|
138 `/templates/${template.type}/${encodeURIComponent(template.name)}`, |
2e47b32a389d
client: encode strings in url paths
Fadi Abbud <fadi.abbud@intevation.de>
parents:
4454
diff
changeset
|
139 { |
2e47b32a389d
client: encode strings in url paths
Fadi Abbud <fadi.abbud@intevation.de>
parents:
4454
diff
changeset
|
140 headers: { |
2e47b32a389d
client: encode strings in url paths
Fadi Abbud <fadi.abbud@intevation.de>
parents:
4454
diff
changeset
|
141 "X-Gemma-Auth": localStorage.getItem("token"), |
2e47b32a389d
client: encode strings in url paths
Fadi Abbud <fadi.abbud@intevation.de>
parents:
4454
diff
changeset
|
142 "Content-type": "text/xml; charset=UTF-8" |
2e47b32a389d
client: encode strings in url paths
Fadi Abbud <fadi.abbud@intevation.de>
parents:
4454
diff
changeset
|
143 } |
2527
1a6553da9078
client:pdf-gen : add download-template functionality
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2522
diff
changeset
|
144 } |
4632
2e47b32a389d
client: encode strings in url paths
Fadi Abbud <fadi.abbud@intevation.de>
parents:
4454
diff
changeset
|
145 ) |
2527
1a6553da9078
client:pdf-gen : add download-template functionality
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2522
diff
changeset
|
146 .then(response => { |
1a6553da9078
client:pdf-gen : add download-template functionality
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2522
diff
changeset
|
147 templateData = response.data.template_data; |
1a6553da9078
client:pdf-gen : add download-template functionality
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2522
diff
changeset
|
148 element.setAttribute( |
1a6553da9078
client:pdf-gen : add download-template functionality
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2522
diff
changeset
|
149 "href", |
1a6553da9078
client:pdf-gen : add download-template functionality
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2522
diff
changeset
|
150 "data:text/json;charset=utf-8," + |
1a6553da9078
client:pdf-gen : add download-template functionality
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2522
diff
changeset
|
151 encodeURIComponent( |
2531
47b9a4f9a05c
client:pdf-gen: change the formatting of the downloaded json file
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2527
diff
changeset
|
152 JSON.stringify( |
47b9a4f9a05c
client:pdf-gen: change the formatting of the downloaded json file
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2527
diff
changeset
|
153 { |
47b9a4f9a05c
client:pdf-gen: change the formatting of the downloaded json file
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2527
diff
changeset
|
154 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
|
155 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
|
156 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
|
157 }, |
47b9a4f9a05c
client:pdf-gen: change the formatting of the downloaded json file
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2527
diff
changeset
|
158 null, |
47b9a4f9a05c
client:pdf-gen: change the formatting of the downloaded json file
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2527
diff
changeset
|
159 2 |
47b9a4f9a05c
client:pdf-gen: change the formatting of the downloaded json file
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2527
diff
changeset
|
160 ) |
2527
1a6553da9078
client:pdf-gen : add download-template functionality
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2522
diff
changeset
|
161 ) |
1a6553da9078
client:pdf-gen : add download-template functionality
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2522
diff
changeset
|
162 ); |
1a6553da9078
client:pdf-gen : add download-template functionality
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2522
diff
changeset
|
163 element.click(); |
1a6553da9078
client:pdf-gen : add download-template functionality
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2522
diff
changeset
|
164 }) |
4868
008bc1ae8897
exception handling
Thomas Junk <thomas.junk@intevation.de>
parents:
4632
diff
changeset
|
165 .catch(error => { |
4869
6b054b91d9b2
backend not reachable as error message etd. Login adjusted
Thomas Junk <thomas.junk@intevation.de>
parents:
4868
diff
changeset
|
166 let message = "Backend not reachable"; |
4868
008bc1ae8897
exception handling
Thomas Junk <thomas.junk@intevation.de>
parents:
4632
diff
changeset
|
167 if (error.response) { |
008bc1ae8897
exception handling
Thomas Junk <thomas.junk@intevation.de>
parents:
4632
diff
changeset
|
168 const { status, data } = error.response; |
008bc1ae8897
exception handling
Thomas Junk <thomas.junk@intevation.de>
parents:
4632
diff
changeset
|
169 message = `${status}: ${data.message || data}`; |
008bc1ae8897
exception handling
Thomas Junk <thomas.junk@intevation.de>
parents:
4632
diff
changeset
|
170 } |
2527
1a6553da9078
client:pdf-gen : add download-template functionality
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2522
diff
changeset
|
171 displayError({ |
1a6553da9078
client:pdf-gen : add download-template functionality
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2522
diff
changeset
|
172 title: this.$gettext("Backend Error"), |
4868
008bc1ae8897
exception handling
Thomas Junk <thomas.junk@intevation.de>
parents:
4632
diff
changeset
|
173 message: message |
2527
1a6553da9078
client:pdf-gen : add download-template functionality
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2522
diff
changeset
|
174 }); |
1a6553da9078
client:pdf-gen : add download-template functionality
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2522
diff
changeset
|
175 }) |
1a6553da9078
client:pdf-gen : add download-template functionality
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2522
diff
changeset
|
176 .finally(() => { |
1a6553da9078
client:pdf-gen : add download-template functionality
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2522
diff
changeset
|
177 document.body.removeChild(element); |
1a6553da9078
client:pdf-gen : add download-template functionality
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2522
diff
changeset
|
178 }); |
1a6553da9078
client:pdf-gen : add download-template functionality
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2522
diff
changeset
|
179 } |
1a6553da9078
client:pdf-gen : add download-template functionality
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2522
diff
changeset
|
180 }, |
2384
c06b001dc26b
client: improved popup implementation
Markus Kottlaender <markus@intevation.de>
parents:
2357
diff
changeset
|
181 uploadTemplate() { |
2257
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
182 const reader = new FileReader(); |
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
183 reader.onload = event => { |
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
184 let template; |
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
185 try { |
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
186 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
|
187 } catch (e) { |
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
188 displayError({ |
2284
9f327f197ddd
client: translation: mark some strings for translations
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2257
diff
changeset
|
189 title: this.$gettext("Format Error"), |
9f327f197ddd
client: translation: mark some strings for translations
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2257
diff
changeset
|
190 message: this.$gettext( |
9f327f197ddd
client: translation: mark some strings for translations
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2257
diff
changeset
|
191 "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
|
192 ) |
2257
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
193 }); |
3243
e9c143436432
client: diagram-template: improve Pdf-templates systemconfiguration
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3234
diff
changeset
|
194 // allow the user to upload the same file |
e9c143436432
client: diagram-template: improve Pdf-templates systemconfiguration
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3234
diff
changeset
|
195 // if user wants to upload the same file after edit it. |
2802
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
196 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
|
197 } |
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
198 if (template.name) { |
3243
e9c143436432
client: diagram-template: improve Pdf-templates systemconfiguration
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3234
diff
changeset
|
199 // check if an element in the uploaded file does not match the predefind template-elements |
2802
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
200 let checkElement = false; |
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
201 template.elements.forEach(e => { |
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
202 if ( |
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
203 [ |
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
204 "text", |
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
205 "box", |
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
206 "textbox", |
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
207 "image", |
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
208 "bottleneck", |
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
209 "legend", |
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
210 "scalebar", |
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
211 "scale", |
3138
106e1d011a5d
client: pdf-gen: include the diagram elements in the upload template constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2874
diff
changeset
|
212 "northarrow", |
106e1d011a5d
client: pdf-gen: include the diagram elements in the upload template constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2874
diff
changeset
|
213 "diagramlegend", |
3160
94935895e6d7
client: add diagram-element to template (waterlevel)
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3138
diff
changeset
|
214 "diagramtitle", |
94935895e6d7
client: add diagram-element to template (waterlevel)
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3138
diff
changeset
|
215 "diagram" |
2802
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
216 ].indexOf(e.type) === -1 |
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
217 ) { |
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
218 checkElement = true; |
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
219 displayError({ |
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
220 title: this.$gettext("Invalid element"), |
2459
408e0f4d4008
clinet:pdf-gen template:unifiy feedback messages for template
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2448
diff
changeset
|
221 message: |
2802
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
222 e.type + |
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
223 this.$gettext(" does not match any template's element") |
2459
408e0f4d4008
clinet:pdf-gen template:unifiy feedback messages for template
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2448
diff
changeset
|
224 }); |
3243
e9c143436432
client: diagram-template: improve Pdf-templates systemconfiguration
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3234
diff
changeset
|
225 // allow the user to upload the same file |
2802
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
226 this.$refs.uploadTemplate.value = null; |
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
227 } |
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
228 }); |
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
229 |
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
230 if (!checkElement) { |
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
231 this.uploading = true; |
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
232 HTTP.post( |
3227
6d4d8e7ef881
client: adjust route for pdftemplate,pdftool and add check type to uploaded templates
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3222
diff
changeset
|
233 "/templates/" + this.type + "/" + template.name, |
2802
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
234 { |
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
235 template_name: template.name, |
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
236 template_data: template |
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
237 }, |
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
238 { |
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
239 headers: { |
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
240 "X-Gemma-Auth": localStorage.getItem("token"), |
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
241 "Content-type": "text/xml; charset=UTF-8" |
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
242 } |
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
243 } |
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
244 ) |
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
245 .then(() => { |
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
246 this.loadTemplates(); |
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
247 displayInfo({ |
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
248 message: |
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
249 template.name + " " + this.$gettext("uploaded successfully") |
2522
24bab584f0a1
client: improved error message format for pdf-template uploads
Markus Kottlaender <markus@intevation.de>
parents:
2462
diff
changeset
|
250 }); |
2802
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
251 }) |
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
252 .catch(e => { |
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
253 const { status, data } = e.response; |
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
254 if (status === 400) { |
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
255 displayError({ |
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
256 title: this.$gettext("Error"), |
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
257 message: `${data.message || data}` |
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
258 }); |
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
259 } else { |
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
260 displayError({ |
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
261 title: this.$gettext("Backend Error"), |
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
262 message: `${status}: ${data.message || data}` |
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
263 }); |
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
264 } |
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
265 }) |
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
266 .finally(() => { |
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
267 this.uploading = false; |
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
268 this.$refs.uploadTemplate.value = null; |
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
269 }); |
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
270 } |
2257
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
271 } else { |
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
272 displayError({ |
2284
9f327f197ddd
client: translation: mark some strings for translations
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2257
diff
changeset
|
273 title: this.$gettext("Format Error"), |
9f327f197ddd
client: translation: mark some strings for translations
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2257
diff
changeset
|
274 message: this.$gettext( |
9f327f197ddd
client: translation: mark some strings for translations
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2257
diff
changeset
|
275 "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
|
276 ) |
2257
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
277 }); |
3243
e9c143436432
client: diagram-template: improve Pdf-templates systemconfiguration
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3234
diff
changeset
|
278 // allow the user to upload the same file |
2802
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
279 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
|
280 } |
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
281 }; |
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
282 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
|
283 }, |
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
284 loadTemplates() { |
3222
83e8e1ea0aff
print_templates: changed route /templates/print to /templates and /templates/print/... to /templates/
Thomas Junk <thomas.junk@intevation.de>
parents:
3160
diff
changeset
|
285 HTTP.get("/templates", { |
2257
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
286 headers: { |
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
287 "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
|
288 "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
|
289 } |
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
290 }) |
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
291 .then(response => { |
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
292 this.templates = response.data; |
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
293 }) |
4868
008bc1ae8897
exception handling
Thomas Junk <thomas.junk@intevation.de>
parents:
4632
diff
changeset
|
294 .catch(error => { |
4869
6b054b91d9b2
backend not reachable as error message etd. Login adjusted
Thomas Junk <thomas.junk@intevation.de>
parents:
4868
diff
changeset
|
295 let message = "Backend not reachable"; |
4868
008bc1ae8897
exception handling
Thomas Junk <thomas.junk@intevation.de>
parents:
4632
diff
changeset
|
296 if (error.response) { |
008bc1ae8897
exception handling
Thomas Junk <thomas.junk@intevation.de>
parents:
4632
diff
changeset
|
297 const { status, data } = error.response; |
008bc1ae8897
exception handling
Thomas Junk <thomas.junk@intevation.de>
parents:
4632
diff
changeset
|
298 message = `${status}: ${data.message || data}`; |
008bc1ae8897
exception handling
Thomas Junk <thomas.junk@intevation.de>
parents:
4632
diff
changeset
|
299 } |
2257
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
300 displayError({ |
2284
9f327f197ddd
client: translation: mark some strings for translations
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2257
diff
changeset
|
301 title: this.$gettext("Backend Error"), |
4868
008bc1ae8897
exception handling
Thomas Junk <thomas.junk@intevation.de>
parents:
4632
diff
changeset
|
302 message: message |
2257
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
303 }); |
2216
585373d33f8f
prepared pdf template administration
Markus Kottlaender <markus@intevation.de>
parents:
2213
diff
changeset
|
304 }); |
585373d33f8f
prepared pdf template administration
Markus Kottlaender <markus@intevation.de>
parents:
2213
diff
changeset
|
305 }, |
2384
c06b001dc26b
client: improved popup implementation
Markus Kottlaender <markus@intevation.de>
parents:
2357
diff
changeset
|
306 deleteTemplate(template) { |
c06b001dc26b
client: improved popup implementation
Markus Kottlaender <markus@intevation.de>
parents:
2357
diff
changeset
|
307 this.$store.commit("application/popup", { |
c06b001dc26b
client: improved popup implementation
Markus Kottlaender <markus@intevation.de>
parents:
2357
diff
changeset
|
308 icon: "trash", |
c06b001dc26b
client: improved popup implementation
Markus Kottlaender <markus@intevation.de>
parents:
2357
diff
changeset
|
309 title: this.$gettext("Delete Template"), |
c06b001dc26b
client: improved popup implementation
Markus Kottlaender <markus@intevation.de>
parents:
2357
diff
changeset
|
310 content: |
c06b001dc26b
client: improved popup implementation
Markus Kottlaender <markus@intevation.de>
parents:
2357
diff
changeset
|
311 this.$gettext( |
c06b001dc26b
client: improved popup implementation
Markus Kottlaender <markus@intevation.de>
parents:
2357
diff
changeset
|
312 "Do you really want to delete the following template:" |
c06b001dc26b
client: improved popup implementation
Markus Kottlaender <markus@intevation.de>
parents:
2357
diff
changeset
|
313 ) + |
c06b001dc26b
client: improved popup implementation
Markus Kottlaender <markus@intevation.de>
parents:
2357
diff
changeset
|
314 `<br> |
c06b001dc26b
client: improved popup implementation
Markus Kottlaender <markus@intevation.de>
parents:
2357
diff
changeset
|
315 <b>${template.name}</b>`, |
c06b001dc26b
client: improved popup implementation
Markus Kottlaender <markus@intevation.de>
parents:
2357
diff
changeset
|
316 confirm: { |
c06b001dc26b
client: improved popup implementation
Markus Kottlaender <markus@intevation.de>
parents:
2357
diff
changeset
|
317 label: this.$gettext("Delete"), |
c06b001dc26b
client: improved popup implementation
Markus Kottlaender <markus@intevation.de>
parents:
2357
diff
changeset
|
318 icon: "trash", |
c06b001dc26b
client: improved popup implementation
Markus Kottlaender <markus@intevation.de>
parents:
2357
diff
changeset
|
319 callback: () => { |
4632
2e47b32a389d
client: encode strings in url paths
Fadi Abbud <fadi.abbud@intevation.de>
parents:
4454
diff
changeset
|
320 HTTP.delete( |
2e47b32a389d
client: encode strings in url paths
Fadi Abbud <fadi.abbud@intevation.de>
parents:
4454
diff
changeset
|
321 `/templates/${template.type}/${encodeURIComponent( |
2e47b32a389d
client: encode strings in url paths
Fadi Abbud <fadi.abbud@intevation.de>
parents:
4454
diff
changeset
|
322 template.name |
2e47b32a389d
client: encode strings in url paths
Fadi Abbud <fadi.abbud@intevation.de>
parents:
4454
diff
changeset
|
323 )}`, |
2e47b32a389d
client: encode strings in url paths
Fadi Abbud <fadi.abbud@intevation.de>
parents:
4454
diff
changeset
|
324 { |
2e47b32a389d
client: encode strings in url paths
Fadi Abbud <fadi.abbud@intevation.de>
parents:
4454
diff
changeset
|
325 headers: { |
2e47b32a389d
client: encode strings in url paths
Fadi Abbud <fadi.abbud@intevation.de>
parents:
4454
diff
changeset
|
326 "X-Gemma-Auth": localStorage.getItem("token"), |
2e47b32a389d
client: encode strings in url paths
Fadi Abbud <fadi.abbud@intevation.de>
parents:
4454
diff
changeset
|
327 "Content-type": "text/xml; charset=UTF-8" |
2e47b32a389d
client: encode strings in url paths
Fadi Abbud <fadi.abbud@intevation.de>
parents:
4454
diff
changeset
|
328 } |
2384
c06b001dc26b
client: improved popup implementation
Markus Kottlaender <markus@intevation.de>
parents:
2357
diff
changeset
|
329 } |
4632
2e47b32a389d
client: encode strings in url paths
Fadi Abbud <fadi.abbud@intevation.de>
parents:
4454
diff
changeset
|
330 ).then(() => { |
2384
c06b001dc26b
client: improved popup implementation
Markus Kottlaender <markus@intevation.de>
parents:
2357
diff
changeset
|
331 let removeIndex = this.templates.findIndex( |
c06b001dc26b
client: improved popup implementation
Markus Kottlaender <markus@intevation.de>
parents:
2357
diff
changeset
|
332 t => t.name === template.name |
c06b001dc26b
client: improved popup implementation
Markus Kottlaender <markus@intevation.de>
parents:
2357
diff
changeset
|
333 ); |
c06b001dc26b
client: improved popup implementation
Markus Kottlaender <markus@intevation.de>
parents:
2357
diff
changeset
|
334 if (removeIndex !== -1) { |
c06b001dc26b
client: improved popup implementation
Markus Kottlaender <markus@intevation.de>
parents:
2357
diff
changeset
|
335 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
|
336 displayInfo({ |
408e0f4d4008
clinet:pdf-gen template:unifiy feedback messages for template
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2448
diff
changeset
|
337 message: |
408e0f4d4008
clinet:pdf-gen template:unifiy feedback messages for template
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2448
diff
changeset
|
338 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
|
339 }); |
2384
c06b001dc26b
client: improved popup implementation
Markus Kottlaender <markus@intevation.de>
parents:
2357
diff
changeset
|
340 } |
c06b001dc26b
client: improved popup implementation
Markus Kottlaender <markus@intevation.de>
parents:
2357
diff
changeset
|
341 }); |
c06b001dc26b
client: improved popup implementation
Markus Kottlaender <markus@intevation.de>
parents:
2357
diff
changeset
|
342 } |
c06b001dc26b
client: improved popup implementation
Markus Kottlaender <markus@intevation.de>
parents:
2357
diff
changeset
|
343 }, |
c06b001dc26b
client: improved popup implementation
Markus Kottlaender <markus@intevation.de>
parents:
2357
diff
changeset
|
344 cancel: { |
c06b001dc26b
client: improved popup implementation
Markus Kottlaender <markus@intevation.de>
parents:
2357
diff
changeset
|
345 label: this.$gettext("Cancel"), |
c06b001dc26b
client: improved popup implementation
Markus Kottlaender <markus@intevation.de>
parents:
2357
diff
changeset
|
346 icon: "times" |
2257
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
347 } |
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
348 }); |
2216
585373d33f8f
prepared pdf template administration
Markus Kottlaender <markus@intevation.de>
parents:
2213
diff
changeset
|
349 } |
2247
e6fba449aa3c
merged pdf-export in default
Markus Kottlaender <markus@intevation.de>
parents:
2216
diff
changeset
|
350 }, |
e6fba449aa3c
merged pdf-export in default
Markus Kottlaender <markus@intevation.de>
parents:
2216
diff
changeset
|
351 mounted() { |
2257
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
352 this.loadTemplates(); |
2213 | 353 } |
354 }; | |
355 </script> |