From 52fcbdb68936a1f7af0a14024bcb14616325e65d Mon Sep 17 00:00:00 2001 From: alexm Date: Tue, 19 Sep 2023 10:21:24 +0200 Subject: [PATCH] refs #5673 feat(crudModel): add saveFn prop --- src/components/CrudModel.vue | 13 ++++++---- src/pages/Worker/Card/WorkerSummary.vue | 3 +-- .../components/common/CrudModel.spec.js | 24 +------------------ 3 files changed, 10 insertions(+), 30 deletions(-) diff --git a/src/components/CrudModel.vue b/src/components/CrudModel.vue index e724bc0c5..7a22d8373 100644 --- a/src/components/CrudModel.vue +++ b/src/components/CrudModel.vue @@ -53,6 +53,10 @@ const $props = defineProps({ type: Object, default: null, }, + saveFn: { + type: Function, + default: null, + }, }); const isLoading = ref(false); @@ -83,6 +87,7 @@ onUnmounted(() => { function tMobile(...args) { if (!quasar.platform.is.mobile) return t(...args); } + async function fetch(data) { if (data && Array.isArray(data)) { let $index = 0; @@ -128,17 +133,18 @@ async function onSubmit() { } async function saveChanges(data) { + if ($props.saveFn) return $props.saveFn(data, getChanges); const changes = data || getChanges(); try { await axios.post($props.saveUrl || $props.url + '/crud', changes); } catch (e) { return (isLoading.value = false); } - originalData.value = JSON.parse(JSON.stringify(formData.value)); + if (changes.creates?.length) await vnPaginateRef.value.fetch(); + hasChanges.value = false; isLoading.value = false; - if (changes.creates?.length) await vnPaginateRef.value.fetch(); } async function insert() { @@ -249,12 +255,9 @@ watch(formUrl, async () => {