fix: edit and rename organization doc
This commit is contained in:
parent
6e13cbf866
commit
8bea5747fe
@ -40,6 +40,7 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import { TextInput, Dialog, call } from 'frappe-ui'
|
import { TextInput, Dialog, call } from 'frappe-ui'
|
||||||
import { ref, defineModel, nextTick, watch } from 'vue'
|
import { ref, defineModel, nextTick, watch } from 'vue'
|
||||||
|
import { useRouter } from 'vue-router'
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
organization: {
|
organization: {
|
||||||
@ -54,38 +55,78 @@ const organizations = defineModel('reloadOrganizations')
|
|||||||
const title = ref(null)
|
const title = ref(null)
|
||||||
const editMode = ref(false)
|
const editMode = ref(false)
|
||||||
let _organization = ref({})
|
let _organization = ref({})
|
||||||
|
const router = useRouter()
|
||||||
|
|
||||||
async function updateOrganization(close) {
|
async function updateOrganization(close) {
|
||||||
if (
|
const old = { ...props.organization }
|
||||||
props.organization.organization_name === _organization.value.name &&
|
const newOrg = { ..._organization.value }
|
||||||
props.organization.website === _organization.value.website
|
|
||||||
)
|
const nameChanged = old.name !== newOrg.name
|
||||||
|
delete old.name
|
||||||
|
delete newOrg.name
|
||||||
|
|
||||||
|
const otherFieldChanged = JSON.stringify(old) !== JSON.stringify(newOrg)
|
||||||
|
const values = newOrg
|
||||||
|
|
||||||
|
if (!nameChanged && !otherFieldChanged) {
|
||||||
|
close()
|
||||||
return
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if (editMode.value) {
|
if (editMode.value) {
|
||||||
let d = await call('frappe.client.set_value', {
|
let name
|
||||||
doctype: 'CRM Organization',
|
if (nameChanged) {
|
||||||
name: _organization.value.name,
|
name = await callRenameDoc()
|
||||||
fieldname: _organization.value,
|
|
||||||
})
|
|
||||||
if (d.name) {
|
|
||||||
organizations.value.reload()
|
|
||||||
}
|
}
|
||||||
|
if (otherFieldChanged) {
|
||||||
|
name = await callSetValue(values)
|
||||||
|
}
|
||||||
|
handleOrganizationUpdate(name)
|
||||||
} else {
|
} else {
|
||||||
let d = await call('frappe.client.insert', {
|
await callInsertDoc()
|
||||||
doc: {
|
|
||||||
doctype: 'CRM Organization',
|
|
||||||
organization_name: _organization.value.name,
|
|
||||||
website: _organization.value.website,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
if (d.name) {
|
|
||||||
organizations.value.reload()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
close()
|
close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function callRenameDoc() {
|
||||||
|
const d = await call('frappe.client.rename_doc', {
|
||||||
|
doctype: 'CRM Organization',
|
||||||
|
old_name: props.organization.name,
|
||||||
|
new_name: _organization.value.name,
|
||||||
|
})
|
||||||
|
return d
|
||||||
|
}
|
||||||
|
|
||||||
|
async function callSetValue(values) {
|
||||||
|
const d = await call('frappe.client.set_value', {
|
||||||
|
doctype: 'CRM Organization',
|
||||||
|
name: _organization.value.name,
|
||||||
|
fieldname: values,
|
||||||
|
})
|
||||||
|
return d.name
|
||||||
|
}
|
||||||
|
|
||||||
|
async function callInsertDoc() {
|
||||||
|
const d = await call('frappe.client.insert', {
|
||||||
|
doc: {
|
||||||
|
doctype: 'CRM Organization',
|
||||||
|
organization_name: _organization.value.name,
|
||||||
|
website: _organization.value.website,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
d.name && handleOrganizationUpdate()
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleOrganizationUpdate(name) {
|
||||||
|
organizations.value.reload()
|
||||||
|
if (name) {
|
||||||
|
router.push({
|
||||||
|
name: 'Organization',
|
||||||
|
params: { organizationId: name },
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
() => show.value,
|
() => show.value,
|
||||||
(value) => {
|
(value) => {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user