fix: workflow creating/editing dialog

This commit is contained in:
Shariq Ansari 2023-05-01 13:25:39 +05:30
parent aa3b6d3ecc
commit 289c774b1a
3 changed files with 90 additions and 5 deletions

View file

@ -25,6 +25,18 @@ frappe.ui.form.on("Workflow", {
});
},
validate: (frm) => {
if (
frm.doc.is_active &&
(frm.doc.states.length === 0 || frm.doc.transitions.length === 0)
) {
let message = "Workflow must have atleast one state and transition";
frappe.throw({
message: __(message),
title: __("Missing Values Required"),
indicator: "orange",
});
}
if (frm.ignore_warning) {
return;
}

View file

@ -70,8 +70,7 @@
"fieldname": "states",
"fieldtype": "Table",
"label": "Document States",
"options": "Workflow Document State",
"reqd": 1
"options": "Workflow Document State"
},
{
"description": "Rules for how states are transitions, like next state and which role is allowed to change state etc.",
@ -84,8 +83,7 @@
"fieldname": "transitions",
"fieldtype": "Table",
"label": "Transitions",
"options": "Workflow Transition",
"reqd": 1
"options": "Workflow Transition"
},
{
"default": "workflow_state",
@ -99,7 +97,7 @@
"icon": "fa fa-random",
"idx": 1,
"links": [],
"modified": "2020-12-17 20:35:16.898040",
"modified": "2023-05-01 13:21:30.951859",
"modified_by": "Administrator",
"module": "Workflow",
"name": "Workflow",

View file

@ -29,5 +29,80 @@ function load_workflow_builder(wrapper) {
workflow: route[1],
});
});
} else {
let d = new frappe.ui.Dialog({
title: __("Create or Edit Workflow"),
fields: [
{
label: __("Action"),
fieldname: "action",
fieldtype: "Select",
options: [
{ label: __("Create New"), value: "Create" },
{ label: __("Edit Existing"), value: "Edit" },
],
change() {
let action = d.get_value("action");
d.get_primary_btn().text(action === "Create" ? __("Create") : __("Edit"));
},
},
{
label: __("Select Document Type"),
fieldname: "doctype",
fieldtype: "Link",
options: "DocType",
filters: {
istable: 0,
},
reqd: 1,
default: frappe.route_options ? frappe.route_options.doctype : null,
},
{
label: __("New Workflow Name"),
fieldname: "workflow_name",
fieldtype: "Data",
depends_on: (doc) => doc.action === "Create",
mandatory_depends_on: (doc) => doc.action === "Create",
},
{
label: __("Select Workflow"),
fieldname: "workflow",
fieldtype: "Link",
options: "Workflow",
only_select: 1,
depends_on: (doc) => doc.action === "Edit",
get_query() {
return {
filters: {
document_type: d.get_value("doctype"),
},
};
},
mandatory_depends_on: (doc) => doc.action === "Edit",
},
],
primary_action_label: __("Edit"),
primary_action({ action, doctype, workflow, workflow_name }) {
if (action === "Edit") {
frappe.set_route("workflow-builder", workflow);
} else if (action === "Create") {
d.get_primary_btn().prop("disabled", true);
frappe.db
.insert({
doctype: "Workflow",
workflow_name: workflow_name,
document_type: doctype,
})
.then((doc) => {
frappe.set_route("workflow-builder", doc.name);
})
.finally(() => {
d.get_primary_btn().prop("disabled", false);
});
}
},
});
d.set_value("action", "Create");
d.show();
}
}