Skip to content

Commit 29a0e33

Browse files
authored
Merge pull request #47564 from nextcloud/backport/47290/stable30
[stable30] feat(templates): add support for checkboxes in template filler
2 parents c24ca3c + 31aae22 commit 29a0e33

18 files changed

Lines changed: 257 additions & 39 deletions

apps/files/src/components/TemplateFiller.vue

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,8 @@
99
<form>
1010
<h3>{{ t('files', 'Fill template fields') }}</h3>
1111

12-
<!-- We will support more than just text fields in the future -->
1312
<div v-for="field in fields" :key="field.index">
14-
<TemplateTextField v-if="field.type == 'rich-text'"
15-
:field="field"
16-
@input="trackInput" />
13+
<component :is="getFieldComponent(field.type)" :field="field" @input="trackInput" />
1714
</div>
1815
</form>
1916
</div>
@@ -29,11 +26,12 @@
2926
</NcModal>
3027
</template>
3128

32-
<script lang="ts">
29+
<script>
3330
import { defineComponent } from 'vue'
3431
import { NcModal, NcButton, NcLoadingIcon } from '@nextcloud/vue'
3532
import { translate as t } from '@nextcloud/l10n'
36-
import TemplateTextField from './TemplateFiller/TemplateTextField.vue'
33+
import TemplateRichTextField from './TemplateFiller/TemplateRichTextField.vue'
34+
import TemplateCheckboxField from './TemplateFiller/TemplateCheckboxField.vue'
3735
3836
export default defineComponent({
3937
name: 'TemplateFiller',
@@ -42,7 +40,8 @@ export default defineComponent({
4240
NcModal,
4341
NcButton,
4442
NcLoadingIcon,
45-
TemplateTextField,
43+
TemplateRichTextField,
44+
TemplateCheckboxField,
4645
},
4746
4847
props: {
@@ -65,10 +64,21 @@ export default defineComponent({
6564
6665
methods: {
6766
t,
68-
trackInput([value, index]) {
69-
this.localFields[index] = {
70-
content: value,
67+
trackInput({ index, property, value }) {
68+
if (!this.localFields[index]) {
69+
this.localFields[index] = {}
7170
}
71+
72+
this.localFields[index][property] = value
73+
},
74+
getFieldComponent(fieldType) {
75+
const fieldComponentType = fieldType.split('-')
76+
.map((str) => {
77+
return str.charAt(0).toUpperCase() + str.slice(1)
78+
})
79+
.join('')
80+
81+
return `Template${fieldComponentType}Field`
7282
},
7383
async submit() {
7484
this.loading = true
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<!--
2+
- SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
3+
- SPDX-License-Identifier: AGPL-3.0-or-later
4+
-->
5+
6+
<template>
7+
<div class="template-field__checkbox">
8+
<NcCheckboxRadioSwitch :id="fieldId"
9+
:checked.sync="value"
10+
type="switch"
11+
@update:checked="input">
12+
{{ fieldLabel }}
13+
</NcCheckboxRadioSwitch>
14+
</div>
15+
</template>
16+
17+
<script lang="ts">
18+
import { defineComponent } from 'vue'
19+
import { NcCheckboxRadioSwitch } from '@nextcloud/vue'
20+
21+
export default defineComponent({
22+
name: 'TemplateCheckboxField',
23+
24+
components: {
25+
NcCheckboxRadioSwitch,
26+
},
27+
28+
props: {
29+
field: {
30+
type: Object,
31+
default: () => {},
32+
},
33+
},
34+
35+
data() {
36+
return {
37+
value: this.field.checked ?? false,
38+
}
39+
},
40+
41+
computed: {
42+
fieldLabel() {
43+
const label = this.field.name ?? this.field.alias ?? 'Unknown field'
44+
45+
return label.charAt(0).toUpperCase() + label.slice(1)
46+
},
47+
fieldId() {
48+
return 'checkbox-field' + this.field.index
49+
},
50+
},
51+
52+
methods: {
53+
input() {
54+
this.$emit('input', {
55+
index: this.field.index,
56+
property: 'checked',
57+
value: this.value,
58+
})
59+
},
60+
},
61+
})
62+
</script>
63+
64+
<style lang="scss" scoped>
65+
.template-field__checkbox {
66+
margin: 20px 0;
67+
}
68+
</style>

apps/files/src/components/TemplateFiller/TemplateTextField.vue renamed to apps/files/src/components/TemplateFiller/TemplateRichTextField.vue

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
:label="fieldLabel"
1616
:label-outside="true"
1717
:placeholder="field.content"
18-
@input="$emit('input', [value, field.index])" />
18+
@input="input" />
1919
</div>
2020
</template>
2121

@@ -24,7 +24,7 @@ import { defineComponent } from 'vue'
2424
import { NcTextField } from '@nextcloud/vue'
2525
2626
export default defineComponent({
27-
name: 'TemplateTextField',
27+
name: 'TemplateRichTextField',
2828
2929
components: {
3030
NcTextField,
@@ -53,6 +53,16 @@ export default defineComponent({
5353
return 'text-field' + this.field.index
5454
},
5555
},
56+
57+
methods: {
58+
input() {
59+
this.$emit('input', {
60+
index: this.field.index,
61+
property: 'content',
62+
value: this.value,
63+
})
64+
},
65+
},
5666
})
5767
</script>
5868

dist/1218-1218.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/1218-1218.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/1218-1218.js.map.license

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1218-1218.js.license

dist/7493-7493.js

Lines changed: 0 additions & 2 deletions
This file was deleted.

dist/7493-7493.js.map

Lines changed: 0 additions & 1 deletion
This file was deleted.

dist/7493-7493.js.map.license

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)