@@ -84,14 +84,14 @@ q-splitter(
8484 q-btn( color ="primary" , icon ="mdi-chevron-left" @click ="cancel" tooltip ="Retour" )
8585 q-tooltip.text-body2 Retour
8686 q-separator.q-mx-sm ( vertical )
87- slot( name ="right-panel-actions-content" v-if ="defaultRightPanelButton" : target= "target" )
87+ slot( name ="right-panel-actions-content" v-if ="defaultRightPanelButton" : target= "target" : isNew = "isNew" : crud = "crud" )
8888 q-btn( color ="positive" icon ='mdi-content-save-plus' @click ="create(target)" v-show ="isNew" v-if ="crud.create" )
8989 q-tooltip.text-body2 Créer
9090 q-btn( color ="positive" icon ='mdi-content-save' @click ="update(target)" v-show ="!isNew" v-if ="crud.update" )
9191 q-tooltip.text-body2 Enregistrer
9292 q-btn( color ="negative" icon ='mdi-delete' @click ="remove(target)" v-show ="!isNew" v-if ="crud.delete" )
9393 q-tooltip.text-body2 Supprimer
94- slot( name ="right-panel-actions-content-after" : target= "target" )
94+ slot( name ="right-panel-actions-content-after" : target= "target" : isNew = "isNew" : crud = "crud" )
9595 q-card-section.q-pa-none.fit.flex ( style ='flex-flow: column; overflow: hidden;' )
9696 slot( name ="right-panel-content" : payload= "{ target }" )
9797 slot( name ="right-panel-content-before" )
@@ -192,6 +192,7 @@ const props = defineProps({
192192 update: <T >(r : T ) => Promise <T >
193193 delete: <T >(r : T ) => Promise <T >
194194 cancel: () => Promise <void >
195+ add: <T >() => Promise <T >
195196 onMounted: <T = object >() => Promise <T | null >
196197 }>,
197198 default: {
@@ -209,6 +210,7 @@ const props = defineProps({
209210 },
210211
211212 cancel : async () => { },
213+ add : async () => { return {} },
212214 onMounted : async () => { },
213215 },
214216 },
@@ -257,7 +259,7 @@ const { debug } = useDebug()
257259const selected = ref ([])
258260const tab = ref (' ' )
259261const targetId = ref <null | string >(route .query ?.read ? ` ${route .query ?.read } ` : null )
260- const target = ref <null | object >(null )
262+ const target = ref <object >({} )
261263const daysjs = useDayjs ()
262264
263265watch (target , (t ) => {
@@ -283,36 +285,38 @@ async function refresh() {
283285async function cancel() {
284286 await props .actions .cancel ()
285287 targetId .value = null
286- target .value = null
288+ target .value = {}
287289 selected .value = []
288290 await router .push ({ query: { ... route .query , read: null } })
289291}
290292async function read(row ) {
291293 targetId .value = row ?._id
292294 const response = await props .actions .read (row )
293- target .value = response
295+ target .value = { ... response }
294296 emit (' read' , response )
295297}
296298
297299async function add() {
298300 const read = NEW_ID
299301 targetId .value = read
300- target .value = {}
301- router .push ({ query: { ... route .query , read } })
302+ target .value = await props . actions . add () || {}
303+ await router .push ({ query: { ... route .query , read } })
302304}
303305
304306async function create(row ) {
305307 console .log (' create' , row )
306308 const response = await props .actions .create (row )
309+ console .log (' response' , response )
307310 // target.value = response
308311 // targetId.value = response?._id
309312 emit (' create' , response )
313+ if (response ) cancel ()
310314}
311315
312316async function update(row ) {
313317 targetId .value = row ?._id
314318 const response = await props .actions .update (row )
315- target .value = response
319+ target .value = { ... response }
316320 emit (' update' , response )
317321}
318322
@@ -357,7 +361,7 @@ onMounted(async () => {
357361 return
358362 }
359363 const newTarget = await props .actions .onMounted ()
360- console .log (' newTarget' , newTarget )
364+ // console.log('newTarget', newTarget)
361365 if (newTarget ) {
362366 target .value = { ... newTarget }
363367 targetId .value = (newTarget as any )?._id
0 commit comments