@mapomodule/uikit 1.0.0-alpha.4 → 1.0.0-alpha.40

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.
Files changed (80) hide show
  1. package/CHANGELOG.md +730 -0
  2. package/components/ConfirmDialog.vue +12 -16
  3. package/components/Detail/Detail.vue +406 -272
  4. package/components/Detail/DetailLangSwitch.vue +7 -2
  5. package/components/DropArea.vue +63 -56
  6. package/components/Form/Form.vue +218 -0
  7. package/components/Form/FormField.vue +213 -0
  8. package/components/Form/FormGroup.vue +146 -0
  9. package/components/Form/FormTabs.vue +188 -0
  10. package/components/Form/defaults.js +91 -0
  11. package/components/Form/fields/ColorField.vue +79 -0
  12. package/components/{fields → Form/fields}/DateField.vue +20 -11
  13. package/components/Form/fields/EnhancedMediaField.vue +224 -0
  14. package/components/Form/fields/FileField.vue +125 -0
  15. package/components/Form/fields/FksField.vue +88 -0
  16. package/components/Form/fields/MediaField.vue +159 -0
  17. package/components/Form/fields/MediaM2mField.vue +149 -0
  18. package/components/Form/fields/Repeater.vue +593 -0
  19. package/components/Form/fields/SeoPreview.vue +89 -0
  20. package/components/Form/fields/wygEditor/defaults.js +25 -0
  21. package/components/{fields/TinyMce → Form/fields/wygEditor}/utils/events.js +0 -0
  22. package/components/{fields/TinyMce → Form/fields/wygEditor}/utils/mapomedia.plugin.js +7 -6
  23. package/components/{fields/TinyMce → Form/fields/wygEditor}/utils/script.injector.js +0 -0
  24. package/components/Form/fields/wygEditor/wygEditor.vue +285 -0
  25. package/components/LangSwitcher.vue +44 -0
  26. package/components/List/List.vue +119 -42
  27. package/components/List/ListActions.vue +60 -21
  28. package/components/List/ListFilters.vue +166 -114
  29. package/components/List/ListHead.vue +30 -12
  30. package/components/List/ListQuickEdit.vue +130 -61
  31. package/components/List/ListTable.vue +292 -80
  32. package/components/Login.vue +17 -7
  33. package/components/LogoutButton.vue +42 -28
  34. package/components/MediaManager/MediaBreadcrumbs.vue +45 -0
  35. package/components/MediaManager/MediaEditor.vue +282 -121
  36. package/components/MediaManager/MediaFolders.vue +169 -116
  37. package/components/MediaManager/MediaGallery.vue +151 -146
  38. package/components/MediaManager/MediaManager.vue +117 -159
  39. package/components/MediaManager/MediaManagerDialog.vue +36 -31
  40. package/components/MediaManager/MediaPreview.vue +203 -0
  41. package/components/MediaManager/MediaUploader.vue +55 -43
  42. package/components/SnackBar.vue +5 -7
  43. package/components/ThemeToggle.vue +13 -0
  44. package/components/layout/Sidebar/Sidebar.vue +61 -30
  45. package/components/layout/Sidebar/SidebarList.vue +19 -15
  46. package/components/layout/Sidebar/SidebarListItem.vue +111 -39
  47. package/components/layout/Sidebar/SidebarProfile.vue +42 -0
  48. package/components/layout/Sidebar/SidebarTitle.vue +45 -0
  49. package/components/layout/Topbar/Topbar.vue +11 -42
  50. package/components/layout/routebuilder.js +3 -3
  51. package/defaults/i18n.js +37 -0
  52. package/defaults/vuetify.js +34 -0
  53. package/layouts/default.vue +33 -18
  54. package/layouts/empty.vue +10 -0
  55. package/module.js +7 -5
  56. package/package.json +6 -4
  57. package/pages/index.vue +19 -18
  58. package/static/{favicon.ico → mapo/favicon.ico} +0 -0
  59. package/static/mapo/tinymce-skins/mapo-dark/content.inline.min.css +7 -0
  60. package/static/mapo/tinymce-skins/mapo-dark/content.min.css +7 -0
  61. package/static/mapo/tinymce-skins/mapo-dark/content.mobile.min.css +7 -0
  62. package/static/mapo/tinymce-skins/mapo-dark/skin.min.css +7 -0
  63. package/static/mapo/tinymce-skins/mapo-dark/skin.mobile.min.css +7 -0
  64. package/static/mapo/tinymce-skins/mapo-light/content.inline.min.css +7 -0
  65. package/static/mapo/tinymce-skins/mapo-light/content.min.css +7 -0
  66. package/static/mapo/tinymce-skins/mapo-light/content.mobile.min.css +7 -0
  67. package/static/mapo/tinymce-skins/mapo-light/skin.min.css +7 -0
  68. package/static/mapo/tinymce-skins/mapo-light/skin.mobile.min.css +7 -0
  69. package/translations/en-US.js +134 -0
  70. package/translations/it-IT.js +136 -0
  71. package/components/Detail/DetailField.vue +0 -129
  72. package/components/Detail/defaults.js +0 -50
  73. package/components/fields/M2mField.vue +0 -95
  74. package/components/fields/MediaField.vue +0 -195
  75. package/components/fields/MediaM2mField.vue +0 -238
  76. package/components/fields/TinyMce/TinyMce.vue +0 -177
  77. package/components/fields/TinyMce/defaults.js +0 -55
  78. package/components/layout/Sidebar/SidebarFooter.vue +0 -75
  79. package/defaults.js +0 -29
  80. package/layouts/error.vue +0 -45
