blob: 22d78d8c67cc8ae124c285d63994e3d774b11cd2 [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 }
Deepesh Gargbb5387f2023-07-07 10:49:56 +05305});
6
Deepesh Garg371413a2023-07-29 22:39:07 +05307erpnext.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}