diff --git a/hrms/public/js/hierarchy-chart.bundle.js b/hrms/public/js/hierarchy-chart.bundle.js index 02703139dd..96563e6256 100644 --- a/hrms/public/js/hierarchy-chart.bundle.js +++ b/hrms/public/js/hierarchy-chart.bundle.js @@ -1,3 +1,4 @@ import "./hierarchy_chart/hierarchy_chart_desktop.js"; import "./hierarchy_chart/hierarchy_chart_mobile.js"; import "./templates/node_card.html"; +import "./templates/hierarchy_empty_state.html"; diff --git a/hrms/public/js/hierarchy_chart/hierarchy_chart_desktop.js b/hrms/public/js/hierarchy_chart/hierarchy_chart_desktop.js index 51019d2250..d1a05db5ce 100644 --- a/hrms/public/js/hierarchy_chart/hierarchy_chart_desktop.js +++ b/hrms/public/js/hierarchy_chart/hierarchy_chart_desktop.js @@ -12,22 +12,12 @@ hrms.HierarchyChart = class { this.method = method; this.doctype = doctype; - this.setup_page_style(); this.page.main.addClass("frappe-card"); this.nodes = {}; this.setup_node_class(); } - setup_page_style() { - this.page.main.css({ - "min-height": "300px", - "max-height": "700px", - overflow: "auto", - position: "relative", - }); - } - setup_node_class() { let me = this; this.Node = class { @@ -228,6 +218,15 @@ hrms.HierarchyChart = class { }) .then((r) => { if (r.message.length) { + me.page.body.find("#hierarchy-empty-root").remove(); + + me.page.main.css({ + "min-height": "300px", + "max-height": "700px", + overflow: "auto", + position: "relative", + }); + let expand_node; let node; @@ -255,6 +254,39 @@ hrms.HierarchyChart = class { if (!expanded_view) { me.expand_node(expand_node); } + } else { + me.page.body.find("#hierarchy-empty-root").remove(); + const empty_html = frappe.render_template("hierarchy_empty_state", { + doctype: me.doctype, + company: me.company, + can_create: frappe.model.can_create(me.doctype), + device_type: "desktop", + }); + + $("#hierarchy-chart-wrapper").remove(); + me.page.body.append(empty_html); + + me.page.main.css({ + "min-height": "100%", + "max-height": "100%", + }); + + (function () { + const root = document.getElementById("hierarchy-empty-root"); + if (!root) return; + try { + const rect = root.getBoundingClientRect(); + const windowHeight = window.innerHeight; + const height = Math.max(300, Math.floor(windowHeight - rect.top - 20)); + root.style.height = height + "px"; + root.style.overflow = "auto"; + root.style.position = "relative"; + } catch (e) {} + })(); + me.page.body.find("#add-doc-btn").on("click", () => { + frappe.route_options = { company: me.company }; + frappe.new_doc(me.doctype); + }); } }); } diff --git a/hrms/public/js/hierarchy_chart/hierarchy_chart_mobile.js b/hrms/public/js/hierarchy_chart/hierarchy_chart_mobile.js index 3505ef1fc2..eb25bcf289 100644 --- a/hrms/public/js/hierarchy_chart/hierarchy_chart_mobile.js +++ b/hrms/public/js/hierarchy_chart/hierarchy_chart_mobile.js @@ -11,12 +11,6 @@ hrms.HierarchyChartMobile = class { this.method = method; this.doctype = doctype; - this.page.main.css({ - "min-height": "300px", - "max-height": "600px", - overflow: "auto", - position: "relative", - }); this.page.main.addClass("frappe-card"); this.nodes = {}; @@ -155,6 +149,15 @@ hrms.HierarchyChartMobile = class { }) .then((r) => { if (r.message.length) { + me.page.body.find("#hierarchy-empty-root").remove(); + + me.page.main.css({ + "min-height": "300px", + "max-height": "600px", + overflow: "auto", + position: "relative", + }); + let root_level = me.$hierarchy.find(".root-level"); root_level.empty(); @@ -171,6 +174,40 @@ hrms.HierarchyChartMobile = class { is_root: true, }); }); + } else { + me.page.body.find("#hierarchy-empty-root").remove(); + me.page.main.css({ + "min-height": "100%", + "max-height": "100%", + overflow: "auto", + position: "relative", + }); + + const empty = frappe.render_template("hierarchy_empty_state", { + doctype: me.doctype, + company: me.company, + can_create: frappe.model.can_create(me.doctype), + device_type: "mobile", + }); + + me.page.main.append(empty); + + (function () { + const root = document.getElementById("hierarchy-empty-root"); + if (!root) return; + try { + const rect = root.getBoundingClientRect(); + const windowHeight = window.innerHeight; + const height = Math.max(300, Math.floor(windowHeight - rect.top - 20)); + root.style.height = height + "px"; + root.style.overflow = "auto"; + root.style.position = "relative"; + } catch (e) {} + })(); + me.page.body.find("#add-doc-btn").on("click", () => { + frappe.route_options = { company: me.company }; + frappe.new_doc(me.doctype); + }); } }); } diff --git a/hrms/public/js/templates/hierarchy_empty_state.html b/hrms/public/js/templates/hierarchy_empty_state.html new file mode 100644 index 0000000000..3296822600 --- /dev/null +++ b/hrms/public/js/templates/hierarchy_empty_state.html @@ -0,0 +1,32 @@ + +