Ankush Menat | 7045810 | 2023-09-15 20:46:39 +0530 | [diff] [blame] | 1 | frappe.provide("erpnext.demo"); |
| 2 | |
Ankush Menat | 8bdf280 | 2023-08-10 17:55:15 +0530 | [diff] [blame] | 3 | $(document).on("toolbar_setup", function () { |
Deepesh Garg | 371413a | 2023-07-29 22:39:07 +0530 | [diff] [blame] | 4 | if (frappe.boot.sysdefaults.demo_company) { |
Ankush Menat | 7045810 | 2023-09-15 20:46:39 +0530 | [diff] [blame] | 5 | render_clear_demo_action(); |
Deepesh Garg | 371413a | 2023-07-29 22:39:07 +0530 | [diff] [blame] | 6 | } |
Deepesh Garg | bb5387f | 2023-07-07 10:49:56 +0530 | [diff] [blame] | 7 | }); |
| 8 | |
Ankush Menat | 7045810 | 2023-09-15 20:46:39 +0530 | [diff] [blame] | 9 | function render_clear_demo_action() { |
| 10 | let demo_action = $( |
| 11 | `<a class="dropdown-item" onclick="return erpnext.demo.clear_demo()"> |
| 12 | ${__("Clear Demo Data")} |
| 13 | </a>` |
Ankush Menat | 8bdf280 | 2023-08-10 17:55:15 +0530 | [diff] [blame] | 14 | ); |
Ankush Menat | 2d3fa80 | 2023-08-12 11:33:35 +0530 | [diff] [blame] | 15 | |
Ankush Menat | 7045810 | 2023-09-15 20:46:39 +0530 | [diff] [blame] | 16 | demo_action.appendTo($("#toolbar-user")); |
Ankush Menat | 6b464ed | 2023-08-12 11:21:33 +0530 | [diff] [blame] | 17 | } |
Ankush Menat | 7045810 | 2023-09-15 20:46:39 +0530 | [diff] [blame] | 18 | |
| 19 | erpnext.demo.clear_demo = function () { |
| 20 | frappe.confirm(__("Are you sure you want to clear all demo data?"), () => { |
| 21 | frappe.call({ |
| 22 | method: "erpnext.setup.demo.clear_demo_data", |
| 23 | freeze: true, |
| 24 | freeze_message: __("Clearing Demo Data..."), |
| 25 | callback: function (r) { |
| 26 | frappe.ui.toolbar.clear_cache(); |
| 27 | frappe.show_alert({ |
| 28 | message: __("Demo data cleared"), |
| 29 | indicator: "green", |
| 30 | }); |
| 31 | }, |
| 32 | }); |
| 33 | }); |
| 34 | }; |