@mapomodule/uikit 1.0.0-alpha.21 → 1.0.0-alpha.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +28 -0
- package/components/Detail/Detail.vue +230 -357
- package/components/Form/Form.vue +224 -0
- package/components/{Detail/DetailField.vue → Form/FormField.vue} +32 -15
- package/components/Form/FormGroup.vue +88 -0
- package/components/Form/FormTabs.vue +134 -0
- package/components/{Detail → Form}/defaults.js +0 -0
- package/components/{fields → Form/fields}/DateField.vue +0 -0
- package/components/{fields → Form/fields}/FileField.vue +0 -0
- package/components/{fields → Form/fields}/FksField.vue +0 -0
- package/components/{fields → Form/fields}/MediaField.vue +0 -0
- package/components/{fields → Form/fields}/MediaM2mField.vue +0 -0
- package/components/Form/fields/Repeater.vue +562 -0
- package/components/{fields → Form/fields}/SeoPreview.vue +0 -0
- package/components/{fields → Form/fields}/wygEditor/defaults.js +0 -0
- package/components/{fields → Form/fields}/wygEditor/utils/events.js +0 -0
- package/components/{fields → Form/fields}/wygEditor/utils/mapomedia.plugin.js +0 -0
- package/components/{fields → Form/fields}/wygEditor/utils/script.injector.js +0 -0
- package/components/{fields → Form/fields}/wygEditor/wygEditor.vue +0 -0
- package/components/List/ListQuickEdit.vue +17 -100
- package/components/List/ListTable.vue +4 -6
- package/module.js +1 -1
- package/package.json +3 -3
- package/components/fields/Repeater.vue +0 -338
|
@@ -30,65 +30,23 @@
|
|
|
30
30
|
<slot name="body.top" v-bind="slotBindings"></slot>
|
|
31
31
|
|
|
32
32
|
<slot name="body" v-bind="slotBindings">
|
|
33
|
-
<
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
class="col-12"
|
|
51
|
-
:class="fields.class"
|
|
52
|
-
>
|
|
53
|
-
<!-- This is a dynamic slot. You can use it to override a field component. For example use `qedit.fields.title` to override the component of the field with value `title`. -->
|
|
54
|
-
<slot
|
|
55
|
-
:name="fields.slotName"
|
|
56
|
-
v-bind="{
|
|
57
|
-
conf: fields,
|
|
58
|
-
...slotBindings,
|
|
59
|
-
}"
|
|
60
|
-
>
|
|
61
|
-
<!-- A [`DetailField`](/components/detail/DetailField/) configured by a [`FieldConfiguration`](#fieldconfiguration). -->
|
|
62
|
-
<DetailField
|
|
63
|
-
v-model="model"
|
|
64
|
-
:langs="langs"
|
|
65
|
-
:currentLang="currentLang"
|
|
66
|
-
:conf="fields"
|
|
67
|
-
:errors="errors"
|
|
68
|
-
/>
|
|
69
|
-
</slot>
|
|
70
|
-
</div>
|
|
71
|
-
</div>
|
|
72
|
-
</div>
|
|
73
|
-
</v-card>
|
|
74
|
-
<slot
|
|
75
|
-
v-else
|
|
76
|
-
:name="field.slotName"
|
|
77
|
-
v-bind="{
|
|
78
|
-
conf: field,
|
|
79
|
-
...slotBindings,
|
|
80
|
-
}"
|
|
81
|
-
>
|
|
82
|
-
<DetailField
|
|
83
|
-
v-model="model"
|
|
84
|
-
:langs="langs"
|
|
85
|
-
:currentLang="currentLang"
|
|
86
|
-
:conf="field"
|
|
87
|
-
:errors="errors"
|
|
88
|
-
/>
|
|
89
|
-
</slot>
|
|
90
|
-
</div>
|
|
91
|
-
</v-row>
|
|
33
|
+
<Form
|
|
34
|
+
v-model="model"
|
|
35
|
+
:currentLang="currentLang"
|
|
36
|
+
:languages="langs"
|
|
37
|
+
:errors="errors"
|
|
38
|
+
:fields="editFields"
|
|
39
|
+
:modeSlotBindings="slotBindings"
|
|
40
|
+
>
|
|
41
|
+
<template v-for="(_, slot) in $slots" :slot="slot">
|
|
42
|
+
<!-- @vuese-ignore -->
|
|
43
|
+
<slot :name="slot"></slot>
|
|
44
|
+
</template>
|
|
45
|
+
<template v-for="(_, slot) in $scopedSlots" v-slot:[slot]="props">
|
|
46
|
+
<!-- @vuese-ignore -->
|
|
47
|
+
<slot :name="slot" v-bind="props" />
|
|
48
|
+
</template>
|
|
49
|
+
</Form>
|
|
92
50
|
</slot>
|
|
93
51
|
<!-- Use this to add content under the main body. -->
|
|
94
52
|
<slot name="body.bottom" v-bind="slotBindings"></slot>
|
|
@@ -175,14 +133,8 @@ export default {
|
|
|
175
133
|
this.close();
|
|
176
134
|
}
|
|
177
135
|
},
|
|
178
|
-
currentLang() {
|
|
179
|
-
this.initLang();
|
|
180
|
-
},
|
|
181
136
|
},
|
|
182
137
|
computed: {
|
|
183
|
-
computedFields() {
|
|
184
|
-
return this.mapConf(this.editFields || []);
|
|
185
|
-
},
|
|
186
138
|
langs() {
|
|
187
139
|
return this.model?.lang_info?.site_languages.map((l) => l.id) || this.languages || [];
|
|
188
140
|
},
|
|
@@ -211,7 +163,6 @@ export default {
|
|
|
211
163
|
this.isNew = !item;
|
|
212
164
|
this.modelBkp = await this.fetchItem(item);
|
|
213
165
|
this.model = deepClone(this.modelBkp);
|
|
214
|
-
this.initLang();
|
|
215
166
|
this.dialog = true;
|
|
216
167
|
this.$refs.form?.resetValidation();
|
|
217
168
|
return new Promise((resolve, reject) => {
|
|
@@ -231,40 +182,6 @@ export default {
|
|
|
231
182
|
this.resolve && this.resolve(res);
|
|
232
183
|
this.dialog = false;
|
|
233
184
|
},
|
|
234
|
-
parseConf(field, i) {
|
|
235
|
-
const conf = typeof field === "string" ? { value: field } : field;
|
|
236
|
-
conf.value = conf.value || "";
|
|
237
|
-
conf.value = conf.value.replace(
|
|
238
|
-
new RegExp(`^translations\.(${this.langs.join("|")})\.?`),
|
|
239
|
-
""
|
|
240
|
-
);
|
|
241
|
-
conf.slotName = `fields.${conf.value || i}`;
|
|
242
|
-
if (this.currentLang && !field.synci18n) {
|
|
243
|
-
const base = `translations.${this.currentLang}`;
|
|
244
|
-
conf.value = (conf.value && `${base}.${conf.value}`) || base;
|
|
245
|
-
}
|
|
246
|
-
return conf;
|
|
247
|
-
},
|
|
248
|
-
mapConf(fields) {
|
|
249
|
-
const icon = "mdi-cube-outline";
|
|
250
|
-
const parseGroup = (group) =>
|
|
251
|
-
typeof group === "string"
|
|
252
|
-
? { name: group, icon }
|
|
253
|
-
: { ...group, icon: group.icon !== undefined ? group.icon : icon };
|
|
254
|
-
return fields.map((f, i) =>
|
|
255
|
-
f.group
|
|
256
|
-
? { group: parseGroup(f.group), fields: this.mapConf(f.fields) }
|
|
257
|
-
: this.parseConf(f, i)
|
|
258
|
-
);
|
|
259
|
-
},
|
|
260
|
-
initLang(lang = this.currentLang) {
|
|
261
|
-
if (lang && !this.model.translations) {
|
|
262
|
-
this.model.translations = {};
|
|
263
|
-
}
|
|
264
|
-
if (lang && !this.model.translations[lang]) {
|
|
265
|
-
this.model.translations[lang] = {};
|
|
266
|
-
}
|
|
267
|
-
},
|
|
268
185
|
async fetchItem(item) {
|
|
269
186
|
if (!this.offline && item && item[this.lookup]) {
|
|
270
187
|
return await this.crud.detail(item[this.lookup]);
|
|
@@ -131,6 +131,8 @@
|
|
|
131
131
|
<script>
|
|
132
132
|
import { getPointed } from "@mapomodule/utils/helpers/objHelpers";
|
|
133
133
|
import { debounce } from "@mapomodule/utils/helpers/debounce";
|
|
134
|
+
import { nameSpacedSlots } from "@mapomodule/utils/helpers/slots";
|
|
135
|
+
|
|
134
136
|
import Sortable from "sortablejs"
|
|
135
137
|
|
|
136
138
|
export default {
|
|
@@ -234,7 +236,8 @@ export default {
|
|
|
234
236
|
}
|
|
235
237
|
},
|
|
236
238
|
methods: {
|
|
237
|
-
|
|
239
|
+
nameSpacedSlots,
|
|
240
|
+
getPointed,
|
|
238
241
|
getDataFromApi(clearSelection = true) {
|
|
239
242
|
if (clearSelection) {
|
|
240
243
|
this.selection = [];
|
|
@@ -383,11 +386,6 @@ export default {
|
|
|
383
386
|
})
|
|
384
387
|
.then((res) => (res ? callback(item) : null));
|
|
385
388
|
},
|
|
386
|
-
nameSpacedSlots(slots, scope) {
|
|
387
|
-
return Object.keys(slots)
|
|
388
|
-
.filter((name) => name.startsWith(scope))
|
|
389
|
-
.map((name) => name.replace(scope, ""));
|
|
390
|
-
},
|
|
391
389
|
toggleSelectAll() {
|
|
392
390
|
this.selectAll = !this.selectAll;
|
|
393
391
|
},
|
package/module.js
CHANGED
|
@@ -39,7 +39,7 @@ export default async function (moduleOptions) {
|
|
|
39
39
|
|
|
40
40
|
// INJECT COMPONENTS
|
|
41
41
|
this.nuxt.hook('components:dirs', (dirs) => {
|
|
42
|
-
const mapoComponents = ['components', 'components/fields', 'components/layout']
|
|
42
|
+
const mapoComponents = ['components', 'components/Form/fields', 'components/layout']
|
|
43
43
|
mapoComponents.forEach(d => dirs.unshift({ path: path.resolve(__dirname, d)}))
|
|
44
44
|
})
|
|
45
45
|
this.nuxt.hook('components:extend', (components) => {
|
package/package.json
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mapomodule/uikit",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.22",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "This is part of Mapo nuxt module. Injects Mapo ui components in the nuxt component discovery system.",
|
|
6
6
|
"author": "bnznamco <gabriele.baldi.01@gmail.com>",
|
|
7
7
|
"repository": "https://github.com/lotrekagency/mapo",
|
|
8
8
|
"main": "./module.js",
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"@mapomodule/utils": "^1.0.0-alpha.
|
|
10
|
+
"@mapomodule/utils": "^1.0.0-alpha.22",
|
|
11
11
|
"@nuxtjs/vuetify": "^1.12.3",
|
|
12
12
|
"vuedraggable": "^2.24.3"
|
|
13
13
|
},
|
|
14
14
|
"publishConfig": {
|
|
15
15
|
"access": "public"
|
|
16
16
|
},
|
|
17
|
-
"gitHead": "
|
|
17
|
+
"gitHead": "49f5a6c1ed148cfdaf80a6b610ffc4233aa177cb"
|
|
18
18
|
}
|
|
@@ -1,338 +0,0 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<div class="container pa-0">
|
|
3
|
-
<span class="repeater-label">{{ label }}:</span>
|
|
4
|
-
<v-divider />
|
|
5
|
-
<draggable
|
|
6
|
-
v-model="items"
|
|
7
|
-
handle=".repeater-handle-sort"
|
|
8
|
-
animation="150"
|
|
9
|
-
@change="sortCallback({ ...$event, items, eventType: 'move' })"
|
|
10
|
-
>
|
|
11
|
-
<div
|
|
12
|
-
class="repeater-wrapper"
|
|
13
|
-
v-for="(model, index) in items"
|
|
14
|
-
:key="index"
|
|
15
|
-
>
|
|
16
|
-
<div class="d-flex">
|
|
17
|
-
<v-divider vertical />
|
|
18
|
-
<div class="row ma-0">
|
|
19
|
-
<div
|
|
20
|
-
v-for="(field, i) in parseFields(model)"
|
|
21
|
-
:key="i"
|
|
22
|
-
:class="field.class || 'col-12'"
|
|
23
|
-
>
|
|
24
|
-
<DetailField
|
|
25
|
-
v-model="items[index]"
|
|
26
|
-
:conf="field"
|
|
27
|
-
:errors="getErrors(index)"
|
|
28
|
-
/>
|
|
29
|
-
</div>
|
|
30
|
-
</div>
|
|
31
|
-
<div class="repeater-side-bar grey lighten-2">
|
|
32
|
-
<span
|
|
33
|
-
class="repeater-counter grey--text text--darken-2 text-truncate"
|
|
34
|
-
>{{ index + 1 }}</span
|
|
35
|
-
>
|
|
36
|
-
<v-tooltip right>
|
|
37
|
-
<template v-slot:activator="{ on, attrs }">
|
|
38
|
-
<v-icon
|
|
39
|
-
v-if="!readonly && sortable"
|
|
40
|
-
v-bind="attrs"
|
|
41
|
-
v-on="on"
|
|
42
|
-
color="grey darken-3"
|
|
43
|
-
class="grey lighten-2 repeater-action repeater-add-line-index"
|
|
44
|
-
@click="addItem(index)"
|
|
45
|
-
>mdi-plus-circle-outline</v-icon
|
|
46
|
-
>
|
|
47
|
-
</template>
|
|
48
|
-
<span>Add here</span>
|
|
49
|
-
</v-tooltip>
|
|
50
|
-
<v-tooltip right>
|
|
51
|
-
<template v-slot:activator="{ on, attrs }">
|
|
52
|
-
<v-hover v-slot="{ hover }">
|
|
53
|
-
<v-icon
|
|
54
|
-
v-if="!readonly"
|
|
55
|
-
v-bind="attrs"
|
|
56
|
-
v-on="on"
|
|
57
|
-
:color="hover ? 'error' : 'grey darken-3'"
|
|
58
|
-
class="repeater-action repeater-remove-line"
|
|
59
|
-
@click="removeItem(index)"
|
|
60
|
-
>mdi-minus-circle-outline</v-icon
|
|
61
|
-
>
|
|
62
|
-
</v-hover>
|
|
63
|
-
</template>
|
|
64
|
-
<span>Remove</span>
|
|
65
|
-
</v-tooltip>
|
|
66
|
-
<v-icon
|
|
67
|
-
v-if="!readonly && sortable"
|
|
68
|
-
color="grey darken-3"
|
|
69
|
-
class="repeater-action repeater-handle-sort"
|
|
70
|
-
>mdi-drag</v-icon
|
|
71
|
-
>
|
|
72
|
-
</div>
|
|
73
|
-
</div>
|
|
74
|
-
<v-divider />
|
|
75
|
-
</div>
|
|
76
|
-
</draggable>
|
|
77
|
-
<div class="d-flex justify-end">
|
|
78
|
-
<v-btn
|
|
79
|
-
class="repeater-add-line"
|
|
80
|
-
@click="addItem"
|
|
81
|
-
:disabled="readonly"
|
|
82
|
-
outlined
|
|
83
|
-
tile
|
|
84
|
-
text
|
|
85
|
-
>
|
|
86
|
-
<v-icon>mdi-plus</v-icon> Add</v-btn
|
|
87
|
-
>
|
|
88
|
-
</div>
|
|
89
|
-
<v-dialog v-if="hasTemplates" v-model="tModalOpen" width="600" scrollable>
|
|
90
|
-
<v-card>
|
|
91
|
-
<v-card-title class="text-h5"> Select template </v-card-title>
|
|
92
|
-
<v-card-text>
|
|
93
|
-
<div class="row mt-4">
|
|
94
|
-
<div
|
|
95
|
-
v-for="(template, i) in templates"
|
|
96
|
-
:key="i"
|
|
97
|
-
class="col-12 col-md-6 pa-0"
|
|
98
|
-
>
|
|
99
|
-
<div @click="tModalCallback(template)" class="template-button">
|
|
100
|
-
<span class="text-h5">{{ template.name }}</span
|
|
101
|
-
><br />
|
|
102
|
-
<span>{{ template.description }}</span>
|
|
103
|
-
<v-img
|
|
104
|
-
v-if="template.preview"
|
|
105
|
-
max-height="150"
|
|
106
|
-
min-width="250px"
|
|
107
|
-
:src="template.preview"
|
|
108
|
-
/>
|
|
109
|
-
<v-skeleton-loader
|
|
110
|
-
v-else
|
|
111
|
-
boilerplate
|
|
112
|
-
min-width="250px"
|
|
113
|
-
type="list-item-avatar-three-line"
|
|
114
|
-
/>
|
|
115
|
-
</div>
|
|
116
|
-
</div>
|
|
117
|
-
</div>
|
|
118
|
-
</v-card-text>
|
|
119
|
-
</v-card>
|
|
120
|
-
</v-dialog>
|
|
121
|
-
</div>
|
|
122
|
-
</template>
|
|
123
|
-
|
|
124
|
-
<style lang="scss" scoped>
|
|
125
|
-
.repeater-action {
|
|
126
|
-
display: none;
|
|
127
|
-
}
|
|
128
|
-
.repeater-side-bar {
|
|
129
|
-
min-width: 24px;
|
|
130
|
-
position: relative;
|
|
131
|
-
display: flex;
|
|
132
|
-
flex-direction: column;
|
|
133
|
-
align-content: center;
|
|
134
|
-
justify-content: center;
|
|
135
|
-
&:hover {
|
|
136
|
-
.repeater-action {
|
|
137
|
-
display: inline-flex;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
.repeater-counter {
|
|
141
|
-
position: absolute;
|
|
142
|
-
align-self: center;
|
|
143
|
-
top: 10px;
|
|
144
|
-
}
|
|
145
|
-
.repeater-add-line-index {
|
|
146
|
-
position: absolute;
|
|
147
|
-
align-self: center;
|
|
148
|
-
top: -11px;
|
|
149
|
-
border-radius: 50%;
|
|
150
|
-
}
|
|
151
|
-
.repeater-handle-sort {
|
|
152
|
-
position: absolute;
|
|
153
|
-
align-self: center;
|
|
154
|
-
bottom: 2px;
|
|
155
|
-
cursor: grab;
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
.repeater-add-line {
|
|
159
|
-
border-top: none;
|
|
160
|
-
}
|
|
161
|
-
.template-button {
|
|
162
|
-
padding: 0.5rem;
|
|
163
|
-
margin: 3px;
|
|
164
|
-
border: solid 1px #393939;
|
|
165
|
-
cursor: pointer;
|
|
166
|
-
}
|
|
167
|
-
.theme--light .template-button {
|
|
168
|
-
border-color: #e0e0e0;
|
|
169
|
-
}
|
|
170
|
-
</style>
|
|
171
|
-
|
|
172
|
-
<script>
|
|
173
|
-
import draggable from "vuedraggable";
|
|
174
|
-
|
|
175
|
-
/**
|
|
176
|
-
* This component is made to manage a list of object that can be added/removed/reordered with a simple form.
|
|
177
|
-
*/
|
|
178
|
-
export default {
|
|
179
|
-
name: "Repeater",
|
|
180
|
-
components: {
|
|
181
|
-
// For recursive dynamic components is better to resolve dependencies at runtime to avoid circular deps
|
|
182
|
-
DetailField: () => import("@mapomodule/uikit/components/Detail/DetailField.vue"),
|
|
183
|
-
draggable,
|
|
184
|
-
},
|
|
185
|
-
data() {
|
|
186
|
-
return {
|
|
187
|
-
items: null,
|
|
188
|
-
tModalOpen: false,
|
|
189
|
-
tModalCallback: () => {},
|
|
190
|
-
};
|
|
191
|
-
},
|
|
192
|
-
props: {
|
|
193
|
-
// V-model of the array needed to edit the objects in realtime.
|
|
194
|
-
value: {
|
|
195
|
-
type: Array,
|
|
196
|
-
default: () => [],
|
|
197
|
-
},
|
|
198
|
-
// The main configuration that determines the arrangement of the fields in each line.
|
|
199
|
-
fields: {
|
|
200
|
-
// [`Array<FieldConfiguration>`](/components/Detail/Detail/#fieldconfiguration)
|
|
201
|
-
type: Array | Object,
|
|
202
|
-
default: () => [],
|
|
203
|
-
},
|
|
204
|
-
// Puts the input in an error state and passes through custom error messages.
|
|
205
|
-
errorMessages: {
|
|
206
|
-
type: Array,
|
|
207
|
-
default: () => [],
|
|
208
|
-
},
|
|
209
|
-
// Sets input label.
|
|
210
|
-
label: String,
|
|
211
|
-
// Makes all the repeater items readonly.
|
|
212
|
-
readonly: Boolean,
|
|
213
|
-
// Makes the repeater field sortable.
|
|
214
|
-
sortable: Boolean,
|
|
215
|
-
// Make the repeater multilanguage. This means that it's going to inherit the languages and the current language from the parent detail component, creating the translations for each line of the repeater.
|
|
216
|
-
translatable: Boolean,
|
|
217
|
-
// This callback is called during sort/add/remove item if the Repeater is sortable. Use this callback to change some prop of the items in the list.
|
|
218
|
-
sortCallback: {
|
|
219
|
-
type: Function,
|
|
220
|
-
default: () => {},
|
|
221
|
-
},
|
|
222
|
-
langs: {
|
|
223
|
-
type: Array,
|
|
224
|
-
default: () => [],
|
|
225
|
-
},
|
|
226
|
-
currentLang: String,
|
|
227
|
-
},
|
|
228
|
-
watch: {
|
|
229
|
-
value(val) {
|
|
230
|
-
this.items = val;
|
|
231
|
-
},
|
|
232
|
-
items(val) {
|
|
233
|
-
this.$emit("input", val);
|
|
234
|
-
},
|
|
235
|
-
tModalOpen(val) {
|
|
236
|
-
!val && this.tModalCallback();
|
|
237
|
-
},
|
|
238
|
-
},
|
|
239
|
-
methods: {
|
|
240
|
-
async addItem(index) {
|
|
241
|
-
const element = {};
|
|
242
|
-
if (this.hasTemplates) {
|
|
243
|
-
const template = await this.chooseTemplate();
|
|
244
|
-
if (!template) return;
|
|
245
|
-
element[template.tCodeField] = template.tCode;
|
|
246
|
-
}
|
|
247
|
-
const newIndex = typeof index == "number" ? index : this.items.length;
|
|
248
|
-
this.items.splice(newIndex, 0, element);
|
|
249
|
-
this.sortable &&
|
|
250
|
-
this.sortCallback({
|
|
251
|
-
moved: { element, newIndex },
|
|
252
|
-
items: this.items,
|
|
253
|
-
eventType: "add",
|
|
254
|
-
});
|
|
255
|
-
},
|
|
256
|
-
removeItem(index) {
|
|
257
|
-
const element = this.items[index];
|
|
258
|
-
this.items.splice(index, 1);
|
|
259
|
-
this.sortable &&
|
|
260
|
-
this.sortCallback({
|
|
261
|
-
moved: { element, oldIndex: index },
|
|
262
|
-
items: this.items,
|
|
263
|
-
eventType: "remove",
|
|
264
|
-
});
|
|
265
|
-
},
|
|
266
|
-
async chooseTemplate() {
|
|
267
|
-
this.tModalOpen = true;
|
|
268
|
-
return new Promise((resolve) => {
|
|
269
|
-
this.tModalCallback = function (template) {
|
|
270
|
-
resolve(template);
|
|
271
|
-
this.tModalCallback = () => {};
|
|
272
|
-
this.tModalOpen = false;
|
|
273
|
-
};
|
|
274
|
-
});
|
|
275
|
-
},
|
|
276
|
-
getErrors(index) {
|
|
277
|
-
return (this.errorMessages || [])[index] || {};
|
|
278
|
-
},
|
|
279
|
-
parseConf(field, i) {
|
|
280
|
-
const conf = typeof field === "string" ? { value: field } : field;
|
|
281
|
-
conf.value = conf.value || "";
|
|
282
|
-
conf.value = this.translatable ? conf.value.replace(new RegExp(`^translations\.(${this.langs.join("|")})\.?`), "") : conf.value;
|
|
283
|
-
conf.slotName = `fields.${conf.value || i}`;
|
|
284
|
-
if (this.translatable && this.currentLang && !field.synci18n) {
|
|
285
|
-
const base = `translations.${this.currentLang}`;
|
|
286
|
-
conf.value = (conf.value && `${base}.${conf.value}`) || base;
|
|
287
|
-
}
|
|
288
|
-
if (this.readonly) {
|
|
289
|
-
conf.attrs = { ...conf.attrs, readonly: true };
|
|
290
|
-
}
|
|
291
|
-
return conf;
|
|
292
|
-
},
|
|
293
|
-
mapConf(fields) {
|
|
294
|
-
fields = this.translatable ? JSON.parse(JSON.stringify(fields)) : fields; // this hack fixes rendering loop on translatable repeater. :/
|
|
295
|
-
const icon = "mdi-cube-outline";
|
|
296
|
-
const parseGroup = (group) => typeof group === "string" ? { name: group, icon } : { ...group, icon: group.icon !== undefined ? group.icon : icon };
|
|
297
|
-
return fields.map((f, i) =>
|
|
298
|
-
f.group
|
|
299
|
-
? { group: parseGroup(f.group), fields: this.mapConf(f.fields) }
|
|
300
|
-
: this.parseConf(f, i)
|
|
301
|
-
);
|
|
302
|
-
},
|
|
303
|
-
parseFields(model) {
|
|
304
|
-
if (this.hasTemplates) {
|
|
305
|
-
const template = this.templates.find(t => model[t.tCodeField] == t.tCode)
|
|
306
|
-
return template ? this.mapConf(template.fields) : [];
|
|
307
|
-
}
|
|
308
|
-
return this.mapConf(this.fields);
|
|
309
|
-
},
|
|
310
|
-
},
|
|
311
|
-
computed: {
|
|
312
|
-
hasTemplates() {
|
|
313
|
-
return typeof this.fields == "object" && !Array.isArray(this.fields);
|
|
314
|
-
},
|
|
315
|
-
templates() {
|
|
316
|
-
const templates = {};
|
|
317
|
-
if (this.hasTemplates) {
|
|
318
|
-
const titleCase = (string) => (string && string[0].toUpperCase() + string.slice(1).toLowerCase()) || "";
|
|
319
|
-
Object.keys(this.fields).forEach((tKey) => {
|
|
320
|
-
const tValue = this.fields[tKey];
|
|
321
|
-
const { preview, description } = tValue;
|
|
322
|
-
templates[tKey] = {
|
|
323
|
-
fields: tValue.fields || tValue,
|
|
324
|
-
name: tValue.name || titleCase(tKey.replace(/_/, " ")),
|
|
325
|
-
tCode: tValue.tCode || tKey,
|
|
326
|
-
tCodeField: tValue.tCodeField || "tCode",
|
|
327
|
-
preview, description,
|
|
328
|
-
};
|
|
329
|
-
});
|
|
330
|
-
}
|
|
331
|
-
return Object.values(templates);
|
|
332
|
-
},
|
|
333
|
-
},
|
|
334
|
-
mounted() {
|
|
335
|
-
this.items = this.value;
|
|
336
|
-
},
|
|
337
|
-
};
|
|
338
|
-
</script>
|