-
-
Notifications
You must be signed in to change notification settings - Fork 622
Expand file tree
/
Copy pathBuilder.vue
More file actions
137 lines (117 loc) · 3.87 KB
/
Builder.vue
File metadata and controls
137 lines (117 loc) · 3.87 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
132
133
134
135
136
137
<template>
<div>
<ui-header :title="__('Edit Blueprint')" icon="blueprints">
<template #actions>
<slot name="actions"></slot>
<ui-command-palette-item
:category="$commandPalette.category.Actions"
:text="__('Save')"
icon="save"
:action="save"
prioritize
v-slot="{ text, action }"
>
<ui-button type="submit" variant="primary" @click.prevent="action" v-text="text" />
</ui-command-palette-item>
</template>
</ui-header>
<ui-panel v-if="showTitle" :heading="__('Settings')">
<ui-card class="p-0! divide-y divide-gray-200 dark:divide-gray-800">
<ui-field inline :label="__('Title')" :instructions="__('messages.blueprints_title_instructions')" :errors="errors?.title">
<ui-input v-model="blueprint.title" />
</ui-field>
<ui-field inline :label="__('Hidden')" :instructions="__('messages.blueprints_hidden_instructions')" :error="errors?.hidden" variant="inline">
<ui-switch v-model="blueprint.hidden" />
</ui-field>
</ui-card>
</ui-panel>
<Tabs
class="mt-8"
:single-tab="!useTabs"
:initial-tabs="tabs"
:errors="errors?.tabs"
:can-define-localizable="canDefineLocalizable"
@updated="tabsUpdated"
/>
</div>
</template>
<script>
import SuggestsConditionalFields from './SuggestsConditionalFields';
import Tabs from './Tabs.vue';
import CanDefineLocalizable from '../fields/CanDefineLocalizable';
export default {
mixins: [SuggestsConditionalFields, CanDefineLocalizable],
components: {
Tabs,
},
props: {
action: String,
initialBlueprint: Object,
showTitle: Boolean,
useTabs: { type: Boolean, default: true },
isFormBlueprint: { type: Boolean, default: false },
},
data() {
return {
blueprint: this.initializeBlueprint(),
errors: {},
saveKeyBinding: null,
};
},
computed: {
tabs() {
return this.blueprint.tabs;
},
},
created() {
this.saveKeyBinding = this.$keys.bindGlobal(['mod+s'], (e) => {
e.preventDefault();
this.save();
});
// Listen for root-form-save events from child components
// This also happens on the fieldset builder.
this.$events.$on('root-form-save', () => {
this.save();
});
if (this.isFormBlueprint) {
Statamic.$config.set('isFormBlueprint', true);
}
},
beforeUnmount() {
this.$events.$off('root-form-save');
this.saveKeyBinding.destroy();
},
watch: {
blueprint: {
deep: true,
handler() {
this.$dirty.add('blueprints');
},
},
},
methods: {
initializeBlueprint() {
let blueprint = clone(this.initialBlueprint);
if (!this.showTitle) delete blueprint.title;
return blueprint;
},
tabsUpdated(tabs) {
this.blueprint.tabs = tabs;
},
save() {
this.$axios['patch'](this.action, this.blueprint)
.then((response) => this.saved(response))
.catch((e) => {
console.error('Blueprint save failed:', e);
this.$toast.error(e.response.data.message);
this.errors = e.response.data.errors;
});
},
saved(response) {
this.$toast.success(__('Saved'));
this.errors = {};
this.$dirty.remove('blueprints');
},
},
};
</script>