From 0abace79112063e86eade3f5c25f6ff831566895 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Mon, 6 Jan 2025 23:04:30 +0100 Subject: [PATCH] refactor(Project): extract custom button function (backport #45116) (#45117) Co-authored-by: Raffael Meyer <14891507+barredterra@users.noreply.github.com> --- erpnext/projects/doctype/project/project.js | 41 +++++++++++---------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/erpnext/projects/doctype/project/project.js b/erpnext/projects/doctype/project/project.js index 643e3b21782..e609e35111f 100644 --- a/erpnext/projects/doctype/project/project.js +++ b/erpnext/projects/doctype/project/project.js @@ -147,29 +147,32 @@ frappe.ui.form.on("Project", { set_project_status_button: function (frm) { frm.add_custom_button( __("Set Project Status"), - () => { - let d = new frappe.ui.Dialog({ - title: __("Set Project Status"), - fields: [ - { - fieldname: "status", - fieldtype: "Select", - label: "Status", - reqd: 1, - options: "Completed\nCancelled", - }, - ], - primary_action: function () { - frm.events.set_status(frm, d.get_values().status); - d.hide(); - }, - primary_action_label: __("Set Project Status"), - }).show(); - }, + () => frm.events.get_project_status_dialog(frm).show(), __("Actions") ); }, + get_project_status_dialog: function (frm) { + const dialog = new frappe.ui.Dialog({ + title: __("Set Project Status"), + fields: [ + { + fieldname: "status", + fieldtype: "Select", + label: "Status", + reqd: 1, + options: "Completed\nCancelled", + }, + ], + primary_action: function () { + frm.events.set_status(frm, dialog.get_values().status); + dialog.hide(); + }, + primary_action_label: __("Set Project Status"), + }); + return dialog; + }, + create_duplicate: function (frm) { return new Promise((resolve) => { frappe.prompt("Project Name", (data) => {