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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
|
<!--
- SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
- SPDX-License-Identifier: AGPL-3.0-or-later
-->
<template>
<div>
<!-- Request note -->
<NcNoteCard type="success">
{{ t('files_sharing', 'You can now share the link below to allow people to upload files to your directory.') }}
</NcNoteCard>
<!-- Copy share link -->
<NcInputField ref="clipboard"
:value="shareLink"
:label="t('files_sharing', 'Share link')"
:readonly="true"
:show-trailing-button="true"
:trailing-button-label="t('files_sharing', 'Copy to clipboard')"
@click="copyShareLink"
@click-trailing-button="copyShareLink">
<template #trailing-button-icon>
<IconCheck v-if="isCopied" :size="20" />
<IconClipboard v-else :size="20" />
</template>
</NcInputField>
<template v-if="isShareByMailEnabled">
<!-- Email share-->
<NcTextField :value.sync="email"
:label="t('files_sharing', 'Send link via email')"
:placeholder="t('files_sharing', 'Enter an email address or paste a list')"
type="email"
@keypress.enter.stop="addNewEmail"
@paste.stop.prevent="onPasteEmails"
@focusout.native="addNewEmail" />
<!-- Email list -->
<div v-if="emails.length > 0" class="file-request-dialog__emails">
<NcChip v-for="mail in emails"
:key="mail"
:aria-label-close="t('files_sharing', 'Remove email')"
:text="mail"
@close="$emit('remove-email', mail)">
<template #icon>
<NcAvatar :disable-menu="true"
:disable-tooltip="true"
:display-name="mail"
:is-no-user="true"
:show-user-status="false"
:size="24" />
</template>
</NcChip>
</div>
</template>
</div>
</template>
<script lang="ts">
import type { PropType } from 'vue'
import Share from '../../models/Share'
import { defineComponent } from 'vue'
import { generateUrl, getBaseUrl } from '@nextcloud/router'
import { showError, showSuccess } from '@nextcloud/dialogs'
import { n, t } from '@nextcloud/l10n'
import NcAvatar from '@nextcloud/vue/dist/Components/NcAvatar.js'
import NcInputField from '@nextcloud/vue/dist/Components/NcInputField.js'
import NcNoteCard from '@nextcloud/vue/dist/Components/NcNoteCard.js'
import NcTextField from '@nextcloud/vue/dist/Components/NcTextField.js'
import NcChip from '@nextcloud/vue/dist/Components/NcChip.js'
import IconCheck from 'vue-material-design-icons/Check.vue'
import IconClipboard from 'vue-material-design-icons/Clipboard.vue'
export default defineComponent({
name: 'NewFileRequestDialogFinish',
components: {
IconCheck,
IconClipboard,
NcAvatar,
NcInputField,
NcNoteCard,
NcTextField,
NcChip,
},
props: {
share: {
type: Object as PropType<Share>,
required: true,
},
emails: {
type: Array as PropType<string[]>,
required: true,
},
isShareByMailEnabled: {
type: Boolean,
required: true,
},
},
emits: ['add-email', 'remove-email'],
setup() {
return {
n, t,
}
},
data() {
return {
isCopied: false,
email: '',
}
},
computed: {
shareLink() {
return generateUrl('/s/{token}', { token: this.share.token }, { baseURL: getBaseUrl() })
},
},
methods: {
async copyShareLink(event: MouseEvent) {
if (this.isCopied) {
this.isCopied = false
return
}
if (!navigator.clipboard) {
// Clipboard API not available
window.prompt(t('files_sharing', 'Automatically copying failed, please copy the share link manually'), this.shareLink)
return
}
await navigator.clipboard.writeText(this.shareLink)
showSuccess(t('files_sharing', 'Link copied to clipboard'))
this.isCopied = true
event.target?.select?.()
setTimeout(() => {
this.isCopied = false
}, 3000)
},
addNewEmail(e: KeyboardEvent) {
if (this.email.trim() === '') {
return
}
if (e.target instanceof HTMLInputElement) {
// Reset the custom validity
e.target.setCustomValidity('')
// Check if the field is valid
if (e.target.checkValidity() === false) {
e.target.reportValidity()
return
}
// The email is already in the list
if (this.emails.includes(this.email.trim())) {
e.target.setCustomValidity(t('files_sharing', 'Email already added'))
e.target.reportValidity()
return
}
// Check if the email is valid
if (!this.isValidEmail(this.email.trim())) {
e.target.setCustomValidity(t('files_sharing', 'Invalid email address'))
e.target.reportValidity()
return
}
this.$emit('add-email', this.email.trim())
this.email = ''
}
},
// Handle dumping a list of emails
onPasteEmails(e: ClipboardEvent) {
const clipboardData = e.clipboardData
if (!clipboardData) {
return
}
const pastedText = clipboardData.getData('text')
const emails = pastedText.split(/[\s,;]+/).filter(Boolean).map((email) => email.trim())
const duplicateEmails = emails.filter((email) => this.emails.includes(email))
const validEmails = emails.filter((email) => this.isValidEmail(email) && !duplicateEmails.includes(email))
const invalidEmails = emails.filter((email) => !this.isValidEmail(email))
validEmails.forEach((email) => this.$emit('add-email', email))
// Warn about invalid emails
if (invalidEmails.length > 0) {
showError(n('files_sharing', 'The following email address is not valid: {emails}', 'The following email addresses are not valid: {emails}', invalidEmails.length, { emails: invalidEmails.join(', ') }))
}
// Warn about duplicate emails
if (duplicateEmails.length > 0) {
showError(n('files_sharing', '1 email address already added', '{count} email addresses already added', duplicateEmails.length, { count: duplicateEmails.length }))
}
if (validEmails.length > 0) {
showSuccess(n('files_sharing', '1 email address added', '{count} email addresses added', validEmails.length, { count: validEmails.length }))
}
this.email = ''
},
// No need to have a fancy regex, just check for an @
isValidEmail(email: string): boolean {
return email.includes('@')
},
},
})
</script>
<style scoped>
.input-field,
.file-request-dialog__emails {
margin-top: var(--margin);
}
.file-request-dialog__emails {
display: flex;
gap: var(--default-grid-baseline);
flex-wrap: wrap;
}
</style>
|