lkt-item-crud 1.0.5 → 1.0.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/LICENSE
CHANGED
package/dist/lkt-item-crud.es.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import { defineComponent as
|
|
2
|
-
import { httpCall as
|
|
3
|
-
import { DataState as
|
|
4
|
-
const
|
|
1
|
+
import { defineComponent as Z, useSlots as ee, ref as d, computed as v, watch as R, resolveComponent as V, openBlock as i, createElementBlock as m, createElementVNode as I, toDisplayString as M, renderSlot as _, createCommentVNode as C, withDirectives as q, createBlock as B, withCtx as U, unref as J, vShow as O, createVNode as E } from "vue";
|
|
2
|
+
import { httpCall as te } from "lkt-http-client";
|
|
3
|
+
import { DataState as ae } from "lkt-data-state";
|
|
4
|
+
const le = { class: "lkt-item-crud" }, ue = {
|
|
5
5
|
key: 0,
|
|
6
6
|
class: "lkt-item-crud_header"
|
|
7
|
-
},
|
|
7
|
+
}, re = { class: "lkt-item-crud_header-title" }, oe = { class: "lkt-item-crud_header-slot" }, se = { class: "lkt-item-crud-buttons" }, de = { key: 1 }, ie = { key: 1 }, ne = {
|
|
8
8
|
key: 1,
|
|
9
9
|
class: "lkt-item-crud_content"
|
|
10
|
-
},
|
|
10
|
+
}, ce = {
|
|
11
11
|
key: 0,
|
|
12
12
|
class: "lkt-grid-1"
|
|
13
|
-
},
|
|
14
|
-
...
|
|
13
|
+
}, ve = { name: "LktItemCrud", inheritAttrs: !1 }, fe = /* @__PURE__ */ Z({
|
|
14
|
+
...ve,
|
|
15
15
|
props: {
|
|
16
16
|
modelValue: { type: Object, required: !1, default: () => ({}) },
|
|
17
17
|
title: { type: String, default: "" },
|
|
@@ -36,155 +36,164 @@ const te = { class: "lkt-item-crud" }, ae = {
|
|
|
36
36
|
saveValidator: { type: Function, required: !1, default: () => !0 }
|
|
37
37
|
},
|
|
38
38
|
emits: ["update:modelValue", "read", "create", "update", "drop", "perms", "error", "modified-data"],
|
|
39
|
-
setup(
|
|
40
|
-
const e =
|
|
39
|
+
setup(a, { expose: N, emit: A }) {
|
|
40
|
+
const e = a, L = ee(), o = A;
|
|
41
41
|
let F = [];
|
|
42
|
-
const
|
|
43
|
-
|
|
42
|
+
const l = d(!0), r = d(e.modelValue), y = d(F), c = d(!1), n = d(!1), f = d(!1), s = d(200), S = d(null), h = d(null), k = d(new ae(r.value)), H = v(() => e.isCreate ? e.createConfirm : e.updateConfirm), P = v(() => e.isCreate ? e.createResource : e.updateResource), z = v(() => e.isCreate ? { ...e.createData, ...JSON.parse(JSON.stringify(r.value)) } : { ...e.updateData, ...JSON.parse(JSON.stringify(r.value)) }), G = v(() => e.isCreate ? e.createDisabled : e.updateDisabled), D = v(() => !e.isCreate && y.value.includes("update")), b = v(() => !e.isCreate && y.value.includes("drop")), w = async () => {
|
|
43
|
+
l.value = !0, s.value = -1, f.value = !1;
|
|
44
44
|
try {
|
|
45
|
-
const t = await
|
|
46
|
-
if (
|
|
47
|
-
|
|
45
|
+
const t = await te(e.readResource, e.readData);
|
|
46
|
+
if (l.value = !1, s.value = t.httpStatus, !t.success) {
|
|
47
|
+
n.value = !1, s.value = t.httpStatus, o("error", t.httpStatus);
|
|
48
48
|
return;
|
|
49
49
|
}
|
|
50
|
-
|
|
50
|
+
n.value = !0, r.value = t.data, y.value = t.perms, k.value.increment(r.value).turnStoredIntoOriginal(), o("read", t);
|
|
51
51
|
} catch {
|
|
52
|
-
|
|
52
|
+
l.value = !1, n.value = !1, s.value = 404, o("error", 404);
|
|
53
53
|
return;
|
|
54
54
|
}
|
|
55
|
-
},
|
|
56
|
-
|
|
55
|
+
}, K = v(() => l.value ? !1 : e.title || !!L["post-title"]);
|
|
56
|
+
R(() => e.modelValue, (t) => {
|
|
57
57
|
r.value = t, k.value.increment(t);
|
|
58
|
-
}, { deep: !0 }),
|
|
58
|
+
}, { deep: !0 }), R(r, (t) => {
|
|
59
59
|
o("update:modelValue", r.value), k.value.increment(t);
|
|
60
|
-
}, { deep: !0 }),
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
const
|
|
64
|
-
if (
|
|
65
|
-
|
|
60
|
+
}, { deep: !0 }), R(y, () => o("perms", y.value));
|
|
61
|
+
const T = v(() => G.value || !e.isCreate && !D.value || typeof e.saveValidator == "function" && !e.saveValidator(r.value) ? !1 : k.value.changed());
|
|
62
|
+
R(T, (t) => o("modified-data", t)), e.readResource && !e.isCreate ? w() : e.isCreate && (n.value = !0, c.value = !0, l.value = !1);
|
|
63
|
+
const Q = (t, u) => {
|
|
64
|
+
if (l.value = !1, s.value = u.httpStatus, !u.success) {
|
|
65
|
+
f.value = !0, o("error", u.httpStatus);
|
|
66
66
|
return;
|
|
67
67
|
}
|
|
68
|
-
|
|
69
|
-
},
|
|
70
|
-
if (
|
|
71
|
-
|
|
68
|
+
f.value = !0, o("drop", u);
|
|
69
|
+
}, W = (t, u) => {
|
|
70
|
+
if (l.value = !1, s.value = u.httpStatus, !u.success) {
|
|
71
|
+
f.value = !0, o("error", u.httpStatus);
|
|
72
72
|
return;
|
|
73
73
|
}
|
|
74
|
-
|
|
75
|
-
let
|
|
76
|
-
e.isCreate || k.value.turnStoredIntoOriginal(), o(
|
|
77
|
-
}, T = () => {
|
|
78
|
-
a.value = !0, n.value = -1;
|
|
74
|
+
f.value = !0;
|
|
75
|
+
let g = e.isCreate ? "create" : "update";
|
|
76
|
+
e.isCreate || k.value.turnStoredIntoOriginal(), u.autoReloadId && (e.readData.id = u.autoReloadId, w()), o(g, u);
|
|
79
77
|
}, $ = () => {
|
|
80
|
-
|
|
78
|
+
l.value = !0, s.value = -1;
|
|
79
|
+
}, x = () => {
|
|
80
|
+
l.value = !1;
|
|
81
81
|
};
|
|
82
|
-
return
|
|
82
|
+
return N({
|
|
83
83
|
doDrop: () => {
|
|
84
|
-
|
|
84
|
+
h.value && typeof h.value.click == "function" && h.value.click();
|
|
85
85
|
},
|
|
86
|
-
doRefresh:
|
|
86
|
+
doRefresh: w,
|
|
87
87
|
doSave: () => {
|
|
88
|
-
|
|
88
|
+
S.value && typeof S.value.click == "function" && S.value.click();
|
|
89
89
|
}
|
|
90
|
-
}), (t,
|
|
91
|
-
const
|
|
92
|
-
return
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
90
|
+
}), (t, u) => {
|
|
91
|
+
const g = V("lkt-button"), X = V("lkt-field-switch"), j = V("lkt-http-info"), Y = V("lkt-loader");
|
|
92
|
+
return i(), m("article", le, [
|
|
93
|
+
K.value ? (i(), m("header", ue, [
|
|
94
|
+
I("h1", re, M(a.title), 1),
|
|
95
|
+
I("div", oe, [
|
|
96
|
+
_(t.$slots, "post-title", {
|
|
97
97
|
item: r.value,
|
|
98
|
-
loading:
|
|
98
|
+
loading: l.value
|
|
99
99
|
})
|
|
100
100
|
])
|
|
101
|
-
])) :
|
|
102
|
-
|
|
103
|
-
|
|
101
|
+
])) : C("", !0),
|
|
102
|
+
q(I("div", se, [
|
|
103
|
+
a.isCreate ? C("", !0) : q((i(), B(g, {
|
|
104
104
|
key: 0,
|
|
105
|
-
ref: (
|
|
105
|
+
ref: (p) => h.value = p,
|
|
106
106
|
palette: "danger",
|
|
107
|
-
disabled:
|
|
108
|
-
"confirm-modal":
|
|
109
|
-
resource:
|
|
110
|
-
"resource-data":
|
|
111
|
-
onLoading:
|
|
112
|
-
onLoaded:
|
|
113
|
-
onClick:
|
|
107
|
+
disabled: a.dropDisabled || !b.value,
|
|
108
|
+
"confirm-modal": a.dropConfirm,
|
|
109
|
+
resource: a.dropResource,
|
|
110
|
+
"resource-data": a.dropData,
|
|
111
|
+
onLoading: $,
|
|
112
|
+
onLoaded: x,
|
|
113
|
+
onClick: Q
|
|
114
114
|
}, {
|
|
115
|
-
default:
|
|
116
|
-
|
|
115
|
+
default: U(() => [
|
|
116
|
+
J(L)["button-drop"] ? _(t.$slots, "button-drop", {
|
|
117
117
|
key: 0,
|
|
118
118
|
item: r.value,
|
|
119
|
-
editMode: c.value
|
|
120
|
-
|
|
119
|
+
editMode: c.value,
|
|
120
|
+
isCreate: a.isCreate,
|
|
121
|
+
canUpdate: D.value,
|
|
122
|
+
canDrop: b.value
|
|
123
|
+
}) : (i(), m("span", de, M(a.dropText), 1))
|
|
121
124
|
]),
|
|
122
125
|
_: 3
|
|
123
126
|
}, 8, ["disabled", "confirm-modal", "resource", "resource-data"])), [
|
|
124
|
-
[
|
|
127
|
+
[O, !l.value && c.value && n.value]
|
|
125
128
|
]),
|
|
126
|
-
|
|
127
|
-
ref: (
|
|
129
|
+
q(E(g, {
|
|
130
|
+
ref: (p) => S.value = p,
|
|
128
131
|
palette: "success",
|
|
129
|
-
disabled: !
|
|
132
|
+
disabled: !T.value,
|
|
130
133
|
"confirm-modal": H.value,
|
|
131
134
|
resource: P.value,
|
|
132
|
-
"resource-data":
|
|
133
|
-
onLoading:
|
|
134
|
-
onLoaded:
|
|
135
|
-
onClick:
|
|
135
|
+
"resource-data": z.value,
|
|
136
|
+
onLoading: $,
|
|
137
|
+
onLoaded: x,
|
|
138
|
+
onClick: W
|
|
136
139
|
}, {
|
|
137
|
-
default:
|
|
138
|
-
|
|
140
|
+
default: U(() => [
|
|
141
|
+
J(L)["button-save"] ? _(t.$slots, "button-save", {
|
|
139
142
|
key: 0,
|
|
140
143
|
item: r.value,
|
|
141
|
-
editMode: c.value
|
|
142
|
-
|
|
144
|
+
editMode: c.value,
|
|
145
|
+
isCreate: a.isCreate,
|
|
146
|
+
canUpdate: D.value,
|
|
147
|
+
canDrop: b.value
|
|
148
|
+
}) : (i(), m("span", ie, M(a.saveText), 1))
|
|
143
149
|
]),
|
|
144
150
|
_: 3
|
|
145
151
|
}, 8, ["disabled", "confirm-modal", "resource", "resource-data"]), [
|
|
146
|
-
[
|
|
152
|
+
[O, !l.value && c.value && n.value]
|
|
147
153
|
]),
|
|
148
|
-
|
|
154
|
+
q(E(X, {
|
|
149
155
|
modelValue: c.value,
|
|
150
|
-
"onUpdate:modelValue":
|
|
151
|
-
label:
|
|
156
|
+
"onUpdate:modelValue": u[0] || (u[0] = (p) => c.value = p),
|
|
157
|
+
label: a.editModeText
|
|
152
158
|
}, null, 8, ["modelValue", "label"]), [
|
|
153
|
-
[
|
|
159
|
+
[O, !l.value && n.value && !a.isCreate]
|
|
154
160
|
])
|
|
155
161
|
], 512), [
|
|
156
|
-
[
|
|
162
|
+
[O, n.value]
|
|
157
163
|
]),
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
164
|
+
l.value ? C("", !0) : (i(), m("div", ne, [
|
|
165
|
+
n.value ? (i(), m("div", ce, [
|
|
166
|
+
f.value ? (i(), B(j, {
|
|
161
167
|
key: 0,
|
|
162
|
-
code:
|
|
168
|
+
code: s.value,
|
|
163
169
|
quick: "",
|
|
164
|
-
palette:
|
|
170
|
+
palette: s.value === 200 ? "success" : "danger",
|
|
165
171
|
"can-close": "",
|
|
166
|
-
onClose:
|
|
167
|
-
}, null, 8, ["code", "palette"])) :
|
|
168
|
-
|
|
172
|
+
onClose: u[1] || (u[1] = (p) => f.value = !1)
|
|
173
|
+
}, null, 8, ["code", "palette"])) : C("", !0),
|
|
174
|
+
_(t.$slots, "item", {
|
|
169
175
|
item: r.value,
|
|
170
|
-
loading:
|
|
171
|
-
editMode: c.value
|
|
176
|
+
loading: l.value,
|
|
177
|
+
editMode: c.value,
|
|
178
|
+
isCreate: a.isCreate,
|
|
179
|
+
canUpdate: D.value,
|
|
180
|
+
canDrop: b.value
|
|
172
181
|
})
|
|
173
|
-
])) : (
|
|
182
|
+
])) : (i(), B(j, {
|
|
174
183
|
key: 1,
|
|
175
|
-
code:
|
|
184
|
+
code: s.value
|
|
176
185
|
}, null, 8, ["code"]))
|
|
177
186
|
])),
|
|
178
|
-
|
|
187
|
+
l.value ? (i(), B(Y, { key: 2 })) : C("", !0)
|
|
179
188
|
]);
|
|
180
189
|
};
|
|
181
190
|
}
|
|
182
191
|
});
|
|
183
|
-
const
|
|
184
|
-
install: (
|
|
185
|
-
|
|
192
|
+
const Se = {
|
|
193
|
+
install: (a, N = {}) => {
|
|
194
|
+
a.component("LktItemCrud", fe);
|
|
186
195
|
}
|
|
187
196
|
};
|
|
188
197
|
export {
|
|
189
|
-
|
|
198
|
+
Se as default
|
|
190
199
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(e,p){typeof exports=="object"&&typeof module<"u"?module.exports=p(require("vue"),require("lkt-http-client"),require("lkt-data-state")):typeof define=="function"&&define.amd?define(["vue","lkt-http-client","lkt-data-state"],p):(e=typeof globalThis<"u"?globalThis:e||self,e.LktItemCrud=p(e.Vue,e.LktHttpClient,e.LktDataState))})(this,function(e,p,
|
|
1
|
+
(function(e,p){typeof exports=="object"&&typeof module<"u"?module.exports=p(require("vue"),require("lkt-http-client"),require("lkt-data-state")):typeof define=="function"&&define.amd?define(["vue","lkt-http-client","lkt-data-state"],p):(e=typeof globalThis<"u"?globalThis:e||self,e.LktItemCrud=p(e.Vue,e.LktHttpClient,e.LktDataState))})(this,function(e,p,L){"use strict";const N={class:"lkt-item-crud"},R={key:0,class:"lkt-item-crud_header"},_={class:"lkt-item-crud_header-title"},I={class:"lkt-item-crud_header-slot"},O={class:"lkt-item-crud-buttons"},E={key:1},T={key:1},x={key:1,class:"lkt-item-crud_content"},M={key:0,class:"lkt-grid-1"},$={name:"LktItemCrud",inheritAttrs:!1},j=e.defineComponent({...$,props:{modelValue:{type:Object,required:!1,default:()=>({})},title:{type:String,default:""},editModeText:{type:String,default:"Edition Mode"},saveText:{type:String,default:"Save"},dropText:{type:String,default:"Delete"},readResource:{type:String,required:!0},createResource:{type:String,required:!1},updateResource:{type:String,required:!1},dropResource:{type:String,required:!1},readData:{type:Object,required:!1,default:()=>({})},createData:{type:Object,required:!1,default:()=>({})},updateData:{type:Object,required:!1,default:()=>({})},dropData:{type:Object,required:!1,default:()=>({})},isCreate:{type:Boolean,default:!1},createConfirm:{type:String,default:""},updateConfirm:{type:String,default:""},dropConfirm:{type:String,default:""},createDisabled:{type:Boolean,default:!1},updateDisabled:{type:Boolean,default:!1},dropDisabled:{type:Boolean,default:!1},saveValidator:{type:Function,required:!1,default:()=>!0}},emits:["update:modelValue","read","create","update","drop","perms","error","modified-data"],setup(l,{expose:g,emit:U}){const t=l,D=e.useSlots(),n=U;let J=[];const r=e.ref(!0),d=e.ref(t.modelValue),m=e.ref(J),u=e.ref(!1),i=e.ref(!1),c=e.ref(!1),s=e.ref(200),v=e.ref(null),h=e.ref(null),k=e.ref(new L.DataState(d.value)),H=e.computed(()=>t.isCreate?t.createConfirm:t.updateConfirm),A=e.computed(()=>t.isCreate?t.createResource:t.updateResource),F=e.computed(()=>t.isCreate?{...t.createData,...JSON.parse(JSON.stringify(d.value))}:{...t.updateData,...JSON.parse(JSON.stringify(d.value))}),P=e.computed(()=>t.isCreate?t.createDisabled:t.updateDisabled),C=e.computed(()=>!t.isCreate&&m.value.includes("update")),S=e.computed(()=>!t.isCreate&&m.value.includes("drop")),B=async()=>{r.value=!0,s.value=-1,c.value=!1;try{const a=await p.httpCall(t.readResource,t.readData);if(r.value=!1,s.value=a.httpStatus,!a.success){i.value=!1,s.value=a.httpStatus,n("error",a.httpStatus);return}i.value=!0,d.value=a.data,m.value=a.perms,k.value.increment(d.value).turnStoredIntoOriginal(),n("read",a)}catch{r.value=!1,i.value=!1,s.value=404,n("error",404);return}},z=e.computed(()=>r.value?!1:t.title||!!D["post-title"]);e.watch(()=>t.modelValue,a=>{d.value=a,k.value.increment(a)},{deep:!0}),e.watch(d,a=>{n("update:modelValue",d.value),k.value.increment(a)},{deep:!0}),e.watch(m,()=>n("perms",m.value));const b=e.computed(()=>P.value||!t.isCreate&&!C.value||typeof t.saveValidator=="function"&&!t.saveValidator(d.value)?!1:k.value.changed());e.watch(b,a=>n("modified-data",a)),t.readResource&&!t.isCreate?B():t.isCreate&&(i.value=!0,u.value=!0,r.value=!1);const G=(a,o)=>{if(r.value=!1,s.value=o.httpStatus,!o.success){c.value=!0,n("error",o.httpStatus);return}c.value=!0,n("drop",o)},K=(a,o)=>{if(r.value=!1,s.value=o.httpStatus,!o.success){c.value=!0,n("error",o.httpStatus);return}c.value=!0;let y=t.isCreate?"create":"update";t.isCreate||k.value.turnStoredIntoOriginal(),o.autoReloadId&&(t.readData.id=o.autoReloadId,B()),n(y,o)},V=()=>{r.value=!0,s.value=-1},w=()=>{r.value=!1};return g({doDrop:()=>{h.value&&typeof h.value.click=="function"&&h.value.click()},doRefresh:B,doSave:()=>{v.value&&typeof v.value.click=="function"&&v.value.click()}}),(a,o)=>{const y=e.resolveComponent("lkt-button"),Q=e.resolveComponent("lkt-field-switch"),q=e.resolveComponent("lkt-http-info"),W=e.resolveComponent("lkt-loader");return e.openBlock(),e.createElementBlock("article",N,[z.value?(e.openBlock(),e.createElementBlock("header",R,[e.createElementVNode("h1",_,e.toDisplayString(l.title),1),e.createElementVNode("div",I,[e.renderSlot(a.$slots,"post-title",{item:d.value,loading:r.value})])])):e.createCommentVNode("",!0),e.withDirectives(e.createElementVNode("div",O,[l.isCreate?e.createCommentVNode("",!0):e.withDirectives((e.openBlock(),e.createBlock(y,{key:0,ref:f=>h.value=f,palette:"danger",disabled:l.dropDisabled||!S.value,"confirm-modal":l.dropConfirm,resource:l.dropResource,"resource-data":l.dropData,onLoading:V,onLoaded:w,onClick:G},{default:e.withCtx(()=>[e.unref(D)["button-drop"]?e.renderSlot(a.$slots,"button-drop",{key:0,item:d.value,editMode:u.value,isCreate:l.isCreate,canUpdate:C.value,canDrop:S.value}):(e.openBlock(),e.createElementBlock("span",E,e.toDisplayString(l.dropText),1))]),_:3},8,["disabled","confirm-modal","resource","resource-data"])),[[e.vShow,!r.value&&u.value&&i.value]]),e.withDirectives(e.createVNode(y,{ref:f=>v.value=f,palette:"success",disabled:!b.value,"confirm-modal":H.value,resource:A.value,"resource-data":F.value,onLoading:V,onLoaded:w,onClick:K},{default:e.withCtx(()=>[e.unref(D)["button-save"]?e.renderSlot(a.$slots,"button-save",{key:0,item:d.value,editMode:u.value,isCreate:l.isCreate,canUpdate:C.value,canDrop:S.value}):(e.openBlock(),e.createElementBlock("span",T,e.toDisplayString(l.saveText),1))]),_:3},8,["disabled","confirm-modal","resource","resource-data"]),[[e.vShow,!r.value&&u.value&&i.value]]),e.withDirectives(e.createVNode(Q,{modelValue:u.value,"onUpdate:modelValue":o[0]||(o[0]=f=>u.value=f),label:l.editModeText},null,8,["modelValue","label"]),[[e.vShow,!r.value&&i.value&&!l.isCreate]])],512),[[e.vShow,i.value]]),r.value?e.createCommentVNode("",!0):(e.openBlock(),e.createElementBlock("div",x,[i.value?(e.openBlock(),e.createElementBlock("div",M,[c.value?(e.openBlock(),e.createBlock(q,{key:0,code:s.value,quick:"",palette:s.value===200?"success":"danger","can-close":"",onClose:o[1]||(o[1]=f=>c.value=!1)},null,8,["code","palette"])):e.createCommentVNode("",!0),e.renderSlot(a.$slots,"item",{item:d.value,loading:r.value,editMode:u.value,isCreate:l.isCreate,canUpdate:C.value,canDrop:S.value})])):(e.openBlock(),e.createBlock(q,{key:1,code:s.value},null,8,["code"]))])),r.value?(e.openBlock(),e.createBlock(W,{key:2})):e.createCommentVNode("",!0)])}}}),X="";return{install:(l,g={})=>{l.component("LktItemCrud",j)}}});
|
|
@@ -485,15 +485,24 @@ declare const _default: {
|
|
|
485
485
|
'button-drop': (_: {
|
|
486
486
|
item: Record<string, any>;
|
|
487
487
|
editMode: boolean;
|
|
488
|
+
isCreate: false;
|
|
489
|
+
canUpdate: boolean;
|
|
490
|
+
canDrop: boolean;
|
|
488
491
|
}) => any;
|
|
489
492
|
'button-save': (_: {
|
|
490
493
|
item: Record<string, any>;
|
|
491
494
|
editMode: boolean;
|
|
495
|
+
isCreate: boolean;
|
|
496
|
+
canUpdate: boolean;
|
|
497
|
+
canDrop: boolean;
|
|
492
498
|
}) => any;
|
|
493
499
|
item: (_: {
|
|
494
500
|
item: Record<string, any>;
|
|
495
501
|
loading: false;
|
|
496
502
|
editMode: boolean;
|
|
503
|
+
isCreate: boolean;
|
|
504
|
+
canUpdate: boolean;
|
|
505
|
+
canDrop: boolean;
|
|
497
506
|
}) => any;
|
|
498
507
|
};
|
|
499
508
|
});
|
package/package.json
CHANGED
|
@@ -65,22 +65,27 @@ const saveConfirm = computed(() => {
|
|
|
65
65
|
: props.updateResource;
|
|
66
66
|
}),
|
|
67
67
|
saveData = computed(() => {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
68
|
+
if (props.isCreate) {
|
|
69
|
+
return {...props.createData, ...JSON.parse(JSON.stringify(item.value))};
|
|
70
|
+
}
|
|
71
|
+
return {...props.updateData, ...JSON.parse(JSON.stringify(item.value))};
|
|
71
72
|
}),
|
|
72
73
|
saveDisabled = computed(() => {
|
|
73
74
|
return props.isCreate
|
|
74
75
|
? props.createDisabled
|
|
75
76
|
: props.updateDisabled;
|
|
76
|
-
})
|
|
77
|
+
}),
|
|
78
|
+
canUpdate = computed(() => !props.isCreate && perms.value.includes('update')),
|
|
79
|
+
canDrop = computed(() => !props.isCreate && perms.value.includes('drop'));
|
|
77
80
|
|
|
78
81
|
const fetchItem = async () => {
|
|
79
82
|
isLoading.value = true;
|
|
80
83
|
httpStatus.value = -1;
|
|
84
|
+
showStoreMessage.value = false;
|
|
81
85
|
try {
|
|
82
86
|
const r = await httpCall(props.readResource, props.readData);
|
|
83
87
|
isLoading.value = false;
|
|
88
|
+
httpStatus.value = r.httpStatus;
|
|
84
89
|
if (!r.success) {
|
|
85
90
|
httpSuccessRead.value = false;
|
|
86
91
|
httpStatus.value = r.httpStatus;
|
|
@@ -121,6 +126,7 @@ watch(perms, () => emit('perms', perms.value));
|
|
|
121
126
|
|
|
122
127
|
const ableToSave = computed(() => {
|
|
123
128
|
if (saveDisabled.value) return false;
|
|
129
|
+
if (!props.isCreate && !canUpdate.value) return false;
|
|
124
130
|
|
|
125
131
|
if (typeof props.saveValidator === 'function' && !props.saveValidator(item.value)) return false;
|
|
126
132
|
|
|
@@ -161,6 +167,11 @@ const onDrop = ($event: PointerEvent, r: HTTPResponse) => {
|
|
|
161
167
|
if (!props.isCreate) {
|
|
162
168
|
dataState.value.turnStoredIntoOriginal();
|
|
163
169
|
}
|
|
170
|
+
|
|
171
|
+
if (r.autoReloadId) {
|
|
172
|
+
props.readData['id'] = r.autoReloadId;
|
|
173
|
+
fetchItem();
|
|
174
|
+
}
|
|
164
175
|
emit(emits, r)
|
|
165
176
|
|
|
166
177
|
},
|
|
@@ -201,7 +212,7 @@ defineExpose({
|
|
|
201
212
|
v-show="!isLoading && editMode && httpSuccessRead"
|
|
202
213
|
v-if="!isCreate"
|
|
203
214
|
palette="danger"
|
|
204
|
-
v-bind:disabled="dropDisabled"
|
|
215
|
+
v-bind:disabled="dropDisabled || !canDrop"
|
|
205
216
|
v-bind:confirm-modal="dropConfirm"
|
|
206
217
|
v-bind:resource="dropResource"
|
|
207
218
|
v-bind:resource-data="dropData"
|
|
@@ -209,7 +220,10 @@ defineExpose({
|
|
|
209
220
|
v-on:loaded="onButtonLoaded"
|
|
210
221
|
v-on:click="onDrop">
|
|
211
222
|
<slot v-if="!!slots['button-drop']" name="button-drop" v-bind:item="item"
|
|
212
|
-
v-bind:edit-mode="editMode"
|
|
223
|
+
v-bind:edit-mode="editMode"
|
|
224
|
+
v-bind:is-create="isCreate"
|
|
225
|
+
v-bind:can-update="canUpdate"
|
|
226
|
+
v-bind:can-drop="canDrop"></slot>
|
|
213
227
|
<span v-else>{{ dropText }}</span>
|
|
214
228
|
</lkt-button>
|
|
215
229
|
|
|
@@ -225,7 +239,10 @@ defineExpose({
|
|
|
225
239
|
v-on:loaded="onButtonLoaded"
|
|
226
240
|
v-on:click="onSave">
|
|
227
241
|
<slot v-if="!!slots['button-save']" name="button-save" v-bind:item="item"
|
|
228
|
-
v-bind:edit-mode="editMode"
|
|
242
|
+
v-bind:edit-mode="editMode"
|
|
243
|
+
v-bind:is-create="isCreate"
|
|
244
|
+
v-bind:can-update="canUpdate"
|
|
245
|
+
v-bind:can-drop="canDrop"></slot>
|
|
229
246
|
<span v-else>{{ saveText }}</span>
|
|
230
247
|
</lkt-button>
|
|
231
248
|
|
|
@@ -238,7 +255,10 @@ defineExpose({
|
|
|
238
255
|
<lkt-http-info :code="httpStatus" v-if="showStoreMessage" quick
|
|
239
256
|
:palette="httpStatus === 200 ? 'success' : 'danger'" can-close
|
|
240
257
|
v-on:close="showStoreMessage = false"></lkt-http-info>
|
|
241
|
-
<slot name="item" v-bind:item="item" v-bind:loading="isLoading" v-bind:edit-mode="editMode"
|
|
258
|
+
<slot name="item" v-bind:item="item" v-bind:loading="isLoading" v-bind:edit-mode="editMode"
|
|
259
|
+
v-bind:is-create="isCreate"
|
|
260
|
+
v-bind:can-update="canUpdate"
|
|
261
|
+
v-bind:can-drop="canDrop"></slot>
|
|
242
262
|
</div>
|
|
243
263
|
<lkt-http-info :code="httpStatus" v-else></lkt-http-info>
|
|
244
264
|
</div>
|