@@ -1,15 +1,25 @@
1
1
  <template>
2
- <v-container>
2
+ <div class="mapo-detail--wrapper">
3
+ <div class="mapo-detail--loader" v-if="loading">
4
+ <v-progress-linear
5
+ color="primary"
6
+ indeterminate
7
+ absolute
8
+ ></v-progress-linear>
9
+ <span class="detail-component-loading">
10
+ <v-icon size="30">mdi-timer-sand</v-icon>
11
+ {{ $t('mapo.fetchingData') }}
12
+ </span>
13
+ </div>
14
+ <div class="mapo-detail--loaded" v-else>
3
15
  <!-- Use this to override the title of the detail component. -->
4
16
  <slot name="title" v-bind="slotBindings">
5
17
  <!-- `<h1> "Create | Edit" + modelName </h1>` -->
6
- <v-row class="mb-14">
7
- <h1>{{ isNew ? "Create" : "Edit" }} {{ modelName }}</h1>
8
- </v-row>
18
+ <h1 class="mapo-detail--title">{{ isNew ? $t("mapo.create") : $t("mapo.edit") }} {{ modelName }}</h1>
9
19
  </slot>
10
- <v-form ref="form">
20
+ <v-form class="mapo-detail--form" ref="form">
11
21
  <v-row>
12
- <v-col cols="12" md="8">
22
+ <v-col class="mapo-detail--main" cols="12" :md="12 - sidenavCol">
13
23
  <!-- Use this to add content at the top of the central layout. -->
14
24
  <slot name="body.top" v-bind="slotBindings"></slot>
15
25
  <!-- Use this to override the Language Switch panel. -->
@@ -17,7 +27,8 @@
17
27
  <!-- [`DetailLangSwitch`](/components/detail/DetailLangSwitch/) -->
18
28
  <DetailLangSwitch
19
29
  v-if="langs && langs.length"
20
- class="mb-4"
30
+ v-show="langs.length > 1"
31
+ class="mapo-detail--language-tabs"
21
32
  v-model="currentLang"
22
33
  :langs="langs"
23
34
  :errors="errors"
@@ -26,314 +37,425 @@
26
37
  <slot name="body.top.underlang" v-bind="slotBindings"></slot>
27
38
  <!-- Use this to override the content of the main body. -->
28
39
  <slot name="body" v-bind="slotBindings">
29
- <!-- The result of the [`DetailConfiguration`](#detailconfiguration) contained in the main body. -->
30
- <div v-for="(field, index) in mainFields" :key="index">
31
- <v-card v-if="field.group" class="my-2">
32
- <v-card-title>
33
- <v-icon left> {{ field.group.icon }} </v-icon>
34
- <span>{{ field.group.name }}</span>
35
- </v-card-title>
36
- <v-card-text>
37
- <div
38
- v-for="(fields, fieldsI) in field.fields"
39
- :key="fieldsI"
40
- class="mb-4"
41
- >
42
- <!-- This is a dynamic slot. You can use it to override a field component. For example use `fields.title` to override the component of the field with value `title`. -->
43
- <slot
44
- :name="fields.slotName"
45
- v-bind="{
46
- conf: fields,
47
- ...slotBindings,
48
- }"
49
- >
50
- <!-- A [`DetailField`](/components/detail/DetailField/) configured by a [`FieldConfiguration`](#fieldconfiguration). -->
51
- <DetailField
52
- v-model="model"
53
- :conf="fields"
54
- :errors="errors"
55
- />
56
- </slot>
57
- </div>
58
- </v-card-text>
59
- </v-card>
60
- <slot
61
- v-else
62
- :name="field.slotName"
63
- v-bind="{
64
- conf: field,
65
- ...slotBindings,
66
- }"
67
- >
68
- <DetailField v-model="model" :conf="field" :errors="errors" />
69
- </slot>
70
- </div>
40
+ <Form
41
+ v-model="model"
42
+ :currentLang="currentLang"
43
+ :languages="langs"
44
+ :errors="errors"
45
+ :fields="mainFields"
46
+ :moreSlotBindings="slotBindings"
47
+ :readonly="isReadonly"
48
+ >
49
+ <template v-for="(_, slot) in $slots" :slot="slot">
50
+ <!-- @vuese-ignore -->
51
+ <slot :name="slot"></slot>
52
+ </template>
53
+ <template v-for="(_, slot) in $scopedSlots" v-slot:[slot]="props">
54
+ <!-- @vuese-ignore -->
55
+ <slot :name="slot" v-bind="props" />
56
+ </template>
57
+ </Form>
71
58
  </slot>
72
59
  <!-- Use this to add content under the main body. -->
