diff --git a/src/components/CrudModel.vue b/src/components/CrudModel.vue index 9bb05d4390..c8fa5809ca 100644 --- a/src/components/CrudModel.vue +++ b/src/components/CrudModel.vue @@ -176,8 +176,8 @@ async function remove(data) { .dialog({ component: VnConfirm, componentProps: { - title: t('confirmDeletion'), - message: t('confirmDeletionMessage'), + title: t('globals.confirmDeletion'), + message: t('globals.confirmDeletionMessage'), newData, ids, }, @@ -317,16 +317,3 @@ watch(formUrl, async () => { color="primary" /> - - - { - "en": { - "confirmDeletion": "Confirm deletion", - "confirmDeletionMessage": "Are you sure you want to delete this?" - }, - "es": { - "confirmDeletion": "Confirmar eliminación", - "confirmDeletionMessage": "Seguro que quieres eliminar?" - } - } - diff --git a/src/components/FormModel.vue b/src/components/FormModel.vue index 0c669902f8..c338354384 100644 --- a/src/components/FormModel.vue +++ b/src/components/FormModel.vue @@ -59,9 +59,9 @@ const $props = defineProps({ type: Function, default: null, }, - updateType: { - type: String, - default: 'patch', + saveFn: { + type: Function, + default: null, }, }); @@ -79,8 +79,8 @@ onMounted(async () => { }); // Podemos enviarle al form la estructura de data inicial sin necesidad de fetchearla - if ($props.formInitialData && !$props.autoLoad) { - state.set($props.model, $props.formInitialData); + if ($props.formInitialData || !$props.autoLoad) { + state.set($props.model, $props.formInitialData ?? {}); } else { await fetch(); } @@ -142,19 +142,19 @@ async function save() { try { const body = $props.mapper ? $props.mapper(formData.value) : formData.value; let response; - if ($props.urlCreate) { - response = await axios.post($props.urlCreate, body); - notify('globals.dataCreated', 'positive'); - } else { - response = await axios[$props.updateType]( - $props.urlUpdate || $props.url, + if ($props.saveFn) response = await $props.saveFn(body); + else + response = await axios[$props.urlCreate ? 'post' : 'patch']( + $props.urlCreate || $props.urlUpdate || $props.url, body ); - } + if ($props.urlCreate) notify('globals.dataCreated', 'positive'); + emit('onDataSaved', formData.value, response?.data); originalData.value = JSON.parse(JSON.stringify(formData.value)); hasChanges.value = false; } catch (err) { + console.error(err); notify('errors.create', 'negative'); } isLoading.value = false; diff --git a/src/components/common/VnDms.vue b/src/components/common/VnDms.vue index 1693561523..6cdca22c55 100644 --- a/src/components/common/VnDms.vue +++ b/src/components/common/VnDms.vue @@ -1,25 +1,35 @@