51
51
multiple
52
52
style="display: none;"
53
53
@change="onLocalAttachmentSelected">
54
+ <FilePicker v-if="isAttachementPickerOpen"
55
+ :title="t('mail','Choose a file to add as attachment')"
56
+ :buttons="attachementPickerButtons"
57
+ :filter-fn="filterAttachements"
58
+ @close="()=>isAttachementPickerOpen = false" />
59
+ <FilePicker v-if="isLinkPickerOpen"
60
+ :title="t('mail','Choose a file to share as a link')"
61
+ :multiselect="false"
62
+ :buttons="linkPickerButtons"
63
+ :filter-fn="filterAttachements"
64
+ @close="()=>isLinkPickerOpen = false" />
54
65
</div>
55
66
</template>
56
67
@@ -60,7 +71,8 @@ import trimStart from 'lodash/fp/trimCharsStart.js'
60
71
import { getRequestToken } from '@nextcloud/auth'
61
72
import { formatFileSize } from '@nextcloud/files'
62
73
import prop from 'lodash/fp/prop.js'
63
- import { getFilePickerBuilder, showWarning } from '@nextcloud/dialogs'
74
+ import { showWarning } from '@nextcloud/dialogs'
75
+ import { FilePickerVue as FilePicker } from '@nextcloud/dialogs/filepicker.js'
64
76
import sumBy from 'lodash/fp/sumBy.js'
65
77
import { translate as t, translatePlural as n } from '@nextcloud/l10n'
66
78
@@ -87,6 +99,7 @@ const mimes = [
87
99
export default {
88
100
name: 'ComposerAttachments',
89
101
components: {
102
+ FilePicker,
90
103
ComposerAttachment,
91
104
ChevronDown,
92
105
ChevronUp,
@@ -113,6 +126,23 @@ export default {
113
126
attachments: [],
114
127
isToggle: false,
115
128
hasNextLine: false,
129
+ isAttachementPickerOpen: false,
130
+ isLinkPickerOpen: false,
131
+ attachementPickerButtons: [
132
+ {
133
+ label: t('mail', 'Choose'),
134
+ callback: this.onAddCloudAttachment,
135
+ type: 'primary',
136
+ },
137
+ ],
138
+ linkPickerButtons: [
139
+ {
140
+ label: t('mail', 'Choose'),
141
+ callback: this.onAddCloudAttachmentLink,
142
+ type: 'primary',
143
+ },
144
+ ],
145
+
116
146
}
117
147
},
118
148
computed: {
@@ -163,8 +193,8 @@ export default {
163
193
},
164
194
created() {
165
195
this.bus.on('on-add-local-attachment', this.onAddLocalAttachment)
166
- this.bus.on('on-add-cloud-attachment', this.onAddCloudAttachment )
167
- this.bus.on('on-add-cloud-attachment-link', this.onAddCloudAttachmentLink )
196
+ this.bus.on('on-add-cloud-attachment', this.openAttachementPicker )
197
+ this.bus.on('on-add-cloud-attachment-link', this.OpenctLinkPicker )
168
198
this.bus.on('on-add-message-as-attachment', this.onAddMessageAsAttachment)
169
199
this.value.map(attachment => {
170
200
this.attachments.push({
@@ -180,6 +210,17 @@ export default {
180
210
})
181
211
},
182
212
methods: {
213
+ filterAttachements(node) {
214
+ const downloadShareAttribute = JSON.parse(node.attributes['share-attributes']).find((shareAttribute) => shareAttribute.key === 'download')
215
+ const downloadPermissions = downloadShareAttribute !== undefined ? downloadShareAttribute.enabled : true
216
+ return (node.permissions & OC.PERMISSION_READ) && downloadPermissions
217
+ },
218
+ openAttachementPicker() {
219
+ this.isAttachementPickerOpen = true
220
+ },
221
+ OpenctLinkPicker() {
222
+ this.isLinkPickerOpen = true
223
+ },
183
224
onAddLocalAttachment() {
184
225
this.$refs.localAttachments.click()
185
226
},
@@ -285,11 +326,10 @@ export default {
285
326
286
327
return done
287
328
},
288
- async onAddCloudAttachment() {
289
- const picker = getFilePickerBuilder(t('mail', 'Choose a file to add as attachment')).setMultiSelect(true).build()
290
-
329
+ async onAddCloudAttachment(nodes) {
291
330
try {
292
- const paths = await picker.pick(t('mail', 'Choose a file to add as attachment'))
331
+ const paths = nodes.map(node => node.path)
332
+ this.cloudAttachement = false
293
333
// maybe fiiled front with placeholder loader...?
294
334
const filesFromCloud = await Promise.all(paths.map(getFileData))
295
335
@@ -332,12 +372,10 @@ export default {
332
372
logger.error('could not choose a file as attachment', { error })
333
373
}
334
374
},
335
- async onAddCloudAttachmentLink() {
336
- const picker = getFilePickerBuilder(t('mail', 'Choose a file to share as a link')).build()
337
-
375
+ async onAddCloudAttachmentLink(nodes) {
338
376
try {
339
- const path = await picker.pick(t('mail', 'Choose a file to share as a link'))
340
- const url = await shareFile(path, getRequestToken())
377
+ this.cloudAttachementLink = false
378
+ const url = await shareFile(nodes[0]. path, getRequestToken())
341
379
342
380
this.appendToBodyAtCursor(`<a href="${url}">${url}</a>`)
343
381
} catch (error) {
0 commit comments