fix: disabel save button if not dirty, reset to old items if cancel
This commit is contained in:
parent
97724c776b
commit
2a38d0fb5f
@ -17,7 +17,7 @@
|
|||||||
<Button
|
<Button
|
||||||
v-if="!editing && (isManager() || isAdmin())"
|
v-if="!editing && (isManager() || isAdmin())"
|
||||||
:label="__('Edit')"
|
:label="__('Edit')"
|
||||||
@click="editing = true"
|
@click="enableEditing"
|
||||||
>
|
>
|
||||||
<template #prefix>
|
<template #prefix>
|
||||||
<LucidePenLine class="size-4" />
|
<LucidePenLine class="size-4" />
|
||||||
@ -34,6 +34,7 @@
|
|||||||
v-if="editing"
|
v-if="editing"
|
||||||
variant="solid"
|
variant="solid"
|
||||||
:label="__('Save')"
|
:label="__('Save')"
|
||||||
|
:disabled="!dirty"
|
||||||
:loading="saveDashboard.loading"
|
:loading="saveDashboard.loading"
|
||||||
@click="save"
|
@click="save"
|
||||||
/>
|
/>
|
||||||
@ -244,13 +245,25 @@ const dashboardItems = createResource({
|
|||||||
auto: true,
|
auto: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const dirty = computed(() => {
|
||||||
|
if (!editing.value) return false
|
||||||
|
return JSON.stringify(dashboardItems.data) !== JSON.stringify(oldItems.value)
|
||||||
|
})
|
||||||
|
|
||||||
|
const oldItems = ref([])
|
||||||
|
|
||||||
provide('fromDate', fromDate)
|
provide('fromDate', fromDate)
|
||||||
provide('toDate', toDate)
|
provide('toDate', toDate)
|
||||||
provide('filters', filters)
|
provide('filters', filters)
|
||||||
|
|
||||||
|
function enableEditing() {
|
||||||
|
editing.value = true
|
||||||
|
oldItems.value = JSON.parse(JSON.stringify(dashboardItems.data))
|
||||||
|
}
|
||||||
|
|
||||||
function cancel() {
|
function cancel() {
|
||||||
editing.value = false
|
editing.value = false
|
||||||
dashboardItems.reload()
|
dashboardItems.data = JSON.parse(JSON.stringify(oldItems.value))
|
||||||
}
|
}
|
||||||
|
|
||||||
const saveDashboard = createResource({
|
const saveDashboard = createResource({
|
||||||
@ -264,9 +277,11 @@ const saveDashboard = createResource({
|
|||||||
|
|
||||||
function save() {
|
function save() {
|
||||||
const dashboardItemsCopy = JSON.parse(JSON.stringify(dashboardItems.data))
|
const dashboardItemsCopy = JSON.parse(JSON.stringify(dashboardItems.data))
|
||||||
|
|
||||||
dashboardItemsCopy.forEach((item: any) => {
|
dashboardItemsCopy.forEach((item: any) => {
|
||||||
delete item.data
|
delete item.data
|
||||||
})
|
})
|
||||||
|
|
||||||
saveDashboard.submit({
|
saveDashboard.submit({
|
||||||
doctype: 'CRM Dashboard',
|
doctype: 'CRM Dashboard',
|
||||||
name: 'Manager Dashboard',
|
name: 'Manager Dashboard',
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user