@mapomodule/uikit 1.0.0-alpha.5 → 1.0.0-alpha.50

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