Ankush Menat | 8bdf280 | 2023-08-10 17:55:15 +0530 | [diff] [blame] | 1 | $(document).on("toolbar_setup", function () { |
Deepesh Garg | 371413a | 2023-07-29 22:39:07 +0530 | [diff] [blame] | 2 | if (frappe.boot.sysdefaults.demo_company) { |
Ankush Menat | 6b464ed | 2023-08-12 11:21:33 +0530 | [diff] [blame] | 3 | render_clear_demo_button(); |
Deepesh Garg | 371413a | 2023-07-29 22:39:07 +0530 | [diff] [blame] | 4 | } |
Ankush Menat | 3a21c90 | 2023-08-10 15:48:57 +0530 | [diff] [blame] | 5 | |
Ankush Menat | 6b464ed | 2023-08-12 11:21:33 +0530 | [diff] [blame] | 6 | // for first load after setup. |
Ankush Menat | 3a21c90 | 2023-08-10 15:48:57 +0530 | [diff] [blame] | 7 | frappe.realtime.on("demo_data_complete", () => { |
Ankush Menat | 6b464ed | 2023-08-12 11:21:33 +0530 | [diff] [blame] | 8 | render_clear_demo_button(); |
Ankush Menat | 8bdf280 | 2023-08-10 17:55:15 +0530 | [diff] [blame] | 9 | }); |
Deepesh Garg | bb5387f | 2023-07-07 10:49:56 +0530 | [diff] [blame] | 10 | }); |
| 11 | |
Ankush Menat | 6b464ed | 2023-08-12 11:21:33 +0530 | [diff] [blame] | 12 | function 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 | |
| 22 | function setup_clear_demo_button() { |
Ankush Menat | 8bdf280 | 2023-08-10 17:55:15 +0530 | [diff] [blame] | 23 | let message_string = __( |
| 24 | "Demo data is present on the system, erase data before starting real usage." |
| 25 | ); |
Deepesh Garg | 371413a | 2023-07-29 22:39:07 +0530 | [diff] [blame] | 26 | 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 Garg | 371413a | 2023-07-29 22:39:07 +0530 | [diff] [blame] | 30 | 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 Menat | 3a21c90 | 2023-08-10 15:48:57 +0530 | [diff] [blame] | 53 | Clear Demo Data |
Deepesh Garg | 371413a | 2023-07-29 22:39:07 +0530 | [diff] [blame] | 54 | </button> |
Ankush Menat | 2d3fa80 | 2023-08-12 11:33:35 +0530 | [diff] [blame] | 55 | |
| 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 Garg | 371413a | 2023-07-29 22:39:07 +0530 | [diff] [blame] | 61 | </div> |
| 62 | </div> |
| 63 | `); |
| 64 | |
Ankush Menat | 8bdf280 | 2023-08-10 17:55:15 +0530 | [diff] [blame] | 65 | $("footer").append($floatingBar); |
Deepesh Garg | 371413a | 2023-07-29 22:39:07 +0530 | [diff] [blame] | 66 | |
Ankush Menat | 8bdf280 | 2023-08-10 17:55:15 +0530 | [diff] [blame] | 67 | $("#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 Garg | 371413a | 2023-07-29 22:39:07 +0530 | [diff] [blame] | 84 | } |
Ankush Menat | 8bdf280 | 2023-08-10 17:55:15 +0530 | [diff] [blame] | 85 | ); |
Deepesh Garg | 371413a | 2023-07-29 22:39:07 +0530 | [diff] [blame] | 86 | }); |
Ankush Menat | 2d3fa80 | 2023-08-12 11:33:35 +0530 | [diff] [blame] | 87 | |
| 88 | $("#dismiss-demo-banner").on("click", function () { |
| 89 | $floatingBar.remove(); |
| 90 | }); |
Ankush Menat | 6b464ed | 2023-08-12 11:21:33 +0530 | [diff] [blame] | 91 | } |