blob: b59c4762e0013d222c1d3c22c886d22687b6f243 [file] [log] [blame]
Ankush Menat8bdf2802023-08-10 17:55:15 +05301$(document).on("toolbar_setup", function () {
Deepesh Garg371413a2023-07-29 22:39:07 +05302 if (frappe.boot.sysdefaults.demo_company) {
Ankush Menat6b464ed2023-08-12 11:21:33 +05303 render_clear_demo_button();
Deepesh Garg371413a2023-07-29 22:39:07 +05304 }
Ankush Menat3a21c902023-08-10 15:48:57 +05305
Ankush Menat6b464ed2023-08-12 11:21:33 +05306 // for first load after setup.
Ankush Menat3a21c902023-08-10 15:48:57 +05307 frappe.realtime.on("demo_data_complete", () => {
Ankush Menat6b464ed2023-08-12 11:21:33 +05308 render_clear_demo_button();
Ankush Menat8bdf2802023-08-10 17:55:15 +05309 });
Deepesh Gargbb5387f2023-07-07 10:49:56 +053010});
11
Ankush Menat6b464ed2023-08-12 11:21:33 +053012function render_clear_demo_button() {
13 let wait_for_onboaring_tours = setInterval(() => {
14 if ($("#driver-page-overlay").length) {
15 return;
16 }
17 setup_clear_demo_button();
18 clearInterval(wait_for_onboaring_tours);
19 }, 2000);
20}
21
22function setup_clear_demo_button() {
Ankush Menat8bdf2802023-08-10 17:55:15 +053023 let message_string = __(
24 "Demo data is present on the system, erase data before starting real usage."
25 );
Deepesh Garg371413a2023-07-29 22:39:07 +053026 let $floatingBar = $(`
27 <div class="flex justify-content-center" style="width: 100%;">
28 <div class="flex justify-content-center flex-col shadow rounded p-2"
29 style="
Deepesh Garg371413a2023-07-29 22:39:07 +053030 background-color: #e0f2fe;
31 position: fixed;
32 bottom: 20px;
33 z-index: 1;">
34 <p style="margin: auto 0; padding-left: 10px; margin-right: 20px; font-size: 15px;">
35 ${message_string}
36 </p>
37 <button id="clear-demo" type="button"
38 class="
39 px-4
40 py-2
41 border
42 border-transparent
43 text-white
44 "
45 style="
46 margin: auto 0;
47 height: fit-content;
48 background-color: #007bff;
49 border-radius: 5px;
50 margin-right: 10px
51 "
52 >
Ankush Menat3a21c902023-08-10 15:48:57 +053053 Clear Demo Data
Deepesh Garg371413a2023-07-29 22:39:07 +053054 </button>
Ankush Menat2d3fa802023-08-12 11:33:35 +053055
56 <a type="button" id="dismiss-demo-banner" class="text-muted" style="align-self: center">
57 <svg class="icon" style="">
58 <use class="" href="#icon-close"></use>
59 </svg>
60 </a>
Deepesh Garg371413a2023-07-29 22:39:07 +053061 </div>
62 </div>
63 `);
64
Ankush Menat8bdf2802023-08-10 17:55:15 +053065 $("footer").append($floatingBar);
Deepesh Garg371413a2023-07-29 22:39:07 +053066
Ankush Menat8bdf2802023-08-10 17:55:15 +053067 $("#clear-demo").on("click", function () {
68 frappe.confirm(
69 __("Are you sure you want to clear all demo data?"),
70 () => {
71 frappe.call({
72 method: "erpnext.setup.demo.clear_demo_data",
73 freeze: true,
74 freeze_message: __("Clearing Demo Data..."),
75 callback: function (r) {
76 frappe.ui.toolbar.clear_cache();
77 frappe.show_alert({
78 message: __("Demo data cleared"),
79 indicator: "green",
80 });
81 $("footer").remove($floatingBar);
82 },
83 });
Deepesh Garg371413a2023-07-29 22:39:07 +053084 }
Ankush Menat8bdf2802023-08-10 17:55:15 +053085 );
Deepesh Garg371413a2023-07-29 22:39:07 +053086 });
Ankush Menat2d3fa802023-08-12 11:33:35 +053087
88 $("#dismiss-demo-banner").on("click", function () {
89 $floatingBar.remove();
90 });
Ankush Menat6b464ed2023-08-12 11:21:33 +053091}