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