fix: added List & Form option in Form Script
This commit is contained in:
parent
fe8bcd7911
commit
5498c88fc8
@ -240,7 +240,8 @@ def get_list_data(
|
||||
"views": get_views(doctype),
|
||||
"total_count": len(frappe.get_list(doctype, filters=filters)),
|
||||
"row_count": len(data),
|
||||
"form_script": get_form_script(doctype)
|
||||
"form_script": get_form_script(doctype),
|
||||
"list_script": get_form_script(doctype, "List"),
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -1,8 +1,38 @@
|
||||
// Copyright (c) 2023, Frappe Technologies Pvt. Ltd. and contributors
|
||||
// For license information, please see license.txt
|
||||
|
||||
// frappe.ui.form.on("CRM Form Script", {
|
||||
// refresh(frm) {
|
||||
frappe.ui.form.on("CRM Form Script", {
|
||||
refresh(frm) {
|
||||
frm.set_query("dt", {
|
||||
filters: {
|
||||
istable: 0,
|
||||
},
|
||||
});
|
||||
},
|
||||
view(frm) {
|
||||
let has_form_boilerplate = frm.doc.script.includes(
|
||||
"function setupForm("
|
||||
);
|
||||
let has_list_boilerplate = frm.doc.script.includes(
|
||||
"function setupList("
|
||||
);
|
||||
|
||||
// },
|
||||
// });
|
||||
if (frm.doc.view == "Form" && !has_form_boilerplate) {
|
||||
frm.doc.script = `
|
||||
function setupForm({ doc }) {
|
||||
return {
|
||||
actions: [],
|
||||
}
|
||||
}`.trim();
|
||||
}
|
||||
if (frm.doc.view == "List" && !has_list_boilerplate) {
|
||||
frm.doc.script = `
|
||||
function setupList({ docs }) {
|
||||
return {
|
||||
actions: [],
|
||||
bulk_actions: [],
|
||||
}
|
||||
}`.trim();
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
@ -7,6 +7,7 @@
|
||||
"engine": "InnoDB",
|
||||
"field_order": [
|
||||
"dt",
|
||||
"view",
|
||||
"column_break_gboh",
|
||||
"enabled",
|
||||
"section_break_xeox",
|
||||
@ -36,16 +37,26 @@
|
||||
"label": "Enabled"
|
||||
},
|
||||
{
|
||||
"default": "function setupForm({ doc }) {\n return {\n actions: []\n }\n}",
|
||||
"default": "function setupForm({ doc }) {\n return {\n actions: [],\n }\n}",
|
||||
"documentation_url": "https://docs.frappe.io/crm/custom-actions",
|
||||
"fieldname": "script",
|
||||
"fieldtype": "Code",
|
||||
"label": "Script",
|
||||
"options": "JS"
|
||||
},
|
||||
{
|
||||
"default": "Form",
|
||||
"fieldname": "view",
|
||||
"fieldtype": "Select",
|
||||
"in_list_view": 1,
|
||||
"label": "Apply To",
|
||||
"options": "Form\nList",
|
||||
"set_only_once": 1
|
||||
}
|
||||
],
|
||||
"index_web_pages_for_search": 1,
|
||||
"links": [],
|
||||
"modified": "2024-01-19 21:52:46.078626",
|
||||
"modified": "2024-04-10 18:27:17.617602",
|
||||
"modified_by": "Administrator",
|
||||
"module": "FCRM",
|
||||
"name": "CRM Form Script",
|
||||
|
||||
@ -14,6 +14,7 @@ class CRMFormScript(Document):
|
||||
if self.dt and self.enabled:
|
||||
filters = {
|
||||
"dt": self.dt,
|
||||
"view": self.view,
|
||||
"enabled": 1,
|
||||
}
|
||||
if self.name:
|
||||
@ -27,13 +28,14 @@ class CRMFormScript(Document):
|
||||
frappe.DuplicateEntryError,
|
||||
)
|
||||
|
||||
def get_form_script(dt):
|
||||
"""Returns the script for the given doctype"""
|
||||
def get_form_script(dt, view="Form"):
|
||||
"""Returns the form script for the given doctype"""
|
||||
FormScript = frappe.qb.DocType("CRM Form Script")
|
||||
query = (
|
||||
frappe.qb.from_(FormScript)
|
||||
.select("script")
|
||||
.where(FormScript.dt == dt)
|
||||
.where(FormScript.view == view)
|
||||
.where(FormScript.enabled == 1)
|
||||
.limit(1)
|
||||
)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user