From a8ee5295b75e0833806401f0f9b8391d5a459e56 Mon Sep 17 00:00:00 2001 From: Shariq Ansari Date: Fri, 6 Jun 2025 16:37:55 +0530 Subject: [PATCH 1/4] fix: trigger onload method if controller is loaded (cherry picked from commit 8db846ad5dc21aa23ff7fbd41e52b7cfe367b179) --- frontend/src/data/document.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/frontend/src/data/document.js b/frontend/src/data/document.js index 8760ccbb..a38e8ed6 100644 --- a/frontend/src/data/document.js +++ b/frontend/src/data/document.js @@ -75,6 +75,8 @@ export function useDocument(doctype, docname) { organizedControllers[controllerKey].push(controller) } controllersCache[doctype][docname || ''] = organizedControllers + + triggerOnload() } function getControllers(row = null) { @@ -93,9 +95,16 @@ export function useDocument(doctype, docname) { return [] } + async function triggerOnload() { + const handler = async function () { + await this.onload?.() + } + await trigger(handler) + } + async function triggerOnRefresh() { const handler = async function () { - await this.refresh() + await this.refresh?.() } await trigger(handler) } @@ -189,6 +198,8 @@ export function useDocument(doctype, docname) { return { document: documentsCache[doctype][docname || ''], assignees, + getControllers, + triggerOnload, triggerOnChange, triggerOnRowAdd, triggerOnRowRemove, From 2e9c5b1d6f1bb703ae8b1c84bfc2c02f8eca4bb2 Mon Sep 17 00:00:00 2001 From: Shariq Ansari Date: Fri, 6 Jun 2025 16:38:39 +0530 Subject: [PATCH 2/4] feat: add custom actions using class based script (cherry picked from commit ca6067912653f621c4d3f1d4fc53c408952a9aa9) --- frontend/src/data/script.js | 38 +++++++++++++++++++++++++++++++++++++ frontend/src/pages/Deal.vue | 4 ++++ frontend/src/pages/Lead.vue | 4 ++++ 3 files changed, 46 insertions(+) diff --git a/frontend/src/data/script.js b/frontend/src/data/script.js index 9532fc11..78c22be6 100644 --- a/frontend/src/data/script.js +++ b/frontend/src/data/script.js @@ -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 diff --git a/frontend/src/pages/Deal.vue b/frontend/src/pages/Deal.vue index d9b29299..67e37d18 100644 --- a/frontend/src/pages/Deal.vue +++ b/frontend/src/pages/Deal.vue @@ -12,6 +12,10 @@ v-if="deal.data._customActions?.length" :actions="deal.data._customActions" /> + + Date: Fri, 6 Jun 2025 17:17:11 +0530 Subject: [PATCH 3/4] feat: add custom statuses using class based script (cherry picked from commit 8942bb7e4804553cd882c51d57c3956cdd579b76) --- frontend/src/data/script.js | 37 +++++++++++++++++++++++++++++++ frontend/src/pages/Deal.vue | 10 ++++++++- frontend/src/pages/Lead.vue | 10 ++++++++- frontend/src/pages/MobileDeal.vue | 8 ++++++- frontend/src/pages/MobileLead.vue | 8 ++++++- 5 files changed, 69 insertions(+), 4 deletions(-) diff --git a/frontend/src/data/script.js b/frontend/src/data/script.js index 78c22be6..b809f744 100644 --- a/frontend/src/data/script.js +++ b/frontend/src/data/script.js @@ -117,6 +117,7 @@ export function getScript(doctype, view = 'Form') { isChildDoctype = false, ) { document.actions = document.actions || [] + document.statuses = document.statuses || [] let instance = new FormClass() @@ -237,6 +238,42 @@ export function getScript(doctype, view = 'Form') { }, }) } + + if ( + !Object.prototype.hasOwnProperty.call(FormClass.prototype, 'statuses') + ) { + Object.defineProperty(FormClass.prototype, 'statuses', { + configurable: true, + enumerable: true, + get() { + if (!this._originalDocumentContext) { + console.warn( + 'CRM Script: _originalDocumentContext not found on instance for statuses getter.', + ) + return [] + } + + return this._originalDocumentContext.statuses + }, + set(newValue) { + if (!this._originalDocumentContext) { + console.warn( + 'CRM Script: _originalDocumentContext not found on instance for statuses setter.', + ) + return + } + if (!Array.isArray(newValue)) { + console.warn( + 'CRM Script: "statuses" property must be an array. Value was not set.', + newValue, + ) + this._originalDocumentContext.statuses = [] + return + } + this._originalDocumentContext.statuses = newValue + }, + }) + } } // utility function to setup a form controller diff --git a/frontend/src/pages/Deal.vue b/frontend/src/pages/Deal.vue index 67e37d18..9265db2e 100644 --- a/frontend/src/pages/Deal.vue +++ b/frontend/src/pages/Deal.vue @@ -22,7 +22,15 @@ doctype="CRM Deal" />