feat: Add action confirm on Workflow
imp: move Action Confirmation into transitions level
This commit is contained in:
parent
aca2801897
commit
85a5f05b80
4 changed files with 42 additions and 22 deletions
|
|
@ -102,25 +102,14 @@ frappe.ui.form.States = class FormStates {
|
||||||
if (frappe.user_roles.includes(d.allowed) && has_approval_access(d)) {
|
if (frappe.user_roles.includes(d.allowed) && has_approval_access(d)) {
|
||||||
added = true;
|
added = true;
|
||||||
me.frm.page.add_action_item(__(d.action), function () {
|
me.frm.page.add_action_item(__(d.action), function () {
|
||||||
// set the workflow_action for use in form scripts
|
if (d.enable_action_confirmation) {
|
||||||
frappe.dom.freeze();
|
frappe.confirm(
|
||||||
me.frm.selected_workflow_action = d.action;
|
__("Are you sure you want to {0}?", [d.action]),
|
||||||
me.frm.script_manager.trigger("before_workflow_action").then(() => {
|
() => me.handle_workflow_action(d)
|
||||||
frappe
|
);
|
||||||
.xcall("frappe.model.workflow.apply_workflow", {
|
} else {
|
||||||
doc: me.frm.doc,
|
me.handle_workflow_action(d);
|
||||||
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();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -129,6 +118,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) {
|
setup_btn(action_added) {
|
||||||
if (action_added) {
|
if (action_added) {
|
||||||
this.frm.page.btn_primary.addClass("hide");
|
this.frm.page.btn_primary.addClass("hide");
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ let properties = computed(() => {
|
||||||
if (store.workflow.selected && "action" in store.workflow.selected.data) {
|
if (store.workflow.selected && "action" in store.workflow.selected.data) {
|
||||||
title.value = __("Transition Properties");
|
title.value = __("Transition Properties");
|
||||||
return store.transitionfields.filter((df) =>
|
return store.transitionfields.filter((df) =>
|
||||||
["action", "allowed", "allow_self_approval", "condition"].includes(df.fieldname)
|
["action", "allowed", "allow_self_approval", "action_confirm", "condition"].includes(df.fieldname)
|
||||||
);
|
);
|
||||||
} else if (store.workflow.selected && "state" in store.workflow.selected.data) {
|
} else if (store.workflow.selected && "state" in store.workflow.selected.data) {
|
||||||
title.value = __("State Properties");
|
title.value = __("State Properties");
|
||||||
|
|
|
||||||
|
|
@ -126,4 +126,4 @@
|
||||||
"sort_order": "DESC",
|
"sort_order": "DESC",
|
||||||
"states": [],
|
"states": [],
|
||||||
"track_changes": 1
|
"track_changes": 1
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@
|
||||||
"allowed",
|
"allowed",
|
||||||
"allow_self_approval",
|
"allow_self_approval",
|
||||||
"send_email_to_creator",
|
"send_email_to_creator",
|
||||||
|
"enable_action_confirmation",
|
||||||
"conditions",
|
"conditions",
|
||||||
"condition",
|
"condition",
|
||||||
"column_break_7",
|
"column_break_7",
|
||||||
|
|
@ -99,7 +100,14 @@
|
||||||
"fieldname": "send_email_to_creator",
|
"fieldname": "send_email_to_creator",
|
||||||
"fieldtype": "Check",
|
"fieldtype": "Check",
|
||||||
"label": "Send Email To Creator"
|
"label": "Send Email To Creator"
|
||||||
}
|
},
|
||||||
|
{
|
||||||
|
"default": "0",
|
||||||
|
"description": "If checked, action confirmation will be required before performing workflow actions",
|
||||||
|
"fieldname": "enable_action_confirmation",
|
||||||
|
"fieldtype": "Check",
|
||||||
|
"label": "Enable Action Confirmation"
|
||||||
|
}
|
||||||
],
|
],
|
||||||
"idx": 1,
|
"idx": 1,
|
||||||
"istable": 1,
|
"istable": 1,
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue