aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files_sharing/src/components/NewFileRequestDialog/NewFileRequestDialogIntro.vue
blob: 57b0328966119b814031098456f76d05b3358a2d (plain)
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
<!--
  - SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
  - SPDX-License-Identifier: AGPL-3.0-or-later
-->

<template>
	<div>
		<!-- Request label -->
		<fieldset class="file-request-dialog__label" data-cy-file-request-dialog-fieldset="label">
			<legend>
				{{ t('files_sharing', 'What are you requesting?') }}
			</legend>
			<NcTextField :value="label"
				:disabled="disabled"
				:label-outside="true"
				:placeholder="t('files_sharing', 'Birthday party photos, History assignment…')"
				:required="false"
				name="label"
				@update:value="$emit('update:label', $event)" />
		</fieldset>

		<!-- Request destination -->
		<fieldset class="file-request-dialog__destination" data-cy-file-request-dialog-fieldset="destination">
			<legend>
				{{ t('files_sharing', 'Where should these files go?') }}
			</legend>
			<NcTextField :value="destination"
				:disabled="disabled"
				:helper-text="t('files_sharing', 'The uploaded files are visible only to you unless you choose to share them.')"
				:label-outside="true"
				:minlength="2/* cannot share root */"
				:placeholder="t('files_sharing', 'Select a destination')"
				:readonly="false /* cannot validate a readonly input */"
				:required="true /* cannot be empty */"
				:show-trailing-button="destination !== context.path"
				:trailing-button-icon="'undo'"
				:trailing-button-label="t('files_sharing', 'Revert to default')"
				name="destination"
				@click="onPickDestination"
				@keypress.prevent.stop="/* prevent typing in the input, we use the picker */"
				@paste.prevent.stop="/* prevent pasting in the input, we use the picker */"
				@trailing-button-click="$emit('update:destination', '')">
				<IconFolder :size="18" />
			</NcTextField>
		</fieldset>

		<!-- Request note -->
		<fieldset class="file-request-dialog__note" data-cy-file-request-dialog-fieldset="note">
			<legend>
				{{ t('files_sharing', 'Add a note') }}
			</legend>
			<NcTextArea :value="note"
				:disabled="disabled"
				:label-outside="true"
				:placeholder="t('files_sharing', 'Add a note to help people understand what you are requesting.')"
				:required="false"
				name="note"
				@update:value="$emit('update:note', $event)" />
		</fieldset>
	</div>
</template>

<script lang="ts">
import type { PropType } from 'vue'
import type { Folder, Node } from '@nextcloud/files'

import { defineComponent } from 'vue'
import { getFilePickerBuilder } from '@nextcloud/dialogs'
import { translate } from '@nextcloud/l10n'

import IconFolder from 'vue-material-design-icons/Folder.vue'
import NcTextArea from '@nextcloud/vue/dist/Components/NcTextArea.js'
import NcTextField from '@nextcloud/vue/dist/Components/NcTextField.js'

export default defineComponent({
	name: 'NewFileRequestDialogIntro',

	components: {
		IconFolder,
		NcTextArea,
		NcTextField,
	},

	props: {
		disabled: {
			type: Boolean,
			required: false,
			default: false,
		},
		context: {
			type: Object as PropType<Folder>,
			required: true,
		},
		label: {
			type: String,
			required: true,
		},
		destination: {
			type: String,
			required: true,
		},
		note: {
			type: String,
			required: true,
		},
	},

	emits: [
		'update:destination',
		'update:label',
		'update:note',
	],

	setup() {
		return {
			t: translate,
		}
	},

	methods: {
		onPickDestination() {
			const filepicker = getFilePickerBuilder(this.t('files_sharing', 'Select a destination'))
				.addMimeTypeFilter('httpd/unix-directory')
				.allowDirectories(true)
				.addButton({
					label: this.t('files_sharing', 'Select'),
					callback: this.onPickedDestination,
				})
				.setFilter(node => node.path !== '/')
				.startAt(this.destination)
				.build()
			try {
				filepicker.pick()
			} catch (e) {
				// ignore cancel
			}
		},

		onPickedDestination(nodes: Node[]) {
			const node = nodes[0]
			if (node) {
				this.$emit('update:destination', node.path)
			}
		},
	},
})
</script>
<style scoped>
.file-request-dialog__note :deep(textarea) {
	width: 100% !important;
	min-height: 80px;
}
</style>