aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files/src
diff options
context:
space:
mode:
authorElizabeth Danzberger <lizzy7128@tutanota.de>2024-08-15 14:38:02 -0400
committerElizabeth Danzberger <lizzy7128@tutanota.de>2024-08-27 14:41:58 -0400
commit79d005e11fbdb0587ffff2f437721218fb29bade (patch)
treec988388dfbdf8ef5e269e1177f2ed323ddbb3034 /apps/files/src
parent95fff6bc72f1f05050d87ef5f7bfb7ce5c5214af (diff)
downloadnextcloud-server-79d005e11fbdb0587ffff2f437721218fb29bade.tar.gz
nextcloud-server-79d005e11fbdb0587ffff2f437721218fb29bade.zip
feat(templates): add support for checkboxes in template filler
Signed-off-by: Elizabeth Danzberger <lizzy7128@tutanota.de>
Diffstat (limited to 'apps/files/src')
-rw-r--r--apps/files/src/components/TemplateFiller.vue30
-rw-r--r--apps/files/src/components/TemplateFiller/TemplateCheckboxField.vue68
-rw-r--r--apps/files/src/components/TemplateFiller/TemplateRichTextField.vue (renamed from apps/files/src/components/TemplateFiller/TemplateTextField.vue)14
3 files changed, 100 insertions, 12 deletions
diff --git a/apps/files/src/components/TemplateFiller.vue b/apps/files/src/components/TemplateFiller.vue
index 926bcdd4dfd..bd3c28d585f 100644
--- a/apps/files/src/components/TemplateFiller.vue
+++ b/apps/files/src/components/TemplateFiller.vue
@@ -9,11 +9,8 @@
<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" />
+ <component :is="getFieldComponent(field.type)" :field="field" @input="trackInput" />
</div>
</form>
</div>
@@ -29,11 +26,12 @@
</NcModal>
</template>
-<script lang="ts">
+<script>
import { defineComponent } from 'vue'
import { NcModal, NcButton, NcLoadingIcon } from '@nextcloud/vue'
import { translate as t } from '@nextcloud/l10n'
-import TemplateTextField from './TemplateFiller/TemplateTextField.vue'
+import TemplateRichTextField from './TemplateFiller/TemplateRichTextField.vue'
+import TemplateCheckboxField from './TemplateFiller/TemplateCheckboxField.vue'
export default defineComponent({
name: 'TemplateFiller',
@@ -42,7 +40,8 @@ export default defineComponent({
NcModal,
NcButton,
NcLoadingIcon,
- TemplateTextField,
+ TemplateRichTextField,
+ TemplateCheckboxField,
},
props: {
@@ -65,10 +64,21 @@ export default defineComponent({
methods: {
t,
- trackInput([value, index]) {
- this.localFields[index] = {
- content: value,
+ trackInput({ index, property, value }) {
+ if (!this.localFields[index]) {
+ this.localFields[index] = {}
}
+
+ this.localFields[index][property] = value
+ },
+ getFieldComponent(fieldType) {
+ const fieldComponentType = fieldType.split('-')
+ .map((str) => {
+ return str.charAt(0).toUpperCase() + str.slice(1)
+ })
+ .join('')
+
+ return `Template${fieldComponentType}Field`
},
async submit() {
this.loading = true
diff --git a/apps/files/src/components/TemplateFiller/TemplateCheckboxField.vue b/apps/files/src/components/TemplateFiller/TemplateCheckboxField.vue
new file mode 100644
index 00000000000..632944f1bab
--- /dev/null
+++ b/apps/files/src/components/TemplateFiller/TemplateCheckboxField.vue
@@ -0,0 +1,68 @@
+<!--
+ - SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
+ - SPDX-License-Identifier: AGPL-3.0-or-later
+-->
+
+<template>
+ <div class="template-field__checkbox">
+ <NcCheckboxRadioSwitch :id="fieldId"
+ :checked.sync="value"
+ type="switch"
+ @update:checked="input">
+ {{ fieldLabel }}
+ </NcCheckboxRadioSwitch>
+ </div>
+</template>
+
+<script lang="ts">
+import { defineComponent } from 'vue'
+import { NcCheckboxRadioSwitch } from '@nextcloud/vue'
+
+export default defineComponent({
+ name: 'TemplateCheckboxField',
+
+ components: {
+ NcCheckboxRadioSwitch,
+ },
+
+ props: {
+ field: {
+ type: Object,
+ default: () => {},
+ },
+ },
+
+ data() {
+ return {
+ value: this.field.checked ?? false,
+ }
+ },
+
+ computed: {
+ fieldLabel() {
+ const label = this.field.name ?? this.field.alias ?? 'Unknown field'
+
+ return label.charAt(0).toUpperCase() + label.slice(1)
+ },
+ fieldId() {
+ return 'checkbox-field' + this.field.index
+ },
+ },
+
+ methods: {
+ input() {
+ this.$emit('input', {
+ index: this.field.index,
+ property: 'checked',
+ value: this.value,
+ })
+ },
+ },
+})
+</script>
+
+<style lang="scss" scoped>
+.template-field__checkbox {
+ margin: 20px 0;
+}
+</style>
diff --git a/apps/files/src/components/TemplateFiller/TemplateTextField.vue b/apps/files/src/components/TemplateFiller/TemplateRichTextField.vue
index b58e17971c7..7246b2743d6 100644
--- a/apps/files/src/components/TemplateFiller/TemplateTextField.vue
+++ b/apps/files/src/components/TemplateFiller/TemplateRichTextField.vue
@@ -15,7 +15,7 @@
:label="fieldLabel"
:label-outside="true"
:placeholder="field.content"
- @input="$emit('input', [value, field.index])" />
+ @input="input" />
</div>
</template>
@@ -24,7 +24,7 @@ import { defineComponent } from 'vue'
import { NcTextField } from '@nextcloud/vue'
export default defineComponent({
- name: 'TemplateTextField',
+ name: 'TemplateRichTextField',
components: {
NcTextField,
@@ -53,6 +53,16 @@ export default defineComponent({
return 'text-field' + this.field.index
},
},
+
+ methods: {
+ input() {
+ this.$emit('input', {
+ index: this.field.index,
+ property: 'content',
+ value: this.value,
+ })
+ },
+ },
})
</script>