fix: added List & Form option in Form Script

This commit is contained in:
Shariq Ansari 2024-04-10 19:35:52 +05:30
parent fe8bcd7911
commit 5498c88fc8
4 changed files with 53 additions and 9 deletions

View File

@ -240,7 +240,8 @@ def get_list_data(
"views": get_views(doctype), "views": get_views(doctype),
"total_count": len(frappe.get_list(doctype, filters=filters)), "total_count": len(frappe.get_list(doctype, filters=filters)),
"row_count": len(data), "row_count": len(data),
"form_script": get_form_script(doctype) "form_script": get_form_script(doctype),
"list_script": get_form_script(doctype, "List"),
} }

View File

@ -1,8 +1,38 @@
// Copyright (c) 2023, Frappe Technologies Pvt. Ltd. and contributors // Copyright (c) 2023, Frappe Technologies Pvt. Ltd. and contributors
// For license information, please see license.txt // For license information, please see license.txt
// frappe.ui.form.on("CRM Form Script", { frappe.ui.form.on("CRM Form Script", {
// refresh(frm) { 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();
}
},
});

View File

@ -7,6 +7,7 @@
"engine": "InnoDB", "engine": "InnoDB",
"field_order": [ "field_order": [
"dt", "dt",
"view",
"column_break_gboh", "column_break_gboh",
"enabled", "enabled",
"section_break_xeox", "section_break_xeox",
@ -36,16 +37,26 @@
"label": "Enabled" "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", "fieldname": "script",
"fieldtype": "Code", "fieldtype": "Code",
"label": "Script", "label": "Script",
"options": "JS" "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, "index_web_pages_for_search": 1,
"links": [], "links": [],
"modified": "2024-01-19 21:52:46.078626", "modified": "2024-04-10 18:27:17.617602",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "FCRM", "module": "FCRM",
"name": "CRM Form Script", "name": "CRM Form Script",

View File

@ -14,6 +14,7 @@ class CRMFormScript(Document):
if self.dt and self.enabled: if self.dt and self.enabled:
filters = { filters = {
"dt": self.dt, "dt": self.dt,
"view": self.view,
"enabled": 1, "enabled": 1,
} }
if self.name: if self.name:
@ -27,13 +28,14 @@ class CRMFormScript(Document):
frappe.DuplicateEntryError, frappe.DuplicateEntryError,
) )
def get_form_script(dt): def get_form_script(dt, view="Form"):
"""Returns the script for the given doctype""" """Returns the form script for the given doctype"""
FormScript = frappe.qb.DocType("CRM Form Script") FormScript = frappe.qb.DocType("CRM Form Script")
query = ( query = (
frappe.qb.from_(FormScript) frappe.qb.from_(FormScript)
.select("script") .select("script")
.where(FormScript.dt == dt) .where(FormScript.dt == dt)
.where(FormScript.view == view)
.where(FormScript.enabled == 1) .where(FormScript.enabled == 1)
.limit(1) .limit(1)
) )