Skip to content

Commit

Permalink
Merge pull request #344 from shariquerik/standard-form-script
Browse files Browse the repository at this point in the history
feat: allow adding standard form script
  • Loading branch information
shariquerik authored Sep 11, 2024
2 parents 49082be + dd6d2b3 commit 3bfc037
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 2 deletions.
22 changes: 22 additions & 0 deletions crm/fcrm/doctype/crm_form_script/crm_form_script.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,29 @@ frappe.ui.form.on("CRM Form Script", {
istable: 0,
},
});

if (frm.doc.is_standard && !frappe.boot.developer_mode) {
frm.disable_form();
frappe.show_alert(
__(
"Standard Form Scripts can not be modified, duplicate the Form Script instead."
)
);
}

frm.trigger("add_enable_button");
},

add_enable_button(frm) {
frm.add_custom_button(
frm.doc.enabled ? __("Disable") : __("Enable"),
() => {
frm.set_value("enabled", !frm.doc.enabled);
frm.save();
}
);
},

view(frm) {
let has_form_boilerplate = frm.doc.script.includes(
"function setupForm("
Expand Down
10 changes: 9 additions & 1 deletion crm/fcrm/doctype/crm_form_script/crm_form_script.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"view",
"column_break_gboh",
"enabled",
"is_standard",
"section_break_xeox",
"script"
],
Expand Down Expand Up @@ -52,11 +53,18 @@
"label": "Apply To",
"options": "Form\nList",
"set_only_once": 1
},
{
"default": "0",
"fieldname": "is_standard",
"fieldtype": "Check",
"label": "Is Standard",
"no_copy": 1
}
],
"index_web_pages_for_search": 1,
"links": [],
"modified": "2024-04-10 18:27:17.617602",
"modified": "2024-09-11 12:56:09.288849",
"modified_by": "Administrator",
"module": "FCRM",
"name": "CRM Form Script",
Expand Down
17 changes: 16 additions & 1 deletion crm/fcrm/doctype/crm_form_script/crm_form_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,26 @@
# For license information, please see license.txt

import frappe
from frappe import _
from frappe.model.document import Document


class CRMFormScript(Document):
pass
def validate(self):
in_user_env = not (
frappe.flags.in_install
or frappe.flags.in_patch
or frappe.flags.in_test
or frappe.flags.in_fixtures
)
if in_user_env and self.is_standard and not frappe.conf.developer_mode:
# only enabled can be changed for standard form scripts
if self.has_value_changed("enabled"):
enabled_value = self.enabled
self.reload()
self.enabled = enabled_value
else:
frappe.throw(_("You need to be in developer mode to edit a Standard Form Script"))

def get_form_script(dt, view="Form"):
"""Returns the form script for the given doctype"""
Expand Down

0 comments on commit 3bfc037

Please sign in to comment.