feat: allow multiple client scripts
This commit is contained in:
parent
18108eef65
commit
5fb2bfab4b
3 changed files with 15 additions and 18 deletions
|
|
@ -1,6 +1,7 @@
|
|||
{
|
||||
"actions": [],
|
||||
"allow_import": 1,
|
||||
"autoname": "Prompt",
|
||||
"creation": "2013-01-10 16:34:01",
|
||||
"description": "Adds a custom client script to a DocType",
|
||||
"doctype": "DocType",
|
||||
|
|
@ -52,6 +53,7 @@
|
|||
"default": "Form",
|
||||
"fieldname": "view",
|
||||
"fieldtype": "Select",
|
||||
"in_list_view": 1,
|
||||
"label": "Apply To",
|
||||
"options": "List\nForm",
|
||||
"set_only_once": 1
|
||||
|
|
@ -75,10 +77,11 @@
|
|||
"idx": 1,
|
||||
"index_web_pages_for_search": 1,
|
||||
"links": [],
|
||||
"modified": "2022-02-18 00:43:33.941466",
|
||||
"modified": "2022-04-12 12:48:15.717985",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Custom",
|
||||
"name": "Client Script",
|
||||
"naming_rule": "Set by user",
|
||||
"owner": "Administrator",
|
||||
"permissions": [
|
||||
{
|
||||
|
|
|
|||
|
|
@ -6,20 +6,6 @@ from frappe.model.document import Document
|
|||
|
||||
|
||||
class ClientScript(Document):
|
||||
def autoname(self):
|
||||
self.name = f"{self.dt}-{self.view}"
|
||||
|
||||
def validate(self):
|
||||
if not self.is_new():
|
||||
return
|
||||
|
||||
exists = frappe.db.exists("Client Script", {"dt": self.dt, "view": self.view})
|
||||
if exists:
|
||||
frappe.throw(
|
||||
_("Client Script for {0} {1} already exists").format(frappe.bold(self.dt), self.view),
|
||||
frappe.DuplicateEntryError,
|
||||
)
|
||||
|
||||
def on_update(self):
|
||||
frappe.clear_cache(doctype=self.dt)
|
||||
|
||||
|
|
|
|||
|
|
@ -155,7 +155,7 @@ class FormMeta(Meta):
|
|||
frappe.db.get_all(
|
||||
"Client Script",
|
||||
filters={"dt": self.name, "enabled": 1},
|
||||
fields=["script", "view"],
|
||||
fields=["name", "script", "view"],
|
||||
order_by="creation asc",
|
||||
)
|
||||
or ""
|
||||
|
|
@ -165,10 +165,18 @@ class FormMeta(Meta):
|
|||
form_script = ""
|
||||
for script in client_scripts:
|
||||
if script.view == "List":
|
||||
list_script += script.script
|
||||
list_script += f"""
|
||||
// {script.name}
|
||||
{script.script}
|
||||
|
||||
"""
|
||||
|
||||
if script.view == "Form":
|
||||
form_script += script.script
|
||||
form_script += f"""
|
||||
// {script.name}
|
||||
{script.script}
|
||||
|
||||
"""
|
||||
|
||||
file = scrub(self.name)
|
||||
form_script += f"\n\n//# sourceURL={file}__custom_js"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue