aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files/src/components/TemplateFiller.vue
blob: 926bcdd4dfd244c58608871bd93abb38ad07b681 (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
<!--
  - SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
  - SPDX-License-Identifier: AGPL-3.0-or-later
-->

<template>
	<NcModal>
		<div class="template-field-modal__content">
			<form>
				<h3>{{ t('files', 'Fill template fields') }}</h3>

				<!-- We will support more than just text fields in the future -->
				<div v-for="field in fields" :key="field.index">
					<TemplateTextField v-if="field.type == 'rich-text'"
						:field="field"
						@input="trackInput" />
				</div>
			</form>
		</div>

		<div class="template-field-modal__buttons">
			<NcLoadingIcon v-if="loading" :name="t('files', 'Submitting fields…')" />
			<NcButton aria-label="Submit button"
				type="primary"
				@click="submit">
				{{ t('files', 'Submit') }}
			</NcButton>
		</div>
	</NcModal>
</template>

<script lang="ts">
import { defineComponent } from 'vue'
import { NcModal, NcButton, NcLoadingIcon } from '@nextcloud/vue'
import { translate as t } from '@nextcloud/l10n'
import TemplateTextField from './TemplateFiller/TemplateTextField.vue'

export default defineComponent({
	name: 'TemplateFiller',

	components: {
		NcModal,
		NcButton,
		NcLoadingIcon,
		TemplateTextField,
	},

	props: {
		fields: {
			type: Array,
			default: () => [],
		},
		onSubmit: {
			type: Function,
			default: async () => {},
		},
	},

	data() {
		return {
			localFields: {},
			loading: false,
		}
	},

	methods: {
		t,
		trackInput([value, index]) {
			this.localFields[index] = {
				content: value,
			}
		},
		async submit() {
			this.loading = true

			await this.onSubmit(this.localFields)

			this.$emit('close')
		},
	},
})
</script>

<style lang="scss" scoped>
$modal-margin: calc(var(--default-grid-baseline) * 4);

.template-field-modal__content {
	padding: $modal-margin;

	h3 {
		text-align: center;
	}
}

.template-field-modal__buttons {
	display: flex;
	justify-content: flex-end;
	gap: var(--default-grid-baseline);
	margin: $modal-margin;
	margin-top: 0;
}
</style>