Skip to content

Commit b07fd22

Browse files
refact: New ModelForm component
1 parent 806b5b1 commit b07fd22

File tree

7 files changed

+78
-36
lines changed

7 files changed

+78
-36
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<template>
2+
<form
3+
class="k-model-form"
4+
method="POST"
5+
@submit.prevent="$emit('submit', $event)"
6+
>
7+
<k-grid variant="columns">
8+
<k-column
9+
v-for="(column, columnIndex) in columns"
10+
:key="api + '-column-' + columnIndex"
11+
:width="column.width"
12+
:sticky="column.sticky"
13+
>
14+
<k-fieldset
15+
ref="fields"
16+
:disabled="lock && lock.state === 'lock'"
17+
:fields="fieldsWithAdditionalData(column.fields)"
18+
:value="content"
19+
:validate="true"
20+
@input="$emit('input', $event)"
21+
@submit="$emit('submit', $event)"
22+
/>
23+
</k-column>
24+
</k-grid>
25+
</form>
26+
</template>
27+
28+
<script>
29+
export default {
30+
props: {
31+
api: String,
32+
columns: Object,
33+
content: Object,
34+
diff: Object,
35+
lock: [Boolean, Object]
36+
},
37+
emits: ["input", "submit"],
38+
methods: {
39+
fieldsWithAdditionalData(fields) {
40+
const result = {};
41+
42+
for (const name in fields) {
43+
result[name] = {
44+
...fields[name],
45+
endpoints: {
46+
field: this.api + "/fields/" + name,
47+
model: this.api
48+
},
49+
hasDiff: Object.hasOwn(this.diff ?? {}, name)
50+
};
51+
}
52+
53+
return result;
54+
}
55+
}
56+
};
57+
</script>

panel/src/components/Forms/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import Fieldset from "./Fieldset.vue";
55
import Form from "./Form.vue";
66
import FormControls from "./FormControls.vue";
77
import Input from "./Input.vue";
8+
import ModelForm from "./ModelForm.vue";
89

910
/* Form parts */
1011
import Blocks from "./Blocks/index.js";
@@ -22,6 +23,7 @@ export default {
2223
app.component("k-form", Form);
2324
app.component("k-form-controls", FormControls);
2425
app.component("k-input", Input);
26+
app.component("k-model-form", ModelForm);
2527

2628
app.use(Blocks);
2729
app.use(Inputs);

panel/src/components/Views/Files/FileView.vue

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,12 @@
4040

4141
<k-model-tabs :diff="diff" :tab="tab.name" :tabs="tabs" />
4242

43-
<k-sections
44-
:blueprint="blueprint"
43+
<k-model-form
44+
:api="api"
45+
:columns="tab.columns"
4546
:content="content"
46-
:empty="
47-
$panel.config.debug
48-
? $t('file.blueprint', { blueprint: $esc(blueprint) })
49-
: null
50-
"
47+
:diff="diff"
5148
:lock="lock"
52-
:parent="api"
53-
:tab="tab"
5449
@input="onInput"
5550
@submit="onSubmit"
5651
/>

panel/src/components/Views/Pages/PageView.vue

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,12 @@
3333

3434
<k-model-tabs :diff="diff" :tab="tab.name" :tabs="tabs" />
3535

36-
<k-sections
37-
:blueprint="blueprint"
36+
<k-model-form
37+
:api="api"
38+
:columns="tab.columns"
3839
:content="content"
39-
:empty="
40-
$panel.config.debug
41-
? $t('page.blueprint', { blueprint: $esc(blueprint) })
42-
: null
43-
"
40+
:diff="diff"
4441
:lock="lock"
45-
:parent="api"
46-
:tab="tab"
4742
@input="onInput"
4843
@submit="onSubmit"
4944
/>

panel/src/components/Views/Pages/SiteView.vue

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,12 @@
3737

3838
<k-model-tabs :diff="diff" :tab="tab.name" :tabs="tabs" />
3939

40-
<k-sections
41-
:blueprint="blueprint"
40+
<k-model-form
41+
:api="api"
42+
:columns="tab.columns"
4243
:content="content"
43-
:empty="$panel.config.debug ? $t('site.blueprint') : null"
44+
:diff="diff"
4445
:lock="lock"
45-
:tab="tab"
46-
parent="site"
4746
@input="onInput"
4847
@submit="onSubmit"
4948
/>

panel/src/components/Views/Preview/PreviewForm.vue

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,16 @@
2121
</header>
2222

2323
<div class="k-preview-form-body">
24-
<k-sections
25-
:blueprint="blueprint"
24+
<k-model-form
25+
:api="api"
26+
:columns="tab.columns"
2627
:content="content"
2728
:empty="
2829
$panel.config.debug
2930
? $t('page.blueprint', { blueprint: $esc(blueprint) })
3031
: null
3132
"
3233
:lock="lock"
33-
:parent="api"
34-
:tab="tab"
3534
@input="$emit('input', $event)"
3635
@submit="$emit('submit', $event)"
3736
/>

panel/src/components/Views/Users/UserView.vue

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,12 @@
5454

5555
<k-model-tabs :diff="diff" :tab="tab.name" :tabs="tabs" />
5656

57-
<k-sections
58-
:blueprint="blueprint"
57+
<k-model-form
58+
:api="api"
59+
:columns="tab.columns"
5960
:content="content"
60-
:empty="
61-
$panel.config.debug
62-
? $t('user.blueprint', { blueprint: $esc(blueprint) })
63-
: null
64-
"
61+
:diff="diff"
6562
:lock="lock"
66-
:parent="api"
67-
:tab="tab"
6863
@input="onInput"
6964
@submit="onSubmit"
7065
/>

0 commit comments

Comments
 (0)