-
-
Notifications
You must be signed in to change notification settings - Fork 621
Expand file tree
/
Copy pathImportSettings.vue
More file actions
131 lines (110 loc) · 4.12 KB
/
ImportSettings.vue
File metadata and controls
131 lines (110 loc) · 4.12 KB
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
<template>
<StackHeader :title="__('Linked fieldset')" icon="fieldsets">
<template #actions>
<Button variant="primary" @click.prevent="commit" :text="__('Apply')" />
<Button v-if="isInsideSet" variant="primary" @click.prevent="commit(true)" :text="__('Apply & Close All')" />
</template>
</StackHeader>
<StackContent>
<CardPanel :heading="__('Linked fieldset')">
<div class="publish-fields">
<Field :label="__('Fieldset')" :instructions="__('messages.fieldset_import_fieldset_instructions')" class="form-group field-w-100">
<Input autofocus :model-value="config.fieldset" @update:model-value="updateField('fieldset', $event)" />
</Field>
<Field :label="__('Prefix')" :instructions="__('messages.fieldset_import_prefix_instructions')" class="form-group field-w-100">
<Input autofocus :model-value="config.prefix" @update:model-value="updateField('prefix', $event)" />
</Field>
<Field
v-if="fieldsetHasSections"
:label="__('Section Behavior')"
:instructions="sectionBehaviorInstructions"
class="form-group field-w-100"
>
<RadioGroup
:model-value="sectionBehavior"
@update:model-value="updateField('section_behavior', $event)"
>
<Radio
v-for="option in sectionBehaviorOptions"
:key="option.value"
:label="option.label"
:description="option.description"
:value="option.value"
/>
</RadioGroup>
</Field>
</div>
</CardPanel>
</StackContent>
</template>
<script>
import { Button, Heading, CardPanel, Field, Input, StackHeader, StackContent, RadioGroup, Radio } from '@/components/ui';
export default {
components: { StackContent, StackHeader, Heading, Button, CardPanel, Field, Input, RadioGroup, Radio },
props: ['config', 'isInsideSet'],
inject: {
commitParentField: {
default: () => {}
}
},
model: {
prop: 'config',
event: 'input',
},
data: function () {
return {
values: clone(this.config),
};
},
computed: {
fieldsetMeta() {
const handle = this.values.fieldset;
return this.$page?.props?.fieldsets?.[handle] ?? null;
},
fieldsetHasSections() {
return this.fieldsetMeta?.has_sections === true;
},
sectionBehavior() {
return this.values.section_behavior ?? 'preserve';
},
sectionBehaviorInstructions() {
return __('Choose whether imported fieldset sections should be preserved or flattened into this section.');
},
sectionBehaviorOptions() {
return [
{
label: __('Preserve'),
description: __('Keep imported sections as-is.'),
value: 'preserve',
},
{
label: __('Flatten'),
description: __('Merge all fields into this section.'),
value: 'flatten',
},
];
},
},
methods: {
focus() {
this.$els.display.select();
},
updateField(handle, value) {
this.values[handle] = value;
if (handle === 'fieldset' && ! this.fieldsetHasSections) {
this.values.section_behavior = 'preserve';
}
},
commit(shouldCommitParent = false) {
this.$emit('committed', this.values);
this.close();
if (shouldCommitParent && this.commitParentField) {
this.commitParentField(true);
}
},
close() {
this.$emit('closed');
},
},
};
</script>