Skip to content

Commit

Permalink
Merge pull request #29021 from anupamvs/project-form-custom-btn-grouping
Browse files Browse the repository at this point in the history
fix: grouping project form custom buttons
  • Loading branch information
deepeshgarg007 authored Dec 28, 2021
2 parents 25f4de8 + 077e2c6 commit 3607f51
Showing 1 changed file with 31 additions and 13 deletions.
44 changes: 31 additions & 13 deletions erpnext/projects/doctype/project/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,22 +59,16 @@ frappe.ui.form.on("Project", {

frm.trigger('show_dashboard');
}
frm.events.set_buttons(frm);
frm.trigger("set_custom_buttons");
},

set_buttons: function(frm) {
set_custom_buttons: function(frm) {
if (!frm.is_new()) {
frm.add_custom_button(__('Duplicate Project with Tasks'), () => {
frm.events.create_duplicate(frm);
});

frm.add_custom_button(__('Completed'), () => {
frm.events.set_status(frm, 'Completed');
}, __('Set Status'));
}, __("Actions"));

frm.add_custom_button(__('Cancelled'), () => {
frm.events.set_status(frm, 'Cancelled');
}, __('Set Status'));
frm.trigger("set_project_status_button");


if (frappe.model.can_read("Task")) {
Expand All @@ -83,21 +77,43 @@ frappe.ui.form.on("Project", {
"project": frm.doc.name
};
frappe.set_route("List", "Task", "Gantt");
});
}, __("View"));

frm.add_custom_button(__("Kanban Board"), () => {
frappe.call('erpnext.projects.doctype.project.project.create_kanban_board_if_not_exists', {
project: frm.doc.name
}).then(() => {
frappe.set_route('List', 'Task', 'Kanban', frm.doc.project_name);
});
});
}, __("View"));
}
}


},

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();
}, __("Actions"));
},

create_duplicate: function(frm) {
return new Promise(resolve => {
frappe.prompt('Project Name', (data) => {
Expand All @@ -117,7 +133,9 @@ frappe.ui.form.on("Project", {
set_status: function(frm, status) {
frappe.confirm(__('Set Project and all Tasks to status {0}?', [status.bold()]), () => {
frappe.xcall('erpnext.projects.doctype.project.project.set_project_status',
{project: frm.doc.name, status: status}).then(() => { /* page will auto reload */ });
{project: frm.doc.name, status: status}).then(() => {
frm.reload_doc();
});
});
},

Expand Down

0 comments on commit 3607f51

Please sign in to comment.