73
60
  <slot name="body.bottom" v-bind="slotBindings"></slot>
74
61
  </v-col>
75
- <v-col cols="12" md="4">
76
- <div class="d-flex flex-column" :style="stickySide">
62
+ <v-col class="mapo-detail--sidenav" cols="12" :md="sidenavCol">
63
+ <div class="mapo-detail--sidenav-col" :style="stickySide">
77
64
  <!-- Use this to add content on the top of the sidebar button panel. -->
78
65
  <slot name="side.buttons.top" v-bind="slotBindings"></slot>
79
66
  <!-- Use this to override the the sidebar button panel. -->
80
67
  <slot name="side.buttons" v-bind="slotBindings">
81
68
  <!-- Save, Save and continue, Back, and Delete buttons. -->
82
- <div class="mt-4 mt-md-0 mb-md-4 mb-0 order-1 order-md-0">
69
+ <div class="mapo-detail--buttons">
83
70
  <!-- Use this to override the Save button. -->
84
71
  <slot name="button.save" v-bind="slotBindings">
85
72
  <!-- The Save button. -->
86
- <v-btn class="mb-2" tile block @click="saveItem(true)">{{
87
- isNew ? "Create" : "Save"
73
+ <v-btn v-show="canGoBack" :loading="buttonClicked == 'saveAndBackBtn'" :disabled="isReadonly" tile block @click="saveItem(true)">{{
74
+ isNew ? $t("mapo.create") : $t("mapo.save")
88
75
  }}</v-btn>
89
76
  </slot>
90
77
  <!-- Use this to override the Save and continue button. -->
91
78
  <slot name="button.savecontinue" v-bind="slotBindings">
92
79
  <!-- The Save and continue button. -->
93
- <v-btn class="mb-2" tile block @click="saveItem(false)"
94
- >{{ isNew ? "Create" : "Save" }} and continue</v-btn
80
+ <v-btn :loading="buttonClicked == 'saveBtn'" :disabled="isReadonly" tile block @click="saveItem(false)"
81
+ >{{ isNew ? $t("mapo.createContinue") : $t("mapo.saveContinue") }}</v-btn
95
82
  >
96
83
  </slot>
97
84
  <!-- Use this to override the Back button. -->
98
85
  <slot name="button.back" v-bind="slotBindings">
99
86
  <!-- The Back button. -->
100
- <v-btn class="mb-2" tile block @click="$router.back()"
101
- >Back</v-btn
87
+ <v-btn v-show="canGoBack" tile block @click="back"
88
+ >{{ $t("mapo.back") }}</v-btn
102
89
  >
103
90
  </slot>
104
91
  <!-- Use this to override the Delete button. -->
105
- <slot name="button.delete" v-bind="slotBindings">
92
+ <slot name="button.delete" :loading="buttonClicked == 'deleteBtn'" v-bind="slotBindings">
106
93
  <!-- The Delete button. -->
107
94
  <v-btn
108
95
  v-if="!isNew"
109
- class="mb-2"
110
96
  color="error"
111
97
  tile
112
98
  block
99
+ :disabled="!canDelete"
113
100
  @click="deleteItem"
114
- >Delete</v-btn
101
+ >{{ $t("mapo.delete") }}</v-btn
115
102
  >
116
103
  </slot>
117
104
  </div>
118
105
  </slot>
119
106
  <!-- Use this to add content on the top of the sidebar fields (or under sidebar buttons). -->
120
107
  <slot name="side.top" v-bind="slotBindings"></slot>
121
- <div v-for="(field, index) in sideFields" :key="index">
122
- <v-card v-if="field.group" class="mb-4">
123
- <v-card-title>
124
- <v-icon left> {{ field.group.icon }} </v-icon>
125
- <span>{{ field.group.name }}</span>
126
- </v-card-title>
127
- <v-card-text>
128
- <div
129
- v-for="(fields, fieldsI) in field.fields"
130
- :key="fieldsI"
131
- class="mb-4"
132
- >
133
- <!-- @vuese-ignore -->
134
- <slot
135
- :name="fields.slotName"
136
- v-bind="{
137
- conf: fields,
138
- ...slotBindings,
139
- }"
140
- >
141
- <DetailField
142
- v-model="model"
143
- :conf="fields"
144
- :errors="errors"
145
- />
146
- </slot>
147
- </div>
148
- </v-card-text>
149
- </v-card>
150
- <slot
151
- v-else
152
- :name="field.slotName"
153
- v-bind="{
154
- conf: field,
155
- ...slotBindings,
156
- }"
157
- >
158
- <DetailField v-model="model" :conf="field" :errors="errors" />
159
- </slot>
160
- </div>
108
+ <Form
109
+ v-model="model"
110
+ :currentLang="currentLang"
111
+ :languages="langs"
112
+ :errors="errors"
113
+ :fields="sideFields"
114
+ :moreSlotBindings="slotBindings"
115
+ >
116
+ <template v-for="(_, slot) in $slots" :slot="slot">
117
+ <!-- @vuese-ignore -->
118
+ <slot :name="slot"></slot>
119
+ </template>
120
+ <template v-for="(_, slot) in $scopedSlots" v-slot:[slot]="props">
121
+ <!-- @vuese-ignore -->
122
+ <slot :name="slot" v-bind="props" />
123
+ </template>
124
+ </Form>
161
125
  <!-- Use this to add content under the sidebar fields. -->
