lkt-item-crud 1.1.5 → 1.1.7
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/dist/build.d.ts +4 -3
- package/dist/build.js +126 -117
- package/dist/functions/debug.d.ts +2 -0
- package/dist/index.d.ts +1 -0
- package/dist/lib-components/LktItemCrud.vue.d.ts +2 -0
- package/dist/settings/Settings.d.ts +3 -0
- package/package.json +1 -1
- package/src/lib-components/LktItemCrud.vue +39 -23
package/dist/build.d.ts
CHANGED
package/dist/build.js
CHANGED
|
@@ -1,17 +1,25 @@
|
|
|
1
|
-
import { defineComponent as
|
|
2
|
-
import { httpCall as
|
|
3
|
-
import { DataState as
|
|
4
|
-
const
|
|
1
|
+
import { defineComponent as ne, useSlots as se, ref as s, computed as d, watch as b, resolveComponent as w, openBlock as c, createElementBlock as h, createElementVNode as j, toDisplayString as N, renderSlot as O, createCommentVNode as D, withDirectives as V, createBlock as q, withCtx as G, unref as K, vShow as I, createVNode as Q } from "vue";
|
|
2
|
+
import { httpCall as ie } from "lkt-http-client";
|
|
3
|
+
import { DataState as ce } from "lkt-data-state";
|
|
4
|
+
const T = class T {
|
|
5
|
+
};
|
|
6
|
+
T.debugEnabled = !1;
|
|
7
|
+
let L = T;
|
|
8
|
+
const p = (...u) => {
|
|
9
|
+
L.debugEnabled && console.info("[LktHttpClient] ", ...u);
|
|
10
|
+
}, Oe = (u = !0) => {
|
|
11
|
+
L.debugEnabled = u;
|
|
12
|
+
}, ve = { class: "lkt-item-crud" }, fe = {
|
|
5
13
|
key: 0,
|
|
6
14
|
class: "lkt-item-crud_header"
|
|
7
|
-
},
|
|
15
|
+
}, pe = { class: "lkt-item-crud_header-title" }, me = { class: "lkt-item-crud_header-slot" }, ye = { class: "lkt-item-crud-buttons" }, he = { key: 1 }, Se = { key: 1 }, ke = {
|
|
8
16
|
key: 1,
|
|
9
17
|
class: "lkt-item-crud_content"
|
|
10
|
-
},
|
|
18
|
+
}, be = {
|
|
11
19
|
key: 0,
|
|
12
20
|
class: "lkt-grid-1"
|
|
13
|
-
},
|
|
14
|
-
...
|
|
21
|
+
}, De = { name: "LktItemCrud", inheritAttrs: !1 }, ge = /* @__PURE__ */ ne({
|
|
22
|
+
...De,
|
|
15
23
|
props: {
|
|
16
24
|
modelValue: { type: Object, required: !1, default: () => ({}) },
|
|
17
25
|
title: { type: String, default: "" },
|
|
@@ -43,170 +51,171 @@ const ne = { class: "lkt-item-crud" }, se = {
|
|
|
43
51
|
onCreate: { type: Function, required: !1, default: () => !0 },
|
|
44
52
|
onUpdate: { type: Function, required: !1, default: () => !0 }
|
|
45
53
|
},
|
|
46
|
-
emits: ["update:modelValue", "read", "create", "update", "drop", "perms", "error", "modified-data"],
|
|
47
|
-
setup(
|
|
48
|
-
const e =
|
|
49
|
-
let
|
|
50
|
-
const
|
|
51
|
-
|
|
54
|
+
emits: ["update:modelValue", "update:isCreate", "read", "create", "update", "drop", "perms", "error", "modified-data"],
|
|
55
|
+
setup(u, { expose: $, emit: W }) {
|
|
56
|
+
const e = u, M = se(), n = W;
|
|
57
|
+
let X = [];
|
|
58
|
+
const o = s(!0), r = s(e.modelValue), S = s(X), v = s(!1), f = s(!1), m = s(!1), i = s(200), g = s(null), C = s(null), k = s(new ce(r.value)), a = s(e.isCreate), Y = d(() => a.value ? e.createConfirm : e.updateConfirm), Z = d(() => a.value ? e.createConfirmData : e.updateConfirmData), x = d(() => a.value ? e.createResource : e.updateResource), ee = d(() => a.value ? { ...e.createData, ...JSON.parse(JSON.stringify(r.value)) } : { ...e.updateData, ...JSON.parse(JSON.stringify(r.value)) }), te = d(() => a.value ? e.createDisabled : e.updateDisabled), B = d(() => !a.value && S.value.includes("update")), _ = d(() => !a.value && S.value.includes("drop")), U = async () => {
|
|
59
|
+
p("fetchItem"), o.value = !0, i.value = -1, m.value = !1;
|
|
52
60
|
try {
|
|
53
|
-
const t = await
|
|
54
|
-
if (
|
|
55
|
-
f.value = !1,
|
|
61
|
+
const t = await ie(e.readResource, e.readData);
|
|
62
|
+
if (p("fetchItem -> response", t), o.value = !1, i.value = t.httpStatus, !t.success) {
|
|
63
|
+
f.value = !1, i.value = t.httpStatus, n("error", t.httpStatus);
|
|
56
64
|
return;
|
|
57
65
|
}
|
|
58
|
-
f.value = !0, r.value = t.data,
|
|
66
|
+
f.value = !0, r.value = t.data, S.value = t.perms, k.value.increment(r.value).turnStoredIntoOriginal(), n("read", t);
|
|
59
67
|
} catch {
|
|
60
|
-
|
|
68
|
+
o.value = !1, f.value = !1, i.value = 404, n("error", 404);
|
|
61
69
|
return;
|
|
62
70
|
}
|
|
63
|
-
},
|
|
64
|
-
|
|
65
|
-
r.value = t,
|
|
66
|
-
}, { deep: !0 }),
|
|
67
|
-
|
|
68
|
-
}, { deep: !0 }),
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
const
|
|
72
|
-
if (
|
|
73
|
-
|
|
71
|
+
}, ae = d(() => o.value ? !1 : e.title || !!M["post-title"]);
|
|
72
|
+
b(() => e.modelValue, (t) => {
|
|
73
|
+
r.value = t, k.value.increment(t);
|
|
74
|
+
}, { deep: !0 }), b(r, (t) => {
|
|
75
|
+
n("update:modelValue", r.value), k.value.increment(t);
|
|
76
|
+
}, { deep: !0 }), b(S, () => n("perms", S.value));
|
|
77
|
+
const E = d(() => te.value || !a.value && !B.value || typeof e.saveValidator == "function" && !e.saveValidator(r.value) ? !1 : k.value.changed());
|
|
78
|
+
b(E, (t) => n("modified-data", t)), b(a, (t) => n("update:isCreate", t)), e.readResource && !a.value ? U() : a.value && (f.value = !0, v.value = !0, o.value = !1);
|
|
79
|
+
const le = (t, l) => {
|
|
80
|
+
if (o.value = !1, i.value = l.httpStatus, !l.success) {
|
|
81
|
+
m.value = !0, n("error", l.httpStatus);
|
|
74
82
|
return;
|
|
75
83
|
}
|
|
76
|
-
|
|
77
|
-
},
|
|
78
|
-
if (
|
|
79
|
-
if (
|
|
80
|
-
|
|
84
|
+
m.value = !0, n("drop", l);
|
|
85
|
+
}, ue = (t, l) => {
|
|
86
|
+
if (p("onSave -> received response:", l), x.value) {
|
|
87
|
+
if (o.value = !1, i.value = l.httpStatus, !l.success) {
|
|
88
|
+
m.value = !0, n("error", l.httpStatus);
|
|
81
89
|
return;
|
|
82
90
|
}
|
|
83
|
-
|
|
91
|
+
m.value = !0;
|
|
84
92
|
}
|
|
85
|
-
let
|
|
86
|
-
|
|
87
|
-
},
|
|
88
|
-
|
|
89
|
-
},
|
|
90
|
-
|
|
93
|
+
let R = a.value ? "create" : "update";
|
|
94
|
+
a.value || (p("onSave -> turn stored data into original"), k.value.turnStoredIntoOriginal()), l.autoReloadId && (p("onSave -> autoReloadId detected: ", l.autoReloadId), e.readData.id = l.autoReloadId, p("onSave -> turning off create mode"), a.value = !1, U()), a.value ? typeof e.onCreate == "function" && (p("onSave -> trigger onCreate callback"), e.onCreate()) : typeof e.onUpdate == "function" && (p("onSave -> trigger onUpdate callback"), e.onUpdate()), n(R, l);
|
|
95
|
+
}, J = () => {
|
|
96
|
+
o.value = !0, i.value = -1;
|
|
97
|
+
}, F = () => {
|
|
98
|
+
o.value = !1;
|
|
91
99
|
};
|
|
92
|
-
|
|
100
|
+
$({
|
|
93
101
|
doDrop: () => {
|
|
94
|
-
|
|
102
|
+
C.value && typeof C.value.click == "function" && C.value.click();
|
|
95
103
|
},
|
|
96
|
-
doRefresh:
|
|
104
|
+
doRefresh: U,
|
|
97
105
|
doSave: () => {
|
|
98
|
-
|
|
106
|
+
g.value && typeof g.value.click == "function" && g.value.click();
|
|
99
107
|
}
|
|
100
108
|
});
|
|
101
|
-
const
|
|
102
|
-
return (t,
|
|
103
|
-
const
|
|
104
|
-
return
|
|
105
|
-
|
|
106
|
-
j("h1",
|
|
107
|
-
j("div",
|
|
109
|
+
const H = d(() => !e.hiddenDrop && !o.value && v.value && f.value), A = d(() => o.value ? !1 : a.value ? !0 : !e.hiddenSave && v.value && f.value), P = d(() => !o.value && !a.value && f.value), oe = d(() => !e.hiddenButtons && (A.value || H.value || P.value));
|
|
110
|
+
return (t, l) => {
|
|
111
|
+
const R = w("lkt-button"), re = w("lkt-field-switch"), z = w("lkt-http-info"), de = w("lkt-loader");
|
|
112
|
+
return c(), h("article", ve, [
|
|
113
|
+
ae.value ? (c(), h("header", fe, [
|
|
114
|
+
j("h1", pe, N(u.title), 1),
|
|
115
|
+
j("div", me, [
|
|
108
116
|
O(t.$slots, "post-title", {
|
|
109
117
|
item: r.value,
|
|
110
|
-
loading:
|
|
118
|
+
loading: o.value
|
|
111
119
|
})
|
|
112
120
|
])
|
|
113
|
-
])) :
|
|
114
|
-
|
|
115
|
-
a.
|
|
121
|
+
])) : D("", !0),
|
|
122
|
+
V(j("div", ye, [
|
|
123
|
+
a.value ? D("", !0) : V((c(), q(R, {
|
|
116
124
|
key: 0,
|
|
117
|
-
ref: (
|
|
125
|
+
ref: (y) => C.value = y,
|
|
118
126
|
palette: "danger",
|
|
119
|
-
disabled:
|
|
120
|
-
"confirm-modal":
|
|
121
|
-
"confirm-data":
|
|
122
|
-
resource:
|
|
123
|
-
"resource-data":
|
|
124
|
-
onLoading:
|
|
125
|
-
onLoaded:
|
|
126
|
-
onClick:
|
|
127
|
+
disabled: u.dropDisabled || !_.value,
|
|
128
|
+
"confirm-modal": u.dropConfirm,
|
|
129
|
+
"confirm-data": u.dropConfirmData,
|
|
130
|
+
resource: u.dropResource,
|
|
131
|
+
"resource-data": u.dropData,
|
|
132
|
+
onLoading: J,
|
|
133
|
+
onLoaded: F,
|
|
134
|
+
onClick: le
|
|
127
135
|
}, {
|
|
128
|
-
default:
|
|
129
|
-
|
|
136
|
+
default: G(() => [
|
|
137
|
+
K(M)["button-drop"] ? O(t.$slots, "button-drop", {
|
|
130
138
|
key: 0,
|
|
131
139
|
item: r.value,
|
|
132
|
-
editMode:
|
|
133
|
-
isCreate: a.
|
|
134
|
-
canUpdate:
|
|
135
|
-
canDrop:
|
|
136
|
-
}) : (
|
|
140
|
+
editMode: v.value,
|
|
141
|
+
isCreate: a.value,
|
|
142
|
+
canUpdate: B.value,
|
|
143
|
+
canDrop: _.value
|
|
144
|
+
}) : (c(), h("span", he, N(u.dropText), 1))
|
|
137
145
|
]),
|
|
138
146
|
_: 3
|
|
139
147
|
}, 8, ["disabled", "confirm-modal", "confirm-data", "resource", "resource-data"])), [
|
|
140
|
-
[
|
|
148
|
+
[I, H.value]
|
|
141
149
|
]),
|
|
142
|
-
|
|
143
|
-
ref: (
|
|
150
|
+
V(Q(R, {
|
|
151
|
+
ref: (y) => g.value = y,
|
|
144
152
|
palette: "success",
|
|
145
|
-
disabled: !
|
|
146
|
-
"confirm-modal":
|
|
147
|
-
"confirm-data":
|
|
148
|
-
resource:
|
|
149
|
-
"resource-data":
|
|
150
|
-
onLoading:
|
|
151
|
-
onLoaded:
|
|
152
|
-
onClick:
|
|
153
|
+
disabled: !E.value,
|
|
154
|
+
"confirm-modal": Y.value,
|
|
155
|
+
"confirm-data": Z.value,
|
|
156
|
+
resource: x.value,
|
|
157
|
+
"resource-data": ee.value,
|
|
158
|
+
onLoading: J,
|
|
159
|
+
onLoaded: F,
|
|
160
|
+
onClick: ue
|
|
153
161
|
}, {
|
|
154
|
-
default:
|
|
155
|
-
|
|
162
|
+
default: G(() => [
|
|
163
|
+
K(M)["button-save"] ? O(t.$slots, "button-save", {
|
|
156
164
|
key: 0,
|
|
157
165
|
item: r.value,
|
|
158
|
-
editMode:
|
|
159
|
-
isCreate: a.
|
|
160
|
-
canUpdate:
|
|
161
|
-
canDrop:
|
|
162
|
-
}) : (
|
|
166
|
+
editMode: v.value,
|
|
167
|
+
isCreate: a.value,
|
|
168
|
+
canUpdate: B.value,
|
|
169
|
+
canDrop: _.value
|
|
170
|
+
}) : (c(), h("span", Se, N(u.saveText), 1))
|
|
163
171
|
]),
|
|
164
172
|
_: 3
|
|
165
173
|
}, 8, ["disabled", "confirm-modal", "confirm-data", "resource", "resource-data"]), [
|
|
166
|
-
[
|
|
174
|
+
[I, A.value]
|
|
167
175
|
]),
|
|
168
|
-
|
|
169
|
-
modelValue:
|
|
170
|
-
"onUpdate:modelValue":
|
|
171
|
-
label:
|
|
176
|
+
V(Q(re, {
|
|
177
|
+
modelValue: v.value,
|
|
178
|
+
"onUpdate:modelValue": l[0] || (l[0] = (y) => v.value = y),
|
|
179
|
+
label: u.editModeText
|
|
172
180
|
}, null, 8, ["modelValue", "label"]), [
|
|
173
|
-
[
|
|
181
|
+
[I, P.value]
|
|
174
182
|
])
|
|
175
183
|
], 512), [
|
|
176
|
-
[
|
|
184
|
+
[I, oe.value]
|
|
177
185
|
]),
|
|
178
|
-
|
|
179
|
-
f.value ? (
|
|
180
|
-
|
|
186
|
+
o.value ? D("", !0) : (c(), h("div", ke, [
|
|
187
|
+
f.value ? (c(), h("div", be, [
|
|
188
|
+
m.value ? (c(), q(z, {
|
|
181
189
|
key: 0,
|
|
182
|
-
code:
|
|
190
|
+
code: i.value,
|
|
183
191
|
quick: "",
|
|
184
|
-
palette:
|
|
192
|
+
palette: i.value === 200 ? "success" : "danger",
|
|
185
193
|
"can-close": "",
|
|
186
|
-
onClose:
|
|
187
|
-
}, null, 8, ["code", "palette"])) :
|
|
194
|
+
onClose: l[1] || (l[1] = (y) => m.value = !1)
|
|
195
|
+
}, null, 8, ["code", "palette"])) : D("", !0),
|
|
188
196
|
O(t.$slots, "item", {
|
|
189
197
|
item: r.value,
|
|
190
|
-
loading:
|
|
191
|
-
editMode:
|
|
192
|
-
isCreate: a.
|
|
193
|
-
canUpdate:
|
|
194
|
-
canDrop:
|
|
198
|
+
loading: o.value,
|
|
199
|
+
editMode: v.value,
|
|
200
|
+
isCreate: a.value,
|
|
201
|
+
canUpdate: B.value,
|
|
202
|
+
canDrop: _.value
|
|
195
203
|
})
|
|
196
|
-
])) : (
|
|
204
|
+
])) : (c(), q(z, {
|
|
197
205
|
key: 1,
|
|
198
|
-
code:
|
|
206
|
+
code: i.value
|
|
199
207
|
}, null, 8, ["code"]))
|
|
200
208
|
])),
|
|
201
|
-
|
|
209
|
+
o.value ? (c(), q(de, { key: 2 })) : D("", !0)
|
|
202
210
|
]);
|
|
203
211
|
};
|
|
204
212
|
}
|
|
205
|
-
}),
|
|
206
|
-
install: (
|
|
207
|
-
|
|
213
|
+
}), Ve = {
|
|
214
|
+
install: (u, $ = {}) => {
|
|
215
|
+
u.component("lkt-item-crud") === void 0 && u.component("lkt-item-crud", ge);
|
|
208
216
|
}
|
|
209
217
|
};
|
|
210
218
|
export {
|
|
211
|
-
|
|
219
|
+
Oe as debugLktItemCrud,
|
|
220
|
+
Ve as default
|
|
212
221
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -132,6 +132,7 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<{
|
|
|
132
132
|
drop: (...args: any[]) => void;
|
|
133
133
|
update: (...args: any[]) => void;
|
|
134
134
|
"update:modelValue": (...args: any[]) => void;
|
|
135
|
+
"update:isCreate": (...args: any[]) => void;
|
|
135
136
|
read: (...args: any[]) => void;
|
|
136
137
|
create: (...args: any[]) => void;
|
|
137
138
|
perms: (...args: any[]) => void;
|
|
@@ -266,6 +267,7 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<{
|
|
|
266
267
|
onDrop?: ((...args: any[]) => any) | undefined;
|
|
267
268
|
onUpdate?: ((...args: any[]) => any) | undefined;
|
|
268
269
|
"onUpdate:modelValue"?: ((...args: any[]) => any) | undefined;
|
|
270
|
+
"onUpdate:isCreate"?: ((...args: any[]) => any) | undefined;
|
|
269
271
|
onRead?: ((...args: any[]) => any) | undefined;
|
|
270
272
|
onCreate?: ((...args: any[]) => any) | undefined;
|
|
271
273
|
onPerms?: ((...args: any[]) => any) | undefined;
|
package/package.json
CHANGED
|
@@ -6,6 +6,7 @@ export default {name: "LktItemCrud", inheritAttrs: false}
|
|
|
6
6
|
import {ref, watch, useSlots, computed} from "vue";
|
|
7
7
|
import {httpCall, HTTPResponse} from "lkt-http-client";
|
|
8
8
|
import {DataState} from "lkt-data-state";
|
|
9
|
+
import {debug} from "../functions/debug";
|
|
9
10
|
|
|
10
11
|
const props = defineProps({
|
|
11
12
|
modelValue: {type: Object, required: false, default: () => ({})},
|
|
@@ -49,7 +50,7 @@ const props = defineProps({
|
|
|
49
50
|
|
|
50
51
|
const slots = useSlots();
|
|
51
52
|
|
|
52
|
-
const emit = defineEmits(['update:modelValue', 'read', 'create', 'update', 'drop', 'perms', 'error', 'modified-data']);
|
|
53
|
+
const emit = defineEmits(['update:modelValue', 'update:isCreate', 'read', 'create', 'update', 'drop', 'perms', 'error', 'modified-data']);
|
|
53
54
|
|
|
54
55
|
let basePerms: string[] = [];
|
|
55
56
|
|
|
@@ -62,43 +63,46 @@ const isLoading = ref(true),
|
|
|
62
63
|
httpStatus = ref(200),
|
|
63
64
|
saveButton = ref(null),
|
|
64
65
|
dropButton = ref(null),
|
|
65
|
-
dataState = ref(new DataState(item.value))
|
|
66
|
+
dataState = ref(new DataState(item.value)),
|
|
67
|
+
createMode = ref(props.isCreate);
|
|
66
68
|
|
|
67
69
|
const saveConfirm = computed(() => {
|
|
68
|
-
return
|
|
70
|
+
return createMode.value
|
|
69
71
|
? props.createConfirm
|
|
70
72
|
: props.updateConfirm;
|
|
71
73
|
}),
|
|
72
74
|
confirmData = computed(() => {
|
|
73
|
-
return
|
|
75
|
+
return createMode.value
|
|
74
76
|
? props.createConfirmData
|
|
75
77
|
: props.updateConfirmData;
|
|
76
78
|
}),
|
|
77
79
|
saveResource = computed(() => {
|
|
78
|
-
return
|
|
80
|
+
return createMode.value
|
|
79
81
|
? props.createResource
|
|
80
82
|
: props.updateResource;
|
|
81
83
|
}),
|
|
82
84
|
saveData = computed(() => {
|
|
83
|
-
if (
|
|
85
|
+
if (createMode.value) {
|
|
84
86
|
return {...props.createData, ...JSON.parse(JSON.stringify(item.value))};
|
|
85
87
|
}
|
|
86
88
|
return {...props.updateData, ...JSON.parse(JSON.stringify(item.value))};
|
|
87
89
|
}),
|
|
88
90
|
saveDisabled = computed(() => {
|
|
89
|
-
return
|
|
91
|
+
return createMode.value
|
|
90
92
|
? props.createDisabled
|
|
91
93
|
: props.updateDisabled;
|
|
92
94
|
}),
|
|
93
|
-
canUpdate = computed(() => !
|
|
94
|
-
canDrop = computed(() => !
|
|
95
|
+
canUpdate = computed(() => !createMode.value && perms.value.includes('update')),
|
|
96
|
+
canDrop = computed(() => !createMode.value && perms.value.includes('drop'));
|
|
95
97
|
|
|
96
98
|
const fetchItem = async () => {
|
|
99
|
+
debug('fetchItem');
|
|
97
100
|
isLoading.value = true;
|
|
98
101
|
httpStatus.value = -1;
|
|
99
102
|
showStoreMessage.value = false;
|
|
100
103
|
try {
|
|
101
104
|
const r = await httpCall(props.readResource, props.readData);
|
|
105
|
+
debug('fetchItem -> response', r);
|
|
102
106
|
isLoading.value = false;
|
|
103
107
|
httpStatus.value = r.httpStatus;
|
|
104
108
|
if (!r.success) {
|
|
@@ -141,17 +145,18 @@ watch(perms, () => emit('perms', perms.value));
|
|
|
141
145
|
|
|
142
146
|
const ableToSave = computed(() => {
|
|
143
147
|
if (saveDisabled.value) return false;
|
|
144
|
-
if (!
|
|
148
|
+
if (!createMode.value && !canUpdate.value) return false;
|
|
145
149
|
|
|
146
150
|
if (typeof props.saveValidator === 'function' && !props.saveValidator(item.value)) return false;
|
|
147
151
|
|
|
148
152
|
return dataState.value.changed();
|
|
149
153
|
});
|
|
150
154
|
watch(ableToSave, (v) => emit('modified-data', v));
|
|
155
|
+
watch(createMode, (v) => emit('update:isCreate', v));
|
|
151
156
|
|
|
152
157
|
// Fetch item
|
|
153
|
-
if (props.readResource && !
|
|
154
|
-
else if (
|
|
158
|
+
if (props.readResource && !createMode.value) fetchItem();
|
|
159
|
+
else if (createMode.value) {
|
|
155
160
|
httpSuccessRead.value = true;
|
|
156
161
|
editMode.value = true;
|
|
157
162
|
isLoading.value = false;
|
|
@@ -170,6 +175,7 @@ const onDrop = ($event: PointerEvent, r: HTTPResponse) => {
|
|
|
170
175
|
|
|
171
176
|
},
|
|
172
177
|
onSave = ($event: PointerEvent, r: HTTPResponse) => {
|
|
178
|
+
debug('onSave -> received response:', r);
|
|
173
179
|
if (saveResource.value) {
|
|
174
180
|
isLoading.value = false;
|
|
175
181
|
httpStatus.value = r.httpStatus;
|
|
@@ -180,19 +186,29 @@ const onDrop = ($event: PointerEvent, r: HTTPResponse) => {
|
|
|
180
186
|
}
|
|
181
187
|
showStoreMessage.value = true;
|
|
182
188
|
}
|
|
183
|
-
let emits: 'create' | 'update' =
|
|
184
|
-
if (!
|
|
189
|
+
let emits: 'create' | 'update' = createMode.value ? 'create' : 'update';
|
|
190
|
+
if (!createMode.value) {
|
|
191
|
+
debug('onSave -> turn stored data into original');
|
|
185
192
|
dataState.value.turnStoredIntoOriginal();
|
|
186
193
|
}
|
|
187
194
|
|
|
188
195
|
if (r.autoReloadId) {
|
|
196
|
+
debug('onSave -> autoReloadId detected: ', r.autoReloadId);
|
|
189
197
|
props.readData['id'] = r.autoReloadId;
|
|
198
|
+
debug('onSave -> turning off create mode');
|
|
199
|
+
createMode.value = false;
|
|
190
200
|
fetchItem();
|
|
191
201
|
}
|
|
192
|
-
if (
|
|
193
|
-
if (typeof props.onCreate === 'function')
|
|
202
|
+
if (createMode.value) {
|
|
203
|
+
if (typeof props.onCreate === 'function') {
|
|
204
|
+
debug('onSave -> trigger onCreate callback');
|
|
205
|
+
props.onCreate();
|
|
206
|
+
}
|
|
194
207
|
} else {
|
|
195
|
-
if (typeof props.onUpdate === 'function')
|
|
208
|
+
if (typeof props.onUpdate === 'function') {
|
|
209
|
+
debug('onSave -> trigger onUpdate callback');
|
|
210
|
+
props.onUpdate();
|
|
211
|
+
}
|
|
196
212
|
}
|
|
197
213
|
emit(emits, r)
|
|
198
214
|
},
|
|
@@ -227,7 +243,7 @@ const showDropButton = computed(() => {
|
|
|
227
243
|
showSaveButton = computed(() => {
|
|
228
244
|
if (isLoading.value) return false;
|
|
229
245
|
|
|
230
|
-
if (
|
|
246
|
+
if (createMode.value) return true;
|
|
231
247
|
|
|
232
248
|
return !props.hiddenSave
|
|
233
249
|
&& editMode.value
|
|
@@ -235,7 +251,7 @@ const showDropButton = computed(() => {
|
|
|
235
251
|
}),
|
|
236
252
|
showSwitchButton = computed(() => {
|
|
237
253
|
return !isLoading.value
|
|
238
|
-
&& !
|
|
254
|
+
&& !createMode.value
|
|
239
255
|
&& httpSuccessRead.value;
|
|
240
256
|
}),
|
|
241
257
|
showButtons = computed(() => {
|
|
@@ -255,7 +271,7 @@ const showDropButton = computed(() => {
|
|
|
255
271
|
<lkt-button
|
|
256
272
|
:ref="(el:any) => dropButton = el"
|
|
257
273
|
v-show="showDropButton"
|
|
258
|
-
v-if="!
|
|
274
|
+
v-if="!createMode"
|
|
259
275
|
palette="danger"
|
|
260
276
|
v-bind:disabled="dropDisabled || !canDrop"
|
|
261
277
|
v-bind:confirm-modal="dropConfirm"
|
|
@@ -267,7 +283,7 @@ const showDropButton = computed(() => {
|
|
|
267
283
|
v-on:click="onDrop">
|
|
268
284
|
<slot v-if="!!slots['button-drop']" name="button-drop" v-bind:item="item"
|
|
269
285
|
v-bind:edit-mode="editMode"
|
|
270
|
-
v-bind:is-create="
|
|
286
|
+
v-bind:is-create="createMode"
|
|
271
287
|
v-bind:can-update="canUpdate"
|
|
272
288
|
v-bind:can-drop="canDrop"></slot>
|
|
273
289
|
<span v-else>{{ dropText }}</span>
|
|
@@ -287,7 +303,7 @@ const showDropButton = computed(() => {
|
|
|
287
303
|
v-on:click="onSave">
|
|
288
304
|
<slot v-if="!!slots['button-save']" name="button-save" v-bind:item="item"
|
|
289
305
|
v-bind:edit-mode="editMode"
|
|
290
|
-
v-bind:is-create="
|
|
306
|
+
v-bind:is-create="createMode"
|
|
291
307
|
v-bind:can-update="canUpdate"
|
|
292
308
|
v-bind:can-drop="canDrop"></slot>
|
|
293
309
|
<span v-else>{{ saveText }}</span>
|
|
@@ -303,7 +319,7 @@ const showDropButton = computed(() => {
|
|
|
303
319
|
:palette="httpStatus === 200 ? 'success' : 'danger'" can-close
|
|
304
320
|
v-on:close="showStoreMessage = false"></lkt-http-info>
|
|
305
321
|
<slot name="item" v-bind:item="item" v-bind:loading="isLoading" v-bind:edit-mode="editMode"
|
|
306
|
-
v-bind:is-create="
|
|
322
|
+
v-bind:is-create="createMode"
|
|
307
323
|
v-bind:can-update="canUpdate"
|
|
308
324
|
v-bind:can-drop="canDrop"></slot>
|
|
309
325
|
</div>
|