From e560d7428e41646bfbea6720a58872cec06f5a21 Mon Sep 17 00:00:00 2001 From: Suraj Shetty Date: Mon, 18 Jan 2021 16:43:22 +0530 Subject: [PATCH] fix: Update split issue & help article --- erpnext/support/doctype/issue/issue.js | 73 ++++++++++++++++---------- 1 file changed, 46 insertions(+), 27 deletions(-) diff --git a/erpnext/support/doctype/issue/issue.js b/erpnext/support/doctype/issue/issue.js index 158416ba796..935b6e81260 100644 --- a/erpnext/support/doctype/issue/issue.js +++ b/erpnext/support/doctype/issue/issue.js @@ -154,52 +154,71 @@ frappe.ui.form.on("Issue", { timeline_refresh: function(frm) { - // create button for "Help Article" - if (frappe.model.can_create("Help Article")) { - // Removing Help Article button if exists to avoid multiple occurance - frm.timeline.wrapper.find('.comment-header .asset-details .btn-add-to-kb').remove(); - $('') - .appendTo(frm.timeline.wrapper.find('.comment-header .asset-details:not([data-communication-type="Comment"])')) - .on("click", function() { - var content = $(this).parents(".timeline-item:first").find(".timeline-item-content").html(); - var doc = frappe.model.get_new_doc("Help Article"); - doc.title = frm.doc.subject; - doc.content = content; - frappe.set_route("Form", "Help Article", doc.name); - }); - } - if (!frm.timeline.wrapper.find(".btn-split-issue").length) { - let split_issue = __("Split Issue") - $(``) - .appendTo(frm.timeline.wrapper.find('.comment-header .asset-details:not([data-communication-type="Comment"])')) + let split_issue_btn = $(` + + ${frappe.utils.icon('branch', 'sm')} + + `); + + let communication_box = frm.timeline.wrapper.find('.timeline-item[data-doctype="Communication"]'); + communication_box.find('.actions').prepend(split_issue_btn); + if (!frm.timeline.wrapper.data("split-issue-event-attached")) { frm.timeline.wrapper.on('click', '.btn-split-issue', (e) => { var dialog = new frappe.ui.Dialog({ title: __("Split Issue"), fields: [ - {fieldname: "subject", fieldtype: "Data", reqd: 1, label: __("Subject"), description: __("All communications including and above this shall be moved into the new Issue")} + { + fieldname: "subject", + fieldtype: "Data", + reqd: 1, + label: __("Subject"), + description: __("All communications including and above this shall be moved into the new Issue") + } ], primary_action_label: __("Split"), - primary_action: function() { + primary_action: () => { frm.call("split_issue", { subject: dialog.fields_dict.subject.value, communication_id: e.currentTarget.closest(".timeline-item").getAttribute("data-name") }, (r) => { - frappe.msgprint(`New issue created: ${r.message}`) + frappe.msgprint(`New issue created: ${r.message}`); frm.reload_doc(); dialog.hide(); }); } }); - dialog.show() - }) - frm.timeline.wrapper.data("split-issue-event-attached", true) + dialog.show(); + }); + frm.timeline.wrapper.data("split-issue-event-attached", true); } } + + // create button for "Help Article" + if (frappe.model.can_create("Help Article")) { + // Removing Help Article button if exists to avoid multiple occurrence + frm.timeline.wrapper.find('.action-btn .btn-add-to-kb').remove(); + + let help_article = $(` + + ${frappe.utils.icon('solid-info', 'sm')} + + `); + + let communication_box = frm.timeline.wrapper.find('.timeline-item[data-doctype="Communication"]'); + communication_box.find('.actions').prepend(help_article); + if (!frm.timeline.wrapper.data("help-article-event-attached")) { + frm.timeline.wrapper.on('click', '.btn-add-to-kb', function () { + const content = $(this).parents('.timeline-item[data-doctype="Communication"]:first').find(".content").html(); + const doc = frappe.model.get_new_doc("Help Article"); + doc.title = frm.doc.subject; + doc.content = content; + frappe.set_route("Form", "Help Article", doc.name); + }); + } + frm.timeline.wrapper.data("help-article-event-attached", true); + } }, });