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