feat: Rename "Custom Script" to "Client Script"

* Remove postfix "-Client" from ClientScript.autoname
This commit is contained in:
Gavin D'souza 2021-02-04 14:06:09 +05:30
parent 399311a699
commit 79cb3f0596
17 changed files with 52 additions and 51 deletions

View file

@ -555,7 +555,7 @@
},
{
"group": "Customization",
"link_doctype": "Custom Script",
"link_doctype": "Client Script",
"link_fieldname": "dt"
},
{

View file

@ -11,6 +11,7 @@
"hide_custom": 0,
"icon": "tool",
"idx": 0,
"is_default": 0,
"is_standard": 1,
"label": "Build",
"links": [
@ -163,8 +164,8 @@
{
"hidden": 0,
"is_query_report": 0,
"label": "Custom Script",
"link_to": "Custom Script",
"label": "Client Script",
"link_to": "Client Script",
"link_type": "DocType",
"onboard": 0,
"only_for": "",
@ -181,7 +182,7 @@
"type": "Link"
}
],
"modified": "2021-01-02 14:03:15.029699",
"modified": "2021-02-04 13:48:48.493146",
"modified_by": "Administrator",
"module": "Core",
"name": "Build",

View file

@ -1,7 +1,7 @@
// Copyright (c) 2016, Frappe Technologies and contributors
// For license information, please see license.txt
frappe.ui.form.on('Custom Script', {
frappe.ui.form.on('Client Script', {
refresh(frm) {
if (frm.doc.dt && frm.doc.script) {
frm.add_custom_button(__('Go to {0}', [frm.doc.dt]),

View file

@ -2,7 +2,7 @@
"actions": [],
"allow_import": 1,
"creation": "2013-01-10 16:34:01",
"description": "Adds a client custom script to a DocType",
"description": "Adds a custom client script to a DocType",
"doctype": "DocType",
"document_type": "Document",
"engine": "InnoDB",
@ -22,9 +22,7 @@
"oldfieldname": "dt",
"oldfieldtype": "Link",
"options": "DocType",
"reqd": 1,
"show_days": 1,
"show_seconds": 1
"reqd": 1
},
{
"fieldname": "script",
@ -32,35 +30,29 @@
"label": "Script",
"oldfieldname": "script",
"oldfieldtype": "Code",
"options": "JS",
"show_days": 1,
"show_seconds": 1
"options": "JS"
},
{
"fieldname": "sample",
"fieldtype": "HTML",
"label": "Sample",
"options": "<h3>Custom Script Help</h3>\n<p>Custom Scripts are executed only on the client-side (i.e. in Forms). Here are some examples to get you started</p>\n<pre><code>\n\n// fetch local_tax_no on selection of customer \n// cur_frm.add_fetch(link_field, source_fieldname, target_fieldname); \ncur_frm.add_fetch('customer', 'local_tax_no', 'local_tax_no');\n\n// additional validation on dates \nfrappe.ui.form.on('Task', 'validate', function(frm) {\n if (frm.doc.from_date &lt; get_today()) {\n msgprint('You can not select past date in From Date');\n validated = false;\n } \n});\n\n// make a field read-only after saving \nfrappe.ui.form.on('Task', {\n refresh: function(frm) {\n // use the __islocal value of doc, to check if the doc is saved or not\n frm.set_df_property('myfield', 'read_only', frm.doc.__islocal ? 0 : 1);\n } \n});\n\n// additional permission check\nfrappe.ui.form.on('Task', {\n validate: function(frm) {\n if(user=='user1@example.com' &amp;&amp; frm.doc.purpose!='Material Receipt') {\n msgprint('You are only allowed Material Receipt');\n validated = false;\n }\n } \n});\n\n// calculate sales incentive\nfrappe.ui.form.on('Sales Invoice', {\n validate: function(frm) {\n // calculate incentives for each person on the deal\n total_incentive = 0\n $.each(frm.doc.sales_team, function(i, d) {\n // calculate incentive\n var incentive_percent = 2;\n if(frm.doc.base_grand_total &gt; 400) incentive_percent = 4;\n // actual incentive\n d.incentives = flt(frm.doc.base_grand_total) * incentive_percent / 100;\n total_incentive += flt(d.incentives)\n });\n frm.doc.total_incentive = total_incentive;\n } \n})\n\n</code></pre>",
"show_days": 1,
"show_seconds": 1
"options": "<h3>Client Script Help</h3>\n<p>Client Scripts are executed only on the client-side (i.e. in Forms). Here are some examples to get you started</p>\n<pre><code>\n\n// fetch local_tax_no on selection of customer \n// cur_frm.add_fetch(link_field, source_fieldname, target_fieldname); \ncur_frm.add_fetch('customer', 'local_tax_no', 'local_tax_no');\n\n// additional validation on dates \nfrappe.ui.form.on('Task', 'validate', function(frm) {\n if (frm.doc.from_date &lt; get_today()) {\n msgprint('You can not select past date in From Date');\n validated = false;\n } \n});\n\n// make a field read-only after saving \nfrappe.ui.form.on('Task', {\n refresh: function(frm) {\n // use the __islocal value of doc, to check if the doc is saved or not\n frm.set_df_property('myfield', 'read_only', frm.doc.__islocal ? 0 : 1);\n } \n});\n\n// additional permission check\nfrappe.ui.form.on('Task', {\n validate: function(frm) {\n if(user=='user1@example.com' &amp;&amp; frm.doc.purpose!='Material Receipt') {\n msgprint('You are only allowed Material Receipt');\n validated = false;\n }\n } \n});\n\n// calculate sales incentive\nfrappe.ui.form.on('Sales Invoice', {\n validate: function(frm) {\n // calculate incentives for each person on the deal\n total_incentive = 0\n $.each(frm.doc.sales_team, function(i, d) {\n // calculate incentive\n var incentive_percent = 2;\n if(frm.doc.base_grand_total &gt; 400) incentive_percent = 4;\n // actual incentive\n d.incentives = flt(frm.doc.base_grand_total) * incentive_percent / 100;\n total_incentive += flt(d.incentives)\n });\n frm.doc.total_incentive = total_incentive;\n } \n})\n\n</code></pre>"
},
{
"default": "0",
"fieldname": "enabled",
"fieldtype": "Check",
"label": "Enabled",
"show_days": 1,
"show_seconds": 1
"label": "Enabled"
}
],
"icon": "fa fa-glass",
"idx": 1,
"index_web_pages_for_search": 1,
"links": [],
"modified": "2020-08-24 21:56:07.719579",
"modified": "2021-02-04 13:57:56.509437",
"modified_by": "Administrator",
"module": "Custom",
"name": "Custom Script",
"name": "Client Script",
"owner": "Administrator",
"permissions": [
{
@ -86,6 +78,7 @@
"write": 1
}
],
"sort_field": "modified",
"sort_order": "ASC",
"track_changes": 1
}

View file

@ -5,9 +5,9 @@ import frappe
from frappe.model.document import Document
class CustomScript(Document):
class ClientScript(Document):
def autoname(self):
self.name = self.dt + "-Client"
self.name = self.dt
def on_update(self):
frappe.clear_cache(doctype=self.dt)

View file

@ -6,7 +6,7 @@ from __future__ import unicode_literals
import frappe
import unittest
# test_records = frappe.get_test_records('Custom Script')
# test_records = frappe.get_test_records('Client Script')
class TestCustomScript(unittest.TestCase):
class TestClientScript(unittest.TestCase):
pass

View file

@ -10,6 +10,7 @@
"hide_custom": 0,
"icon": "customization",
"idx": 0,
"is_default": 0,
"is_standard": 1,
"label": "Customization",
"links": [
@ -81,8 +82,8 @@
"dependencies": "",
"hidden": 0,
"is_query_report": 0,
"label": "Custom Script",
"link_to": "Custom Script",
"label": "Client Script",
"link_to": "Client Script",
"link_type": "DocType",
"onboard": 0,
"type": "Link"
@ -115,7 +116,7 @@
"type": "Link"
}
],
"modified": "2020-12-01 13:38:39.843773",
"modified": "2021-02-04 13:50:35.750463",
"modified_by": "Administrator",
"module": "Custom",
"name": "Customization",
@ -134,8 +135,14 @@
"type": "DocType"
},
{
"label": "Custom Script",
"link_to": "Custom Script",
"label": "Client Script",
"link_to": "Client Script",
"type": "DocType"
},
{
"doc_view": "",
"label": "Server Script",
"link_to": "Server Script",
"type": "DocType"
}
]

View file

@ -130,7 +130,7 @@ class FormMeta(Meta):
def add_custom_script(self):
"""embed all require files"""
# custom script
custom = frappe.db.get_value("Custom Script", {"dt": self.name, "enabled": 1}, "script") or ""
custom = frappe.db.get_value("Client Script", {"dt": self.name, "enabled": 1}, "script") or ""
self.set("__custom_js", custom)

View file

@ -47,7 +47,7 @@ def validate_link():
except Exception as e:
error_message = str(e).split("Unknown column '")
fieldname = None if len(error_message)<=1 else error_message[1].split("'")[0]
frappe.msgprint(_("Wrong fieldname <b>{0}</b> in add_fetch configuration of custom script").format(fieldname))
frappe.msgprint(_("Wrong fieldname <b>{0}</b> in add_fetch configuration of custom client script").format(fieldname))
frappe.errprint(frappe.get_traceback())
if fetch_value:

View file

@ -118,7 +118,7 @@ core_doctypes_list = (
'Customize Form Field',
'Property Setter',
'Custom Field',
'Custom Script'
'Client Script'
)
log_types = (

View file

@ -68,7 +68,7 @@ def delete_doc(doctype=None, name=None, force=0, ignore_doctypes=None, for_reloa
check_permission_and_not_submitted(doc)
frappe.db.sql("delete from `tabCustom Field` where dt = %s", name)
frappe.db.sql("delete from `tabCustom Script` where dt = %s", name)
frappe.db.sql("delete from `tabClient Script` where dt = %s", name)
frappe.db.sql("delete from `tabProperty Setter` where doc_type = %s", name)
frappe.db.sql("delete from `tabReport` where ref_doctype=%s", name)
frappe.db.sql("delete from `tabCustom DocPerm` where parent=%s", name)

View file

@ -176,7 +176,7 @@ frappe.ui.form.ScriptManager = Class.extend({
eval(doctype.__custom_js);
} catch(e) {
frappe.msgprint({
title: __('Error in Custom Script'),
title: __('Error in Client Script'),
indicator: 'orange',
message: '<pre class="small"><code>' + e.stack + '</code></pre>'
});

View file

@ -15,7 +15,7 @@ $.extend(frappe.model, {
core_doctypes_list: ['DocType', 'DocField', 'DocPerm', 'User', 'Role', 'Has Role',
'Page', 'Module Def', 'Print Format', 'Report', 'Customize Form',
'Customize Form Field', 'Property Setter', 'Custom Field', 'Custom Script'],
'Customize Form Field', 'Property Setter', 'Custom Field', 'Client Script'],
std_fields: [
{fieldname:'name', fieldtype:'Link', label:__('ID')},

View file

@ -12,9 +12,9 @@ class TestDataImportFixtures(unittest.TestCase):
def setUp(self):
pass
#start test for Custom Script
#start test for Client Script
def test_Custom_Script_fixture_simple(self):
fixture = "Custom Script"
fixture = "Client Script"
path = frappe.scrub(fixture) + "_original_style.csv"
export_csv(fixture, path)
@ -22,7 +22,7 @@ class TestDataImportFixtures(unittest.TestCase):
os.remove(path)
def test_Custom_Script_fixture_simple_name_equal_default(self):
fixture = ["Custom Script", {"name":["Item-Client"]}]
fixture = ["Client Script", {"name":["Item"]}]
path = frappe.scrub(fixture[0]) + "_simple_name_equal_default.csv"
export_csv(fixture, path)
@ -30,7 +30,7 @@ class TestDataImportFixtures(unittest.TestCase):
os.remove(path)
def test_Custom_Script_fixture_simple_name_equal(self):
fixture = ["Custom Script", {"name":["Item-Client"],"op":"="}]
fixture = ["Client Script", {"name":["Item"],"op":"="}]
path = frappe.scrub(fixture[0]) + "_simple_name_equal.csv"
export_csv(fixture, path)
@ -38,7 +38,7 @@ class TestDataImportFixtures(unittest.TestCase):
os.remove(path)
def test_Custom_Script_fixture_simple_name_not_equal(self):
fixture = ["Custom Script", {"name":["Item-Client"],"op":"!="}]
fixture = ["Client Script", {"name":["Item"],"op":"!="}]
path = frappe.scrub(fixture[0]) + "_simple_name_not_equal.csv"
export_csv(fixture, path)
@ -47,7 +47,7 @@ class TestDataImportFixtures(unittest.TestCase):
#without [] around the name...
def test_Custom_Script_fixture_simple_name_at_least_equal(self):
fixture = ["Custom Script", {"name":"Item-Cli"}]
fixture = ["Client Script", {"name":"Item-Cli"}]
path = frappe.scrub(fixture[0]) + "_simple_name_at_least_equal.csv"
export_csv(fixture, path)
@ -55,7 +55,7 @@ class TestDataImportFixtures(unittest.TestCase):
os.remove(path)
def test_Custom_Script_fixture_multi_name_equal(self):
fixture = ["Custom Script", {"name":["Item-Client", "Customer-Client"],"op":"="}]
fixture = ["Client Script", {"name":["Item", "Customer"],"op":"="}]
path = frappe.scrub(fixture[0]) + "_multi_name_equal.csv"
export_csv(fixture, path)
@ -63,7 +63,7 @@ class TestDataImportFixtures(unittest.TestCase):
os.remove(path)
def test_Custom_Script_fixture_multi_name_not_equal(self):
fixture = ["Custom Script", {"name":["Item-Client", "Customer-Client"],"op":"!="}]
fixture = ["Client Script", {"name":["Item", "Customer"],"op":"!="}]
path = frappe.scrub(fixture[0]) + "_multi_name_not_equal.csv"
export_csv(fixture, path)
@ -71,7 +71,7 @@ class TestDataImportFixtures(unittest.TestCase):
os.remove(path)
def test_Custom_Script_fixture_empty_object(self):
fixture = ["Custom Script", {}]
fixture = ["Client Script", {}]
path = frappe.scrub(fixture[0]) + "_empty_object_should_be_all.csv"
export_csv(fixture, path)
@ -79,16 +79,16 @@ class TestDataImportFixtures(unittest.TestCase):
os.remove(path)
def test_Custom_Script_fixture_just_list(self):
fixture = ["Custom Script"]
fixture = ["Client Script"]
path = frappe.scrub(fixture[0]) + "_just_list_should_be_all.csv"
export_csv(fixture, path)
self.assertTrue(True)
os.remove(path)
# Custom Script regular expression
# Client Script regular expression
def test_Custom_Script_fixture_rex_no_flags(self):
fixture = ["Custom Script", {"name":r"^[i|A]"}]
fixture = ["Client Script", {"name":r"^[i|A]"}]
path = frappe.scrub(fixture[0]) + "_rex_no_flags.csv"
export_csv(fixture, path)
@ -96,7 +96,7 @@ class TestDataImportFixtures(unittest.TestCase):
os.remove(path)
def test_Custom_Script_fixture_rex_with_flags(self):
fixture = ["Custom Script", {"name":r"^[i|A]", "flags":"L,M"}]
fixture = ["Client Script", {"name":r"^[i|A]", "flags":"L,M"}]
path = frappe.scrub(fixture[0]) + "_rex_with_flags.csv"
export_csv(fixture, path)

View file

@ -38,13 +38,13 @@ def import_custom_scripts(app):
"custom_scripts") + os.path.sep + fname) as f:
doctype = fname.rsplit(".", 1)[0]
script = f.read()
if frappe.db.exists("Custom Script", {"dt": doctype}):
custom_script = frappe.get_doc("Custom Script", {"dt": doctype})
if frappe.db.exists("Client Script", {"dt": doctype}):
custom_script = frappe.get_doc("Client Script", {"dt": doctype})
custom_script.script = script
custom_script.save()
else:
frappe.get_doc({
"doctype":"Custom Script",
"doctype":"Client Script",
"dt": doctype,
"script": script
}).insert()