162
126
  <slot name="side.bottom" v-bind="slotBindings"></slot>
163
127
  </div>
164
128
  </v-col>
165
129
  </v-row>
166
130
  </v-form>
167
- </v-container>
131
+ </div>
132
+ </div>
168
133
  </template>
169
134
 
135
+ <style lang="scss" scoped>
136
+ .mapo-detail--loader {
137
+ .v-progress-linear {
138
+ top: 0;
139
+ }
140
+ span{
141
+ position: absolute;
142
+ top: 50%;
143
+ transform: translateY(-50%);
144
+ width: 100%;
145
+ display: flex;
146
+ flex-direction: column;
147
+ justify-content: center;
148
+ align-items: center;
149
+ }
150
+ }
151
+ .mapo-detail--title{
152
+ margin-bottom: 20px;
153
+ font-weight: normal;
154
+ }
155
+ .mapo-detail--language-tabs {
156
+ margin-bottom: 20px;
157
+ }
158
+ .mapo-detail--sidenav-col {
159
+ display: flex;
160
+ flex-direction: column;
161
+ }
162
+ .mapo-detail--buttons {
163
+ margin-top: 16px;
164
+ margin-bottom: 0px;
165
+ order: 1;
166
+ @media (min-width: 960px) {
167
+ margin-bottom: 16px;
168
+ margin-top: 0px;
169
+ order: 0;
170
+ }
171
+ .v-btn{
172
+ margin-bottom: 8px;
173
+ }
174
+ }
175
+ </style>
170
176
 
171
177
  <script>
178
+ import { diffObjs, deepClone } from "@mapomodule/utils/helpers/objHelpers";
179
+
172
180
  /**
173
181
  * The purpose of this component is to provide you with a very quick way to create an edit page for a payload to send to the server.
174
182
  * A use case example could be "build a page that allows you to change the specifications of a product for an ecommerce".<br> <h4>Index:</h4> [[toc]]
175
183
  */
