Merge pull request #33439 from TheerayutEncoder/add-action-confirm-on-workflow

feat: Add action confirm on Workflow
This commit is contained in:
Ejaaz Khan 2025-10-12 23:05:35 +05:30 committed by GitHub
commit e5b7c17c8f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 48 additions and 22 deletions

View file

@ -98,31 +98,26 @@ frappe.ui.form.States = class FormStates {
frappe.workflow.get_transitions(this.frm.doc).then((transitions) => {
this.frm.page.clear_actions_menu();
const frm = this.frm;
transitions.forEach((d) => {
if (frappe.user_roles.includes(d.allowed) && has_approval_access(d)) {
added = true;
me.frm.page.add_action_item(__(d.action), function () {
// set the workflow_action for use in form scripts
frappe.dom.freeze();
me.frm.selected_workflow_action = d.action;
if (!frappe.ui.form.check_mandatory(frm)) return frappe.dom.unfreeze();
me.frm.script_manager.trigger("before_workflow_action").then(() => {
frappe
.xcall("frappe.model.workflow.apply_workflow", {
doc: me.frm.doc,
action: d.action,
})
.then((doc) => {
frappe.model.sync(doc);
me.frm.refresh();
me.frm.selected_workflow_action = null;
me.frm.script_manager.trigger("after_workflow_action");
})
.finally(() => {
frappe.dom.unfreeze();
});
});
frappe.db
.get_value(
"Workflow",
{ document_type: me.frm.doctype },
"enable_action_confirmation"
)
.then((r) => {
if (r.message.enable_action_confirmation) {
frappe.confirm(
__("Are you sure you want to {0}?", [d.action]),
() => me.handle_workflow_action(d)
);
} else {
me.handle_workflow_action(d);
}
});
});
}
});
@ -131,6 +126,29 @@ frappe.ui.form.States = class FormStates {
});
}
handle_workflow_action(transition) {
var me = this;
// set the workflow_action for use in form scripts
frappe.dom.freeze();
me.frm.selected_workflow_action = transition.action;
me.frm.script_manager.trigger("before_workflow_action").then(() => {
frappe
.xcall("frappe.model.workflow.apply_workflow", {
doc: me.frm.doc,
action: transition.action,
})
.then((doc) => {
frappe.model.sync(doc);
me.frm.refresh();
me.frm.selected_workflow_action = null;
me.frm.script_manager.trigger("after_workflow_action");
})
.finally(() => {
frappe.dom.unfreeze();
});
});
}
setup_btn(action_added) {
if (action_added) {
this.frm.page.btn_primary.addClass("hide");

View file

@ -13,6 +13,7 @@
"is_active",
"override_status",
"send_email_alert",
"enable_action_confirmation",
"states_head",
"states",
"transition_rules",
@ -60,6 +61,13 @@
"fieldtype": "Check",
"label": "Send Email Alert"
},
{
"default": "0",
"description": "If checked, a confirmation will be required before performing workflow actions.",
"fieldname": "enable_action_confirmation",
"fieldtype": "Check",
"label": "Enable Action Confirmation"
},
{
"description": "Different \"States\" this document can exist in. Like \"Open\", \"Pending Approval\" etc.",
"fieldname": "states_head",
@ -126,4 +134,4 @@
"sort_order": "DESC",
"states": [],
"track_changes": 1
}
}