feat: let people reset layout back to original (#21290)

This commit is contained in:
Ankush Menat 2023-06-08 18:07:12 +05:30 committed by GitHub
parent 924ecc71f6
commit e98519211e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 49 additions and 1 deletions

View file

@ -126,6 +126,14 @@ frappe.ui.form.on("Customize Form", {
__("Actions")
);
frm.add_custom_button(
__("Reset Layout"),
() => {
frm.trigger("reset_layout");
},
__("Actions")
);
frm.add_custom_button(
__("Set Permissions"),
function () {
@ -164,6 +172,28 @@ frappe.ui.form.on("Customize Form", {
}
},
reset_layout(frm) {
frappe.confirm(
__("Layout will be reset to standard layout, are you sure you want to do this?"),
null,
() => {
return frm.call({
doc: frm.doc,
method: "reset_to_defaults",
callback: function (r) {
if (!r.exc) {
frappe.show_alert({
message: __("Layout Reset"),
indicator: "green",
});
frappe.customize_form.clear_locals_and_refresh(frm);
}
},
});
}
);
},
setup_export(frm) {
if (frappe.boot.developer_mode) {
frm.add_custom_button(

View file

@ -35,7 +35,7 @@ class CustomizeForm(Document):
if not self.doc_type:
return
meta = frappe.get_meta(self.doc_type)
meta = frappe.get_meta(self.doc_type, cached=False)
self.validate_doctype(meta)
@ -568,6 +568,24 @@ class CustomizeForm(Document):
reset_customization(self.doc_type)
self.fetch_to_customize()
@frappe.whitelist()
def reset_layout(self):
if not self.doc_type:
return
property_setter = frappe.db.get_value(
"Property Setter",
filters={
"doc_type": self.doc_type,
"property": "field_order",
"is_system_generated": False,
},
)
if property_setter:
frappe.delete_doc("Property Setter", property_setter)
self.fetch_to_customize()
@classmethod
def allow_fieldtype_change(self, old_type: str, new_type: str) -> bool:
"""allow type change, if both old_type and new_type are in same field group.