blob: e810c37e48716c13a581c7a8dbd27110a486c1ee [file] [log] [blame]
Deepesh Gargbb5387f2023-07-07 10:49:56 +05301$(document).on("toolbar_setup", function() {
Deepesh Garg371413a2023-07-29 22:39:07 +05302 if (frappe.boot.sysdefaults.demo_company) {
3 erpnext.setup_clear_button();
4 }
Ankush Menat3a21c902023-08-10 15:48:57 +05305
6 // for first load
7 frappe.realtime.on("demo_data_complete", () => {
8 erpnext.setup_clear_button();
9 })
Deepesh Gargbb5387f2023-07-07 10:49:56 +053010});
11
Deepesh Garg371413a2023-07-29 22:39:07 +053012erpnext.setup_clear_button = function() {
Ankush Menat3a21c902023-08-10 15:48:57 +053013 let message_string = __("Demo data is present on the system, erase data before starting real usage.");
Deepesh Garg371413a2023-07-29 22:39:07 +053014 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 Garg371413a2023-07-29 22:39:07 +053018 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 Menat3a21c902023-08-10 15:48:57 +053041 Clear Demo Data
Deepesh Garg371413a2023-07-29 22:39:07 +053042 </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 Menat3a21c902023-08-10 15:48:57 +053061}