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) { |
| 3 | erpnext.setup_clear_button(); |
| 4 | } |
Ankush Menat | 3a21c90 | 2023-08-10 15:48:57 +0530 | [diff] [blame] | 5 | |
| 6 | // for first load |
| 7 | frappe.realtime.on("demo_data_complete", () => { |
| 8 | erpnext.setup_clear_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 | 8bdf280 | 2023-08-10 17:55:15 +0530 | [diff] [blame] | 12 | erpnext.setup_clear_button = function () { |
| 13 | let message_string = __( |
| 14 | "Demo data is present on the system, erase data before starting real usage." |
| 15 | ); |
Deepesh Garg | 371413a | 2023-07-29 22:39:07 +0530 | [diff] [blame] | 16 | let $floatingBar = $(` |
| 17 | <div class="flex justify-content-center" style="width: 100%;"> |
| 18 | <div class="flex justify-content-center flex-col shadow rounded p-2" |
| 19 | style=" |
Deepesh Garg | 371413a | 2023-07-29 22:39:07 +0530 | [diff] [blame] | 20 | background-color: #e0f2fe; |
| 21 | position: fixed; |
| 22 | bottom: 20px; |
| 23 | z-index: 1;"> |
| 24 | <p style="margin: auto 0; padding-left: 10px; margin-right: 20px; font-size: 15px;"> |
| 25 | ${message_string} |
| 26 | </p> |
| 27 | <button id="clear-demo" type="button" |
| 28 | class=" |
| 29 | px-4 |
| 30 | py-2 |
| 31 | border |
| 32 | border-transparent |
| 33 | text-white |
| 34 | " |
| 35 | style=" |
| 36 | margin: auto 0; |
| 37 | height: fit-content; |
| 38 | background-color: #007bff; |
| 39 | border-radius: 5px; |
| 40 | margin-right: 10px |
| 41 | " |
| 42 | > |
Ankush Menat | 3a21c90 | 2023-08-10 15:48:57 +0530 | [diff] [blame] | 43 | Clear Demo Data |
Deepesh Garg | 371413a | 2023-07-29 22:39:07 +0530 | [diff] [blame] | 44 | </button> |
| 45 | </div> |
| 46 | </div> |
| 47 | `); |
| 48 | |
Ankush Menat | 8bdf280 | 2023-08-10 17:55:15 +0530 | [diff] [blame] | 49 | $("footer").append($floatingBar); |
Deepesh Garg | 371413a | 2023-07-29 22:39:07 +0530 | [diff] [blame] | 50 | |
Ankush Menat | 8bdf280 | 2023-08-10 17:55:15 +0530 | [diff] [blame] | 51 | $("#clear-demo").on("click", function () { |
| 52 | frappe.confirm( |
| 53 | __("Are you sure you want to clear all demo data?"), |
| 54 | () => { |
| 55 | frappe.call({ |
| 56 | method: "erpnext.setup.demo.clear_demo_data", |
| 57 | freeze: true, |
| 58 | freeze_message: __("Clearing Demo Data..."), |
| 59 | callback: function (r) { |
| 60 | frappe.ui.toolbar.clear_cache(); |
| 61 | frappe.show_alert({ |
| 62 | message: __("Demo data cleared"), |
| 63 | indicator: "green", |
| 64 | }); |
| 65 | $("footer").remove($floatingBar); |
| 66 | }, |
| 67 | }); |
Deepesh Garg | 371413a | 2023-07-29 22:39:07 +0530 | [diff] [blame] | 68 | } |
Ankush Menat | 8bdf280 | 2023-08-10 17:55:15 +0530 | [diff] [blame] | 69 | ); |
Deepesh Garg | 371413a | 2023-07-29 22:39:07 +0530 | [diff] [blame] | 70 | }); |
Ankush Menat | 8bdf280 | 2023-08-10 17:55:15 +0530 | [diff] [blame] | 71 | }; |