Mercurial > gemma
annotate client/src/components/systemconfiguration/PDFTemplates.vue @ 4643:a1a9b1eab57c stree-experiment
Use append/slicing trick to simplify tree traversals.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Fri, 11 Oct 2019 23:46:35 +0200 |
parents | 2e47b32a389d |
children | 008bc1ae8897 |
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 }) |
1a6553da9078
client:pdf-gen : add download-template functionality
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2522
diff
changeset
|
165 .catch(e => { |
1a6553da9078
client:pdf-gen : add download-template functionality
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2522
diff
changeset
|
166 const { status, data } = e.response; |
1a6553da9078
client:pdf-gen : add download-template functionality
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2522
diff
changeset
|
167 displayError({ |
1a6553da9078
client:pdf-gen : add download-template functionality
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2522
diff
changeset
|
168 title: this.$gettext("Backend Error"), |
1a6553da9078
client:pdf-gen : add download-template functionality
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2522
diff
changeset
|
169 message: `${status}: ${data.message || data}` |
1a6553da9078
client:pdf-gen : add download-template functionality
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2522
diff
changeset
|
170 }); |
1a6553da9078
client:pdf-gen : add download-template functionality
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2522
diff
changeset
|
171 }) |
1a6553da9078
client:pdf-gen : add download-template functionality
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2522
diff
changeset
|
172 .finally(() => { |
1a6553da9078
client:pdf-gen : add download-template functionality
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2522
diff
changeset
|
173 document.body.removeChild(element); |
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 }, |
2384
c06b001dc26b
client: improved popup implementation
Markus Kottlaender <markus@intevation.de>
parents:
2357
diff
changeset
|
177 uploadTemplate() { |
2257
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
178 const reader = new FileReader(); |
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
179 reader.onload = event => { |
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
180 let template; |
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
181 try { |
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
182 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
|
183 } catch (e) { |
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
184 displayError({ |
2284
9f327f197ddd
client: translation: mark some strings for translations
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2257
diff
changeset
|
185 title: this.$gettext("Format Error"), |
9f327f197ddd
client: translation: mark some strings for translations
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2257
diff
changeset
|
186 message: this.$gettext( |
9f327f197ddd
client: translation: mark some strings for translations
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2257
diff
changeset
|
187 "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
|
188 ) |
2257
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
189 }); |
3243
e9c143436432
client: diagram-template: improve Pdf-templates systemconfiguration
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3234
diff
changeset
|
190 // 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
|
191 // 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
|
192 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
|
193 } |
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
194 if (template.name) { |
3243
e9c143436432
client: diagram-template: improve Pdf-templates systemconfiguration
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3234
diff
changeset
|
195 // 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
|
196 let checkElement = false; |
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
197 template.elements.forEach(e => { |
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
198 if ( |
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
199 [ |
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
200 "text", |
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
201 "box", |
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
202 "textbox", |
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
203 "image", |
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
204 "bottleneck", |
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
205 "legend", |
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
206 "scalebar", |
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
207 "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
|
208 "northarrow", |
106e1d011a5d
client: pdf-gen: include the diagram elements in the upload template constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2874
diff
changeset
|
209 "diagramlegend", |
3160
94935895e6d7
client: add diagram-element to template (waterlevel)
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3138
diff
changeset
|
210 "diagramtitle", |
94935895e6d7
client: add diagram-element to template (waterlevel)
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3138
diff
changeset
|
211 "diagram" |
2802
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
212 ].indexOf(e.type) === -1 |
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
213 ) { |
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
214 checkElement = true; |
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
215 displayError({ |
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
216 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
|
217 message: |
2802
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
218 e.type + |
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
219 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
|
220 }); |
3243
e9c143436432
client: diagram-template: improve Pdf-templates systemconfiguration
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3234
diff
changeset
|
221 // 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
|
222 this.$refs.uploadTemplate.value = null; |
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
223 } |
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
224 }); |
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
225 |
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
226 if (!checkElement) { |
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
227 this.uploading = true; |
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
228 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
|
229 "/templates/" + this.type + "/" + template.name, |
2802
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
230 { |
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
231 template_name: template.name, |
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
232 template_data: template |
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
233 }, |
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 headers: { |
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
236 "X-Gemma-Auth": localStorage.getItem("token"), |
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
237 "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
|
238 } |
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
239 } |
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
240 ) |
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
241 .then(() => { |
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
242 this.loadTemplates(); |
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
243 displayInfo({ |
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
244 message: |
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
245 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
|
246 }); |
2802
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
247 }) |
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
248 .catch(e => { |
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
249 const { status, data } = e.response; |
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
250 if (status === 400) { |
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
251 displayError({ |
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
252 title: this.$gettext("Error"), |
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
253 message: `${data.message || data}` |
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
254 }); |
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
255 } else { |
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
256 displayError({ |
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
257 title: this.$gettext("Backend Error"), |
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
258 message: `${status}: ${data.message || data}` |
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
259 }); |
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
260 } |
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
261 }) |
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
262 .finally(() => { |
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
263 this.uploading = false; |
9adbe0633bf9
client:pdf-gen: improve template upload constraint
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2782
diff
changeset
|
264 this.$refs.uploadTemplate.value = null; |
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 } |
2257
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
267 } else { |
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
268 displayError({ |
2284
9f327f197ddd
client: translation: mark some strings for translations
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2257
diff
changeset
|
269 title: this.$gettext("Format Error"), |
9f327f197ddd
client: translation: mark some strings for translations
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2257
diff
changeset
|
270 message: this.$gettext( |
9f327f197ddd
client: translation: mark some strings for translations
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2257
diff
changeset
|
271 "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
|
272 ) |
2257
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
273 }); |
3243
e9c143436432
client: diagram-template: improve Pdf-templates systemconfiguration
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3234
diff
changeset
|
274 // 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
|
275 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
|
276 } |
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
277 }; |
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
278 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
|
279 }, |
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
280 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
|
281 HTTP.get("/templates", { |
2257
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
282 headers: { |
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
283 "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
|
284 "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
|
285 } |
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
286 }) |
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
287 .then(response => { |
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
288 this.templates = response.data; |
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 .catch(e => { |
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
291 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
|
292 displayError({ |
2284
9f327f197ddd
client: translation: mark some strings for translations
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2257
diff
changeset
|
293 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
|
294 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
|
295 }); |
2216
585373d33f8f
prepared pdf template administration
Markus Kottlaender <markus@intevation.de>
parents:
2213
diff
changeset
|
296 }); |
585373d33f8f
prepared pdf template administration
Markus Kottlaender <markus@intevation.de>
parents:
2213
diff
changeset
|
297 }, |
2384
c06b001dc26b
client: improved popup implementation
Markus Kottlaender <markus@intevation.de>
parents:
2357
diff
changeset
|
298 deleteTemplate(template) { |
c06b001dc26b
client: improved popup implementation
Markus Kottlaender <markus@intevation.de>
parents:
2357
diff
changeset
|
299 this.$store.commit("application/popup", { |
c06b001dc26b
client: improved popup implementation
Markus Kottlaender <markus@intevation.de>
parents:
2357
diff
changeset
|
300 icon: "trash", |
c06b001dc26b
client: improved popup implementation
Markus Kottlaender <markus@intevation.de>
parents:
2357
diff
changeset
|
301 title: this.$gettext("Delete Template"), |
c06b001dc26b
client: improved popup implementation
Markus Kottlaender <markus@intevation.de>
parents:
2357
diff
changeset
|
302 content: |
c06b001dc26b
client: improved popup implementation
Markus Kottlaender <markus@intevation.de>
parents:
2357
diff
changeset
|
303 this.$gettext( |
c06b001dc26b
client: improved popup implementation
Markus Kottlaender <markus@intevation.de>
parents:
2357
diff
changeset
|
304 "Do you really want to delete the following template:" |
c06b001dc26b
client: improved popup implementation
Markus Kottlaender <markus@intevation.de>
parents:
2357
diff
changeset
|
305 ) + |
c06b001dc26b
client: improved popup implementation
Markus Kottlaender <markus@intevation.de>
parents:
2357
diff
changeset
|
306 `<br> |
c06b001dc26b
client: improved popup implementation
Markus Kottlaender <markus@intevation.de>
parents:
2357
diff
changeset
|
307 <b>${template.name}</b>`, |
c06b001dc26b
client: improved popup implementation
Markus Kottlaender <markus@intevation.de>
parents:
2357
diff
changeset
|
308 confirm: { |
c06b001dc26b
client: improved popup implementation
Markus Kottlaender <markus@intevation.de>
parents:
2357
diff
changeset
|
309 label: this.$gettext("Delete"), |
c06b001dc26b
client: improved popup implementation
Markus Kottlaender <markus@intevation.de>
parents:
2357
diff
changeset
|
310 icon: "trash", |
c06b001dc26b
client: improved popup implementation
Markus Kottlaender <markus@intevation.de>
parents:
2357
diff
changeset
|
311 callback: () => { |
4632
2e47b32a389d
client: encode strings in url paths
Fadi Abbud <fadi.abbud@intevation.de>
parents:
4454
diff
changeset
|
312 HTTP.delete( |
2e47b32a389d
client: encode strings in url paths
Fadi Abbud <fadi.abbud@intevation.de>
parents:
4454
diff
changeset
|
313 `/templates/${template.type}/${encodeURIComponent( |
2e47b32a389d
client: encode strings in url paths
Fadi Abbud <fadi.abbud@intevation.de>
parents:
4454
diff
changeset
|
314 template.name |
2e47b32a389d
client: encode strings in url paths
Fadi Abbud <fadi.abbud@intevation.de>
parents:
4454
diff
changeset
|
315 )}`, |
2e47b32a389d
client: encode strings in url paths
Fadi Abbud <fadi.abbud@intevation.de>
parents:
4454
diff
changeset
|
316 { |
2e47b32a389d
client: encode strings in url paths
Fadi Abbud <fadi.abbud@intevation.de>
parents:
4454
diff
changeset
|
317 headers: { |
2e47b32a389d
client: encode strings in url paths
Fadi Abbud <fadi.abbud@intevation.de>
parents:
4454
diff
changeset
|
318 "X-Gemma-Auth": localStorage.getItem("token"), |
2e47b32a389d
client: encode strings in url paths
Fadi Abbud <fadi.abbud@intevation.de>
parents:
4454
diff
changeset
|
319 "Content-type": "text/xml; charset=UTF-8" |
2e47b32a389d
client: encode strings in url paths
Fadi Abbud <fadi.abbud@intevation.de>
parents:
4454
diff
changeset
|
320 } |
2384
c06b001dc26b
client: improved popup implementation
Markus Kottlaender <markus@intevation.de>
parents:
2357
diff
changeset
|
321 } |
4632
2e47b32a389d
client: encode strings in url paths
Fadi Abbud <fadi.abbud@intevation.de>
parents:
4454
diff
changeset
|
322 ).then(() => { |
2384
c06b001dc26b
client: improved popup implementation
Markus Kottlaender <markus@intevation.de>
parents:
2357
diff
changeset
|
323 let removeIndex = this.templates.findIndex( |
c06b001dc26b
client: improved popup implementation
Markus Kottlaender <markus@intevation.de>
parents:
2357
diff
changeset
|
324 t => t.name === template.name |
c06b001dc26b
client: improved popup implementation
Markus Kottlaender <markus@intevation.de>
parents:
2357
diff
changeset
|
325 ); |
c06b001dc26b
client: improved popup implementation
Markus Kottlaender <markus@intevation.de>
parents:
2357
diff
changeset
|
326 if (removeIndex !== -1) { |
c06b001dc26b
client: improved popup implementation
Markus Kottlaender <markus@intevation.de>
parents:
2357
diff
changeset
|
327 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
|
328 displayInfo({ |
408e0f4d4008
clinet:pdf-gen template:unifiy feedback messages for template
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2448
diff
changeset
|
329 message: |
408e0f4d4008
clinet:pdf-gen template:unifiy feedback messages for template
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2448
diff
changeset
|
330 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
|
331 }); |
2384
c06b001dc26b
client: improved popup implementation
Markus Kottlaender <markus@intevation.de>
parents:
2357
diff
changeset
|
332 } |
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 } |
c06b001dc26b
client: improved popup implementation
Markus Kottlaender <markus@intevation.de>
parents:
2357
diff
changeset
|
335 }, |
c06b001dc26b
client: improved popup implementation
Markus Kottlaender <markus@intevation.de>
parents:
2357
diff
changeset
|
336 cancel: { |
c06b001dc26b
client: improved popup implementation
Markus Kottlaender <markus@intevation.de>
parents:
2357
diff
changeset
|
337 label: this.$gettext("Cancel"), |
c06b001dc26b
client: improved popup implementation
Markus Kottlaender <markus@intevation.de>
parents:
2357
diff
changeset
|
338 icon: "times" |
2257
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
339 } |
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
340 }); |
2216
585373d33f8f
prepared pdf template administration
Markus Kottlaender <markus@intevation.de>
parents:
2213
diff
changeset
|
341 } |
2247
e6fba449aa3c
merged pdf-export in default
Markus Kottlaender <markus@intevation.de>
parents:
2216
diff
changeset
|
342 }, |
e6fba449aa3c
merged pdf-export in default
Markus Kottlaender <markus@intevation.de>
parents:
2216
diff
changeset
|
343 mounted() { |
2257
ce6fd3d4a3a2
client: pdf-gen: moved template handling from store to components
Markus Kottlaender <markus@intevation.de>
parents:
2247
diff
changeset
|
344 this.loadTemplates(); |
2213 | 345 } |
346 }; | |
347 </script> |