added help in custom script

This commit is contained in:
Rushabh Mehta 2014-06-19 16:30:21 +05:30
parent 6083999f8a
commit 833913e9e0

View file

@ -1,6 +1,6 @@
{
"autoname": "CustomScript.####",
"creation": "2013-01-10 16:34:01.000000",
"creation": "2013-01-10 16:34:01",
"description": "Adds a custom script (client or server) to a DocType",
"docstatus": 0,
"doctype": "DocType",
@ -8,6 +8,7 @@
{
"fieldname": "dt",
"fieldtype": "Link",
"in_list_view": 1,
"label": "DocType",
"oldfieldname": "dt",
"oldfieldtype": "Link",
@ -19,6 +20,7 @@
"fieldname": "script_type",
"fieldtype": "Select",
"hidden": 1,
"in_list_view": 1,
"label": "Script Type",
"oldfieldname": "script_type",
"oldfieldtype": "Select",
@ -29,16 +31,24 @@
{
"fieldname": "script",
"fieldtype": "Code",
"in_list_view": 1,
"label": "Script",
"oldfieldname": "script",
"oldfieldtype": "Code",
"options": "Script",
"permlevel": 0
},
{
"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// additional validation on dates\ncur_frm.cscript.custom_validate = function(doc) {\n if (doc.from_date < 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\ncur_frm.cscript.custom_refresh = function(doc) {\n // use the __islocal value of doc, to check if the doc is saved or not\n cur_frm.set_df_property(\"myfield\", \"read_only\", doc.__islocal ? 0 : 1);\n}\n\n// addtional permission checking\ncur_frm.cscript.custom_validate = function(doc) {\n if(user==\"user1@example.com\" && doc.purpose!=\"Material Receipt\") {\n msgprint(\"You are only allowed Material Receipt\");\n validated = false;\n }\n}\n\n// calculate sales incentive\ncur_frm.cscript.custom_validate = function(doc) {\n // calculate incentives for each person on the deal\n total_incentive = 0\n $.each(wn.model.get(\"Sales Team\", {parent:doc.name}), function(i, d) {\n\n // calculate incentive\n var incentive_percent = 2;\n if(doc.grand_total &gt; 400) incentive_percent = 4;\n\n // actual incentive\n d.incentives = flt(doc.grand_total) * incentive_percent / 100;\n total_incentive += flt(d.incentives)\n });\n\n doc.total_incentive = total_incentive;\n}\n</code>\n</pre>",
"permlevel": 0
}
],
"icon": "icon-glass",
"idx": 1,
"modified": "2014-01-20 17:48:31.000000",
"modified": "2014-06-19 06:55:02.522204",
"modified_by": "Administrator",
"module": "Core",
"name": "Custom Script",