Merge pull request #33439 from TheerayutEncoder/add-action-confirm-on-workflow
feat: Add action confirm on Workflow
This commit is contained in:
commit
e5b7c17c8f
2 changed files with 48 additions and 22 deletions
|
|
@ -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");
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue