refactor templates controller

This commit is contained in:
Pete Matsyburka
2024-03-23 23:16:40 +02:00
parent 715c70d422
commit 077eab7005
10 changed files with 75 additions and 60 deletions
+11 -2
View File
@@ -444,6 +444,11 @@ export default {
required: false,
default: true
},
authenticityToken: {
type: String,
required: false,
default: ''
},
withDocumentsList: {
type: Boolean,
required: false,
@@ -1023,7 +1028,11 @@ export default {
baseFetch (path, options = {}) {
return fetch(this.baseUrl + path, {
...options,
headers: { ...this.fetchOptions.headers, ...options.headers }
headers: {
'X-CSRF-Token': this.authenticityToken,
...this.fetchOptions.headers,
...options.headers
}
})
},
save ({ force } = { force: false }) {
@@ -1039,7 +1048,7 @@ export default {
this.pushUndo()
return this.baseFetch(`/api/templates/${this.template.id}`, {
return this.baseFetch(`/templates/${this.template.id}`, {
method: 'PUT',
body: JSON.stringify({
template: {
+4 -4
View File
@@ -119,7 +119,7 @@ export default {
this.isProcessing = true
this.baseFetch(`/api/templates/${this.templateId}/documents`, {
this.baseFetch(`/templates/${this.templateId}/documents`, {
method: 'POST',
body: JSON.stringify({ blobs }),
headers: { 'Content-Type': 'application/json' }
@@ -132,7 +132,7 @@ export default {
} else if (resp.status === 422) {
resp.json().then((data) => {
if (data.error === 'PDF encrypted') {
this.baseFetch(`/api/templates/${this.templateId}/documents`, {
this.baseFetch(`/templates/${this.templateId}/documents`, {
method: 'POST',
body: JSON.stringify({ blobs, password: prompt('Enter PDF password') }),
headers: { 'Content-Type': 'application/json' }
@@ -151,7 +151,7 @@ export default {
this.isProcessing = false
})
} else {
this.baseFetch(`/api/templates/${this.templateId}/documents`, {
this.baseFetch(`/templates/${this.templateId}/documents`, {
method: 'POST',
body: new FormData(this.$refs.form)
}).then((resp) => {
@@ -167,7 +167,7 @@ export default {
formData.append('password', prompt('Enter PDF password'))
this.baseFetch(`/api/templates/${this.templateId}/documents`, {
this.baseFetch(`/templates/${this.templateId}/documents`, {
method: 'POST',
body: formData
}).then(async (resp) => {