blob: 05866e98647e293ab1b27c3f86e8850a9cdbeb03 [file] [log] [blame]
Ankush Menat8bdf2802023-08-10 17:55:15 +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();
Ankush Menat8bdf2802023-08-10 17:55:15 +05309 });
Deepesh Gargbb5387f2023-07-07 10:49:56 +053010});
11
Ankush Menat8bdf2802023-08-10 17:55:15 +053012erpnext.setup_clear_button = function () {
13 let message_string = __(
14 "Demo data is present on the system, erase data before starting real usage."
15 );
Deepesh Garg371413a2023-07-29 22:39:07 +053016 let $floatingBar = $(`
17 <div class="flex justify-content-center" style="width: 100%;">
18 <div class="flex justify-content-center flex-col shadow rounded p-2"
19 style="
Deepesh Garg371413a2023-07-29 22:39:07 +053020 background-color: #e0f2fe;
21 position: fixed;
22 bottom: 20px;
23 z-index: 1;">
24 <p style="margin: auto 0; padding-left: 10px; margin-right: 20px; font-size: 15px;">
25 ${message_string}
26 </p>
27 <button id="clear-demo" type="button"
28 class="
29 px-4
30 py-2
31 border
32 border-transparent
33 text-white
34 "
35 style="
36 margin: auto 0;
37 height: fit-content;
38 background-color: #007bff;
39 border-radius: 5px;
40 margin-right: 10px
41 "
42 >
Ankush Menat3a21c902023-08-10 15:48:57 +053043 Clear Demo Data
Deepesh Garg371413a2023-07-29 22:39:07 +053044 </button>
45 </div>
46 </div>
47 `);
48
Ankush Menat8bdf2802023-08-10 17:55:15 +053049 $("footer").append($floatingBar);
Deepesh Garg371413a2023-07-29 22:39:07 +053050
Ankush Menat8bdf2802023-08-10 17:55:15 +053051 $("#clear-demo").on("click", function () {
52 frappe.confirm(
53 __("Are you sure you want to clear all demo data?"),
54 () => {
55 frappe.call({
56 method: "erpnext.setup.demo.clear_demo_data",
57 freeze: true,
58 freeze_message: __("Clearing Demo Data..."),
59 callback: function (r) {
60 frappe.ui.toolbar.clear_cache();
61 frappe.show_alert({
62 message: __("Demo data cleared"),
63 indicator: "green",
64 });
65 $("footer").remove($floatingBar);
66 },
67 });
Deepesh Garg371413a2023-07-29 22:39:07 +053068 }
Ankush Menat8bdf2802023-08-10 17:55:15 +053069 );
Deepesh Garg371413a2023-07-29 22:39:07 +053070 });
Ankush Menat8bdf2802023-08-10 17:55:15 +053071};