/
File.vue
124 lines (107 loc) · 2.6 KB
/
File.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<template>
<b-form-group
label-class="d-flex align-items-center text-primary p-0"
:class="formGroupStyleClasses"
>
<template
v-if="!valueOnly"
#label
>
<span class="d-inline-block text-truncate mw-100 py-1">
{{ label }}
</span>
<hint
:id="field.fieldID"
:text="hint"
/>
</template>
<div
class="small text-muted"
:class="{ 'mb-1': description }"
>
{{ description }}
</div>
<uploader
:endpoint="endpoint"
:accepted-files="mimetypes"
:max-filesize="maxSize"
:form-data="uploaderFormData"
@uploaded="appendAttachment"
/>
<list-loader
kind="record"
:set.sync="set"
:namespace="namespace"
:enable-order="field.isMulti"
enable-delete
mode="list"
class="mt-2"
/>
<errors :errors="errors" />
</b-form-group>
</template>
<script>
import base from './base'
import Uploader from 'corteza-webapp-compose/src/components/Public/Page/Attachment/Uploader'
import ListLoader from 'corteza-webapp-compose/src/components/Public/Page/Attachment/ListLoader'
import { NoID } from '@cortezaproject/corteza-js'
export default {
components: {
Uploader,
ListLoader,
},
extends: base,
computed: {
endpoint () {
const { moduleID, recordID } = this.record
const { namespaceID } = this.namespace
return this.$ComposeAPI.recordUploadEndpoint({
namespaceID,
moduleID,
recordID,
fieldName: this.field.name,
})
},
uploaderFormData () {
const fd = {
fieldName: this.field.name,
}
if (this.record && this.record.recordID !== NoID) {
fd.recordID = this.record.recordID
}
return fd
},
mimetypes () {
const a = (this.field.options.mimetypes || '').trim()
if (!a) {
return this.$s('compose.Record.Attachments.Mimetypes', ['*/*'])
}
return a.split(',').map(p => p.trim())
},
maxSize () {
return this.field.options.maxSize || this.$s('compose.Record.Attachments.MaxSize', 100)
},
set: {
get () {
return this.field.isMulti ? this.value : [this.value]
},
set (v) {
if (this.field.isMulti) {
this.value = v
} else {
this.value = (Array.isArray(v) && v.length > 0) ? v[0] : undefined
}
},
},
},
methods: {
appendAttachment ({ attachmentID } = {}) {
if (this.field.isMulti) {
this.value.push(attachmentID)
} else {
this.value = attachmentID
}
},
},
}
</script>