From 7045810bae40ba24241123ac28708db32a638f89 Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Fri, 15 Sep 2023 20:46:39 +0530 Subject: [PATCH] refactor: move clear data button to user action --- erpnext/public/js/utils/demo.js | 109 ++++++++------------------------ 1 file changed, 26 insertions(+), 83 deletions(-) diff --git a/erpnext/public/js/utils/demo.js b/erpnext/public/js/utils/demo.js index 3ebc5efcf1..ef83cf61d4 100644 --- a/erpnext/public/js/utils/demo.js +++ b/erpnext/public/js/utils/demo.js @@ -1,91 +1,34 @@ +frappe.provide("erpnext.demo"); + $(document).on("toolbar_setup", function () { if (frappe.boot.sysdefaults.demo_company) { - render_clear_demo_button(); + render_clear_demo_action(); } - - // for first load after setup. - frappe.realtime.on("demo_data_complete", () => { - render_clear_demo_button(); - }); }); -function render_clear_demo_button() { - let wait_for_onboaring_tours = setInterval(() => { - if ($("#driver-page-overlay").length || $("#show-dialog").length) { - return; - } - setup_clear_demo_button(); - clearInterval(wait_for_onboaring_tours); - }, 2000); -} - -function setup_clear_demo_button() { - let message_string = __( - "Demo data is present on the system, erase data before starting real usage." +function render_clear_demo_action() { + let demo_action = $( + ` + ${__("Clear Demo Data")} + ` ); - let $floatingBar = $(` -
-
-

- ${message_string} -

- - - - - - -
-
- `); - - $("footer").append($floatingBar); - - $("#clear-demo").on("click", function () { - frappe.confirm( - __("Are you sure you want to clear all demo data?"), - () => { - frappe.call({ - method: "erpnext.setup.demo.clear_demo_data", - freeze: true, - freeze_message: __("Clearing Demo Data..."), - callback: function (r) { - frappe.ui.toolbar.clear_cache(); - frappe.show_alert({ - message: __("Demo data cleared"), - indicator: "green", - }); - $("footer").remove($floatingBar); - }, - }); - } - ); - }); - - $("#dismiss-demo-banner").on("click", function () { - $floatingBar.remove(); - }); + demo_action.appendTo($("#toolbar-user")); } + +erpnext.demo.clear_demo = function () { + frappe.confirm(__("Are you sure you want to clear all demo data?"), () => { + frappe.call({ + method: "erpnext.setup.demo.clear_demo_data", + freeze: true, + freeze_message: __("Clearing Demo Data..."), + callback: function (r) { + frappe.ui.toolbar.clear_cache(); + frappe.show_alert({ + message: __("Demo data cleared"), + indicator: "green", + }); + }, + }); + }); +};