feat: add custom actions using class based script
This commit is contained in:
parent
8db846ad5d
commit
ca60679126
@ -116,8 +116,12 @@ export function getScript(doctype, view = 'Form') {
|
||||
parentInstance = null,
|
||||
isChildDoctype = false,
|
||||
) {
|
||||
document.actions = document.actions || []
|
||||
|
||||
let instance = new FormClass()
|
||||
|
||||
// Store the original document context to be used by properties like 'actions'
|
||||
instance._originalDocumentContext = document
|
||||
instance._isChildDoctype = isChildDoctype
|
||||
|
||||
for (const key in document) {
|
||||
@ -199,6 +203,40 @@ export function getScript(doctype, view = 'Form') {
|
||||
return createDocProxy(row, this)
|
||||
}
|
||||
}
|
||||
|
||||
if (!Object.prototype.hasOwnProperty.call(FormClass.prototype, 'actions')) {
|
||||
Object.defineProperty(FormClass.prototype, 'actions', {
|
||||
configurable: true,
|
||||
enumerable: true,
|
||||
get() {
|
||||
if (!this._originalDocumentContext) {
|
||||
console.warn(
|
||||
'CRM Script: _originalDocumentContext not found on instance for actions getter.',
|
||||
)
|
||||
return []
|
||||
}
|
||||
|
||||
return this._originalDocumentContext.actions
|
||||
},
|
||||
set(newValue) {
|
||||
if (!this._originalDocumentContext) {
|
||||
console.warn(
|
||||
'CRM Script: _originalDocumentContext not found on instance for actions setter.',
|
||||
)
|
||||
return
|
||||
}
|
||||
if (!Array.isArray(newValue)) {
|
||||
console.warn(
|
||||
'CRM Script: "actions" property must be an array. Value was not set.',
|
||||
newValue,
|
||||
)
|
||||
this._originalDocumentContext.actions = []
|
||||
return
|
||||
}
|
||||
this._originalDocumentContext.actions = newValue
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// utility function to setup a form controller
|
||||
|
||||
@ -12,6 +12,10 @@
|
||||
v-if="deal.data._customActions?.length"
|
||||
:actions="deal.data._customActions"
|
||||
/>
|
||||
<CustomActions
|
||||
v-if="document.actions?.length"
|
||||
:actions="document.actions"
|
||||
/>
|
||||
<AssignTo
|
||||
v-model="assignees.data"
|
||||
:data="document.doc"
|
||||
|
||||
@ -12,6 +12,10 @@
|
||||
v-if="lead.data._customActions?.length"
|
||||
:actions="lead.data._customActions"
|
||||
/>
|
||||
<CustomActions
|
||||
v-if="document.actions?.length"
|
||||
:actions="document.actions"
|
||||
/>
|
||||
<AssignTo
|
||||
v-model="assignees.data"
|
||||
:data="document.doc"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user