fix: use document to load doc data in DataFields
(cherry picked from commit e65899e38406452cef0c7ec879038037facda2ed)
This commit is contained in:
parent
c8d21ef8f0
commit
1c0e17109e
@ -5,7 +5,7 @@
|
|||||||
<div class="flex h-8 items-center text-xl font-semibold text-ink-gray-8">
|
<div class="flex h-8 items-center text-xl font-semibold text-ink-gray-8">
|
||||||
{{ __('Data') }}
|
{{ __('Data') }}
|
||||||
<Badge
|
<Badge
|
||||||
v-if="data.isDirty"
|
v-if="document.isDirty"
|
||||||
class="ml-3"
|
class="ml-3"
|
||||||
:label="'Not Saved'"
|
:label="'Not Saved'"
|
||||||
theme="orange"
|
theme="orange"
|
||||||
@ -20,15 +20,15 @@
|
|||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
label="Save"
|
label="Save"
|
||||||
:disabled="!data.isDirty"
|
:disabled="!document.isDirty"
|
||||||
variant="solid"
|
variant="solid"
|
||||||
:loading="data.save.loading"
|
:loading="document.save.loading"
|
||||||
@click="saveChanges"
|
@click="saveChanges"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
v-if="data.get.loading"
|
v-if="document.get.loading"
|
||||||
class="flex flex-1 flex-col items-center justify-center gap-3 text-xl font-medium text-gray-500"
|
class="flex flex-1 flex-col items-center justify-center gap-3 text-xl font-medium text-gray-500"
|
||||||
>
|
>
|
||||||
<LoadingIndicator class="h-6 w-6" />
|
<LoadingIndicator class="h-6 w-6" />
|
||||||
@ -38,7 +38,7 @@
|
|||||||
<FieldLayout
|
<FieldLayout
|
||||||
v-if="tabs.data"
|
v-if="tabs.data"
|
||||||
:tabs="tabs.data"
|
:tabs="tabs.data"
|
||||||
:data="data.doc"
|
:data="document.doc"
|
||||||
:doctype="doctype"
|
:doctype="doctype"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@ -49,7 +49,7 @@
|
|||||||
@reload="
|
@reload="
|
||||||
() => {
|
() => {
|
||||||
tabs.reload()
|
tabs.reload()
|
||||||
data.reload()
|
document.reload()
|
||||||
}
|
}
|
||||||
"
|
"
|
||||||
/>
|
/>
|
||||||
@ -59,10 +59,10 @@
|
|||||||
import EditIcon from '@/components/Icons/EditIcon.vue'
|
import EditIcon from '@/components/Icons/EditIcon.vue'
|
||||||
import DataFieldsModal from '@/components/Modals/DataFieldsModal.vue'
|
import DataFieldsModal from '@/components/Modals/DataFieldsModal.vue'
|
||||||
import FieldLayout from '@/components/FieldLayout/FieldLayout.vue'
|
import FieldLayout from '@/components/FieldLayout/FieldLayout.vue'
|
||||||
import { Badge, createResource, createDocumentResource } from 'frappe-ui'
|
import { Badge, createResource } from 'frappe-ui'
|
||||||
import LoadingIndicator from '@/components/Icons/LoadingIndicator.vue'
|
import LoadingIndicator from '@/components/Icons/LoadingIndicator.vue'
|
||||||
import { createToast } from '@/utils'
|
|
||||||
import { usersStore } from '@/stores/users'
|
import { usersStore } from '@/stores/users'
|
||||||
|
import { useDocument } from '@/data/document'
|
||||||
import { isMobileView } from '@/composables/settings'
|
import { isMobileView } from '@/composables/settings'
|
||||||
import { ref, watch } from 'vue'
|
import { ref, watch } from 'vue'
|
||||||
|
|
||||||
@ -76,33 +76,11 @@ const props = defineProps({
|
|||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
const { isManager } = usersStore()
|
const { isManager } = usersStore()
|
||||||
|
|
||||||
const showDataFieldsModal = ref(false)
|
const showDataFieldsModal = ref(false)
|
||||||
|
|
||||||
const data = createDocumentResource({
|
const { document } = useDocument(props.doctype, props.docname)
|
||||||
doctype: props.doctype,
|
|
||||||
name: props.docname,
|
|
||||||
setValue: {
|
|
||||||
onSuccess: () => {
|
|
||||||
data.reload()
|
|
||||||
createToast({
|
|
||||||
title: 'Data Updated',
|
|
||||||
icon: 'check',
|
|
||||||
iconClasses: 'text-ink-green-3',
|
|
||||||
})
|
|
||||||
},
|
|
||||||
onError: (err) => {
|
|
||||||
createToast({
|
|
||||||
title: 'Error',
|
|
||||||
text: err.messages[0],
|
|
||||||
icon: 'x',
|
|
||||||
iconClasses: 'text-red-600',
|
|
||||||
})
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
const tabs = createResource({
|
const tabs = createResource({
|
||||||
url: 'crm.fcrm.doctype.crm_fields_layout.crm_fields_layout.get_fields_layout',
|
url: 'crm.fcrm.doctype.crm_fields_layout.crm_fields_layout.get_fields_layout',
|
||||||
@ -112,19 +90,19 @@ const tabs = createResource({
|
|||||||
})
|
})
|
||||||
|
|
||||||
function saveChanges() {
|
function saveChanges() {
|
||||||
data.save.submit()
|
document.save.submit()
|
||||||
}
|
}
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
() => data.doc,
|
() => document.doc,
|
||||||
(newValue, oldValue) => {
|
(newValue, oldValue) => {
|
||||||
if (!oldValue) return
|
if (!oldValue) return
|
||||||
if (newValue && oldValue) {
|
if (newValue && oldValue) {
|
||||||
const isDirty =
|
const isDirty =
|
||||||
JSON.stringify(newValue) !== JSON.stringify(data.originalDoc)
|
JSON.stringify(newValue) !== JSON.stringify(document.originalDoc)
|
||||||
data.isDirty = isDirty
|
document.isDirty = isDirty
|
||||||
if (isDirty) {
|
if (isDirty) {
|
||||||
data.save.loading = false
|
document.save.loading = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user