176
184
  export default {
177
- name: "Detail",
178
- data() {
179
- return {
180
- model: {},
181
- currentLang: null,
182
- errors: null
183
- };
184
- },
185
- props: {
186
- // The main configuration that determines the arrangement of the fields in the detail layout.
187
- fields: {
188
- // [`DetailConfiguration`](#detailconfiguration)
189
- type: Object | Array,
190
- required: true
185
+ name: "Detail",
186
+ data() {
187
+ return {
188
+ model: {},
189
+ modelLanguages: [],
190
+ currentLang: this.lang,
191
+ errors: null,
192
+ buttonClicked: null
193
+ };
191
194
  },
192
- // A list of languages into which the payload needs to be translated.
193
- languages: {
194
- type: Array,
195
- default: () => []
196
- },
197
- // The url of the endpoint to which the payload is to be sent. From this url a complete crud (See [this.$mapo.$api.crud](/core/#$api.crud)) will be created.
198
- endpoint: String,
199
- // The identifier of the object you need to retrieve and edit. It can be "new" if you need to create a new payload.
200
- identifier: {
201
- // `String|Number`.
202
- type: String | Number,
203
- default: "new"
204
- },
205
- // The title of the detail page.
206
- modelName: String,
207
- // This determines the style of the sidebar. If set to true the sidebar will remain sticky during the scroll.
208
- sticky: {
209
- type: Boolean,
210
- default: true
211
- }
212
- },
213
- methods: {
214
- saveItem(back = false) {
215
- this.errors = null;
216
- this.$refs.form?.resetValidation();
217
- this.crud
218
- .updateOrCreate(this.model)
219
- .then(() => back && this.$router.back())
220
- .catch(error => {
221
- this.errors =
222
- (error.response.status == 400 && error.response.data) || null;
223
- this.$mapo.$snack.open({
224
- message: "Something whent bad, please try again later...",
225
- color: "error"
226
- });
227
- });
195
+ props: {
196
+ // V-model of the object we are editing.
197
+ value: {
198
+ type: Object,
199
+ required: false
200
+ },
201
+ // Set the current lang to value.
202
+ lang: {
203
+ type: String,
204
+ required: false
205
+ },
206
+ // The main configuration that determines the arrangement of the fields in the detail layout.
207
+ fields: {
208
+ // [`DetailConfiguration`](#detailconfiguration)
209
+ type: Object | Array,
210
+ required: true
211
+ },
212
+ usePatch: {
213
+ type: Boolean,
214
+ default() { return this.$mapo.$options?.content?.usePatch || false; },
215
+ },
216
+ // A list of languages into which the payload needs to be translated.
217
+ languages: {
218
+ type: Array,
219
+ default() { return this.$mapo.$options?.content?.languages || []; },
220
+ },
221
+ // Forces use of languages passed as prop, instead of those loaded with model
222
+ forceLanguages: {
223
+ type: Boolean,
224
+ default() { return this.$mapo.$options?.content?.forceLanguages || false; },
225
+ },
226
+ // The url of the endpoint to which the payload is to be sent. From this url a complete crud (See [this.$mapo.$api.crud](/core/#$api.crud)) will be created.
227
+ endpoint: {
228
+ type: String,
229
+ default: null
230
+ },
231
+ // This determines the width of the sidebar in desktop view in a 12 col grid.
232
+ sidenavCol: {
233
+ type: Number | String,
234
+ default: "4",
235
+ validator: function (value) {
236
+ // The value must be a number between 0 and 12
237
+ return [...Array(12).keys()].indexOf(+value) !== -1;
238
+ },
239
+ },
240
+ // The identifier of the object you need to retrieve and edit. It can be "new" if you need to create a new payload.
241
+ identifier: {
242
+ // `String|Number`.
243
+ type: String | Number,
244
+ default: "new"
245
+ },
246
+ // The title of the detail page.
247
+ modelName: String,
248
+ // This determines the style of the sidebar. If set to true the sidebar will remain sticky during the scroll.
249
+ sticky: {
250
+ type: Boolean,
251
+ default: true
252
+ },
253
+ // Set the multipart politic. Accepts `'auto'|'force|'disable'`. If auto is set the request is transformed in multipart if any file is in the payload. If set to force the request is transformed in multipart no matter if files are found. If set to `'disable'` the request is never transformed in multipart.
254
+ multipart: {
255
+ type: String,
256
+ default: "auto",
257
+ validator: function (value) {
258
+ // The value must match one of these strings
259
+ return ["auto", "force", "disable"].indexOf(value) !== -1;
260
+ },
261
+ },
228
262
  },
229
- deleteItem() {
230
- this.$mapo.$confirm
231
- .open({
232
- title: "Delete",
233
- question: "Are you sure you want to delete this item?",
234
- approveButton: { text: "Delete", attrs: { color: "red" } }
235
- })
236
- .then(res => {
237
- if (res) {
238
- this.crud
239
- .delete(this.identifier)
240
- .then(() => this.$router.back())
241
- .catch(error =>
242
- this.$mapo.$snack.open({
243
- message: "Something whent bad, please try again later...",
263
+ methods: {
264
+ back() {
265
+ this.$nuxt.context?.from?.name == "login" ? this.$router.go(-3) : this.$router.back();
266
+ },
267
+ saveItem(back = false) {
268
+ this.buttonClicked = back ? "saveAndBackBtn" : "saveBtn";
269
+ this.errors = null;
270
+ this.$refs.form?.resetValidation();
271
+ this.apiSendPayload().then((resp) => {
272
+ this.model = resp;
273
+ this.modelBkp = deepClone(this.model);
274
+ this.$mapo.$snack.open({ message: this.isNew ? this.$t("mapo.createSuccess") : this.$t("mapo.saveSuccess"), color: "success" })
275
+ this.isNew && this.$router.replace({ params: { detail: resp.id } })
276
+ back && this.back();
277
+ }).catch(error => {
278
+ this.errors =
279
+ (error.response.status == 400 && error.response.data) || null;
280
+ this.$mapo.$snack.open({
281
+ message: error.response?.data?.detail || this.$t("mapo.genericError"),
244
282
  color: "error"
245
- })
246
- );
283
+ })
284
+ }).finally(() => {this.buttonClicked = null;});;
285
+ },
286
+ deleteItem() {
287
+ this.$mapo.$confirm
288
+ .open({
289
+ title: "Delete",
290
+ question: this.$t("mapo.confirmDelete"),
291
+ approveButton: { text: this.$t("mapo.delete"), attrs: { color: "red", text: true } }
292
+ })
293
+ .then(res => {
294
+ if (res) {
295
+ this.buttonClicked = "deleteBtn";
296
+ this.crud
297
+ .delete(this.identifier)
298
+ .then(() => this.back())
299
+ .catch(error => this.$mapo.$snack.open({
300
+ message: error.response?.data?.detail || this.$t("mapo.genericError"),
301
+ color: "error"
302
+ })).finally(()=> {this.buttonClicked = null;});
303
+ }
304
+ });
305
+ },
306
+ setRouterGuard(){
307
+ const checkUnsaved = async (to, from, next) => {
308
+ if (to.name !== from.name && this.hasDiff){
309
+ this.$mapo.$confirm
310
+ .open({
311
+ title: this.$t("mapo.unsavedData"),
312
+ question: this.$t("mapo.confirmLeaveChanges"),
313
+ approveButton: { text: this.$t("mapo.confirm"), attrs: { text: true } }
314
+ }).then(next);
315
+ } else {
316
+ next();
317
+ }
318
+ };
319
+ checkUnsaved.bind(this);
320
+ this.$router.beforeHooks.push(checkUnsaved);
321
+ window?.addEventListener('beforeunload', this.preventWindowClose);
322
+ },
323
+ preventWindowClose(event){
324
+ const text = this.$t("mapo.confirmLeaveChanges");
325
+ if (this.hasDiff) {
326
+ event.returnValue = text;
327
+ return text;
247
328
  }
248
- });
249
- },
250
- parseConf(field) {
251
- const conf = typeof field === "string" ? { value: field } : field;
252
- conf.value = conf.value.replace(/^translations\..*\./, "");
253
- conf.slotName = `fields.${conf.value}`;
254
- if (this.currentLang && !field.synci18n) {
255
- conf.value = `translations.${this.currentLang}.${conf.value}`;
256
- }
257
- return conf;
258
- },
259
- mapConf(fields) {
260
- const icon = "mdi-cube-outline";
261
- const parseGroup = group =>
262
- typeof group === "string"
263
- ? { name: group, icon }
264
- : { ...group, icon: group.icon || icon };
265
- return fields.map(f =>
266
- f.group
267
- ? { group: parseGroup(f.group), fields: this.mapConf(f.fields) }
268
- : this.parseConf(f)
269
- );
270
- }
271
- },
272
- watch: {
273
- currentLang(val) {
274
- if (val && !this.model.translations) {
275
- this.model.translations = {};
276
- }
277
- if (val && !this.model.translations[val]) {
278
- this.model.translations[val] = {};
279
- }
280
- }
281
- },
282
- computed: {
283
- crud() {
284
- return this.$mapo.$api.crud(this.endpoint);
285
- },
286
- mainFields() {
287
- return this.mapConf(
288
- this.fields instanceof Array ? this.fields : this.fields.main || []
289
- );
290
- },
291
- sideFields() {
292
- return this.mapConf(
293
- (this.fields instanceof Object && this.fields.sidenav) || []
294
- );
295
- },
296
- isNew() {
297
- return this.identifier && this.identifier == "new";
298
- },
299
- loading() {
300
- if (this.identifier === "new") {
301
- return false;
302
- }
303
- return !Object.keys(this.model).length;
329
+ },
330
+ unsetRouterGuard(){
331
+ window?.removeEventListener('beforeunload', this.preventWindowClose);
332
+ this.$router.beforeHooks = this.$router.beforeHooks.filter(({name})=> name != 'checkUnsaved');
333
+ }
304
334
  },
305
- langs() {
306
- return (
307
- this.model?.active_languages?.languages.map(l => l.id) || this.languages
308
- );
335
+ watch: {
336
+ currentLang(val) {
337
+ // Fired when the current language changes.
338
+ // @arg Emits the language name as a string.
339
+ this.$emit("update:lang", val);
340
+ },
341
+ model(val) {
342
+ // Fired when the v-model changes.
343
+ // @arg Emits the entire payload modified.
344
+ this.$emit("input", val);
345
+ },
346
+ lang(val) {
347
+ if (val && this.langs.includes(val)) {
348
+ this.currentLang = val;
349
+ }
350
+ },
351
+ value(val) {
352
+ if (val) {
353
+ this.model = val;
354
+ }
355
+ },
309
356
  },
310
- slotBindings() {
311
- return {
312
- model: this.model,
313
- currentLang: this.currentLang,
314
- crud: this.crud,
315
- isNew: this.isNew,
316
- langs: this.langs,
317
- loading: this.loading,
318
- form: this.$refs.form,
319
- saveItem: this.saveItem,
320
- deleteItem: this.deleteItem
321
- };
357
+ computed: {
358
+ canGoBack() {
359
+ if (typeof window !== "undefined") {
360
+ return this.$nuxt?.context?.from?.name !== "login" && window.history.length > 1 || window.history.length > 3;
361
+ }
362
+ return true;
363
+ },
364
+ crud() {
365
+ return this.$mapo.$api.crud(this.endpoint);
366
+ },
367
+ apiSendPayload(){
368
+ let method, args;
369
+ if (!this.model.id){
370
+ method = this.crud.create;
371
+ args = [this.model, {}, { multipart: this.multipart }]
372
+ } else if (this.usePatch) {
373
+ method = this.crud.partialUpdate;
374
+ args = [this.model.id, this.modelDiff, {}, { multipart: this.multipart }]
375
+ } else {
376
+ method = this.crud.update;
377
+ args = [this.model.id, this.model, {}, { multipart: this.multipart }]
378
+ }
379
+ return async () => method(...args)
380
+ },
381
+ isReadonly() {
382
+ if (this.$mapo.$auth.routeMiddlewares.includes("permissions")) {
383
+ return !this.$mapo.$auth.user.permissions.includes(this.isNew ? "add" : "change");
384
+ }
385
+ return !!this.buttonClicked;
386
+ },
387
+ canDelete() {
388
+ if (this.$mapo.$auth.routeMiddlewares.includes("permissions")) {
389
+ return this.$mapo.$auth.user.permissions.includes("delete");
390
+ }
391
+ return true;
392
+ },
393
+ mainFields() {
394
+ return this.fields instanceof Array ? this.fields : this.fields.main || [];
395
+ },
396
+ sideFields() {
397
+ return (this.fields instanceof Object && this.fields.sidenav) || [];
398
+ },
399
+ isNew() {
400
+ return this.identifier && this.identifier == "new";
401
+ },
402
+ loading() {
403
+ if (this.identifier === "new") {
404
+ return false;
405
+ }
406
+ return !Object.keys(this.model).length;
407
+ },
408
+ langs() {
409
+ return (!this.forceLanguages && (this.modelLanguages || []).length) ? this.modelLanguages : this.languages;
410
+ },
411
+ slotBindings() {
412
+ return {
413
+ model: this.model,
414
+ errors: this.errors,
415
+ currentLang: this.currentLang,
416
+ crud: this.crud,
417
+ isNew: this.isNew,
418
+ langs: this.langs,
419
+ loading: this.loading,
420
+ form: this.$refs.form,
421
+ saveItem: this.saveItem,
422
+ deleteItem: this.deleteItem
423
+ };
424
+ },
425
+ stickySide() {
426
+ return this.sticky
427
+ ? {
428
+ position: "sticky",
429
+ top: "60px"
430
+ }
431
+ : {};
432
+ },
433
+ modelDiff(){
434
+ return diffObjs(this.modelBkp, this.model) || {};
435
+ },
436
+ hasDiff() {
437
+ return !!(this.modelDiff && Object.keys(this.modelDiff).length > 0);
438
+ }
322
439
  },
323
- stickySide() {
324
- return this.sticky
325
- ? {
326
- position: "sticky",
327
- top: "60px"
440
+ async mounted() {
441
+ if (this.identifier && this.identifier !== "new") {
442
+ try {
443
+ this.model = await this.crud.detail(this.identifier);
444
+ this.modelLanguages = this.model?.lang_info?.site_languages.map(l => l.id);
445
+ } catch (error) {
446
+ this.$nuxt.error({ statusCode: error.response.status, message: error.response.data?.detail || this.$t("mapo.genericError") });
328
447
  }
329
- : {};
330
- }
331
- },
332
- mounted() {
333
- if (this.identifier && this.identifier !== "new") {
334
- this.crud.detail(this.identifier).then(res => (this.model = res));
448
+ }
449
+ else if (this.value) {
450
+ this.model = this.value;
451
+ this.modelLanguages = this.model?.lang_info?.site_languages.map(l => l.id);
452
+ }
453
+ this.modelBkp = deepClone(this.model);
454
+ this.setRouterGuard();
455
+ },
456
+ destroyed(){
457
+ this.unsetRouterGuard();
335
458
  }
336
- }
337
459
  };
338
460
  </script>
339
461
 
@@ -341,7 +463,7 @@ export default {
341
463
 
342
464
  ## DetailConfiguration
343
465
 
344
- The DetailConfiguration determines the behavior of the main form and is an `Array` of [`FieldConfiguration`](#fieldconfiguration).
466
+ The DetailConfiguration determines the behavior of the main form and is an `Array` of [`FieldConfiguration`](#fieldconfiguration).
345
467
  Each field configuration represents a field of the form.
346
468
  The configuration can also consist of an object with two keys `{ main sidenav }`.
347
469
  Each key is an `Array` of [`FieldConfiguration`](#fieldconfiguration) and will modify a different part of the component:
@@ -351,7 +473,7 @@ Each key is an `Array` of [`FieldConfiguration`](#fieldconfiguration) and will m
351
473
 
352
474
  ### FieldConfiguration
353
475
 
354
- The `FieldConfiguration` is a `String` containing the dottedPath of a value inside the payload we want to modify.
476
+ The `FieldConfiguration` is a `String` containing the dottedPath of a value inside the payload we want to modify.
355
477
  So, for example, if we have the payload: `{ image: { name: "...", url: "..." } }` we can modify the image name using the dottedPath `"image.name"`.
356
478
 
357
479
  The default component used to render a field of a form is a [`v-text-field`](https://vuetifyjs.com/en/components/text-fields/).
@@ -359,12 +481,12 @@ If you want more control over the generated component you can use an `Object` wi
359
481
 
360
482
  |Name|Description|Type|Required|Default|
361
483
  |---|---|---|---|---|
362
- |value|The dottedPath of the value we want to modify.|`String`|`true`|-|
363
- |synci18n|Determines if the field is translatable or not. If set to true the value will remain the same in all translations (untranslatable).|`Boolean`|`false`|`false`|
364
- |type|Type of the field. This determines which component will be rendered. The list of possible choices can be found [here](#field-types) |`String`|`false`|`text`|
365
- |accessor|[`Accessor`](#accessor) object to specify the setter and the getter of the field.|`Object`|`false`|`{set: x=>x, get: x=>x}`|
366
- |attrs|The attributes that will be passed to the component.|`Object`|`false`|-|
367
- |is|The component to be rendered in the form. This has a higher priority than the "type" attribute. Here you can pass in any regitered Vue component instance or name. [Learn more](https://vuejs.org/v2/guide/components.html#Dynamic-Components).|`String | VueComponent`|`false`|-|
484
+ |value|The dottedPath of the value we want to modify.|`String`|`true`|-|
485
+ |synci18n|Determines if the field is translatable or not. If set to true the value will remain the same in all translations (untranslatable).|`Boolean`|`false`|`false`|
486
+ |type|Type of the field. This determines which component will be rendered. The list of possible choices can be found [here](#field-types) |`String`|`false`|`text`|
487
+ |accessor|[`Accessor`](#accessor) object to specify the setter and the getter of the field.|`Object`|`false`|`{set: x=>x, get: x=>x}`|
488
+ |attrs|The attributes that will be passed to the component.|`Object`|`false`|-|
489
+ |is|The component to be rendered in the form. This has a higher priority than the "type" attribute. Here you can pass in any regitered Vue component instance or name. [Learn more](https://vuejs.org/v2/guide/components.html#Dynamic-Components).|`String | VueComponent`|`false`|-|
368
490
 
369
491
  #### Accessor
370
492
 
@@ -374,19 +496,21 @@ Each function must return the processed value.
374
496
 
375
497
  #### Field types
376
498
 
377
- Here the list of the FieldConfiguration type association.
499
+ Here the list of the FieldConfiguration type association.
378
500
 
379
501
  - `text` ==> [v-text-field](https://vuetifyjs.com/en/components/text-fields/),
380
502
  - `select` ==> [v-select](https://vuetifyjs.com/en/components/selects/),
381
- - `date` ==> [date-field](/components/fields/DateField/),
503
+ - `date` ==> [date-field](/components/Form/fields/DateField/),
382
504
  - `textarea` ==> [v-textarea](https://vuetifyjs.com/en/components/textareas/),
383
505
  - `switch` ==> [v-switch](https://vuetifyjs.com/en/components/switches/),
384
506
  - `slider` ==> [v-slider](https://vuetifyjs.com/en/components/sliders/),
385
- - `file` ==> [v-file-input](https://vuetifyjs.com/en/components/file-inputs/),
386
- - `editor` ==> [tiny-mce](/components/fields/TinyMce/TinyMce/),
387
- - `media` ==> [media-field](/components/fields/MediaField/),
388
- - `m2m` ==> [m2m-field](/components/fields/M2mField/),
389
- - `mediaList` ==> [media-m2m-field](/components/fields/MediaM2mField/)
507
+ - `file` ==> [file-field](/components/Form/fields/FileField/),
508
+ - `editor` ==> [wyg-editor](/components/Form/fields/wygEditor/wygEditor/),
509
+ - `media` ==> [media-field](/components/Form/fields/MediaField/),
510
+ - `enhancedMedia` ==> [enhanced-media-field](/components/Form/fields/EnhancedMediaField/),
511
+ - `mediaList` ==> [media-m2m-field](/components/Form/fields/MediaM2mField/)
512
+ - `m2m` or `fks` ==> [fks-field](/components/Form/fields/FksField/),
513
+ - `repeater` ==> [repeater](/components/Form/fields/Repeater/),
390
514
 
391
515
 
392
516
  #### Example of a [`FieldConfiguration`](#fieldconfiguration):
@@ -405,8 +529,8 @@ Here the list of the FieldConfiguration type association.
405
529
 
406
530
  ### FieldGroup
407
531
 
408
- You can use this mixed with `FieldConfiguration` to group multiple fields in one card with a title and an icon.
409
- The `FieldGroup` has the key group that is a string repreenting the name of the group and the key fields that is an `Array` of [`FieldConfiguration`](#fieldconfiguration).
532
+ You can use this mixed with `FieldConfiguration` to group multiple fields in one card with a title and an icon.
533
+ The `FieldGroup` has the key group that is a string repreenting the name of the group and the key fields that is an `Array` of [`FieldConfiguration`](#fieldconfiguration).
410
534
  The group key can also be an `Object`. In that case it contains the name and the icon for the group `{name: "...", icon: "..."}`. For a list of all available icons, visit the official [Material Design Icons](https://materialdesignicons.com/) page.
411
535
 
412
536
  <br><br>
@@ -423,8 +547,9 @@ This is an interactive example. You can play with it but remember that all http
423
547
  ::: demo
424
548
  <template>
425
549
  <v-app>
550
+ <div class="d-flex justify-end"><ThemeToggle/></div>
426
551
  <Detail
427
- endpoint="api/camomilla/articles"
552
+ endpoint="api/articles"
428
553
  identifier="new"
429
554
  :fields="fields"
430
555
  :languages="['it', 'en', 'de']"
@@ -440,12 +565,21 @@ export default {
440
565
  main: [
441
566
  { value: "identifier", synci18n: true },
442
567
  { value: "content", type: "editor" },
568
+ { value: "sections", type: "repeater", attrs: {
569
+ sortable: true,
570
+ fields: [
571
+ { value: "title", class: "col-md-6" },
572
+ { value: "subtitle", class: "col-md-6" },
573
+ { value: "content", type: "textarea" },
574
+ ]}
575
+ },
443
576
  {
444
577
  group: "Seo",
445
578
  fields: [
446
579
  "title",
447
580
  { value: "description", type: "textarea" },
448
581
  "permalink",
582
+ { type: "seoPreview" }
449
583
  ]
450
584
  }
451
585
  ],
@@ -486,4 +620,4 @@ export default {
486
620
 
487
621
 
488
622
 
489
- </docs>
623
+ </docs>