fix: confirm before clearing demo data

This commit is contained in:
Ankush Menat
2023-08-10 17:55:15 +05:30
parent e4b863af05
commit 8bdf280cfb

View File

@@ -1,4 +1,4 @@
$(document).on("toolbar_setup", function() { $(document).on("toolbar_setup", function () {
if (frappe.boot.sysdefaults.demo_company) { if (frappe.boot.sysdefaults.demo_company) {
erpnext.setup_clear_button(); erpnext.setup_clear_button();
} }
@@ -6,11 +6,13 @@ $(document).on("toolbar_setup", function() {
// for first load // for first load
frappe.realtime.on("demo_data_complete", () => { frappe.realtime.on("demo_data_complete", () => {
erpnext.setup_clear_button(); erpnext.setup_clear_button();
}) });
}); });
erpnext.setup_clear_button = function() { erpnext.setup_clear_button = function () {
let message_string = __("Demo data is present on the system, erase data before starting real usage."); let message_string = __(
"Demo data is present on the system, erase data before starting real usage."
);
let $floatingBar = $(` let $floatingBar = $(`
<div class="flex justify-content-center" style="width: 100%;"> <div class="flex justify-content-center" style="width: 100%;">
<div class="flex justify-content-center flex-col shadow rounded p-2" <div class="flex justify-content-center flex-col shadow rounded p-2"
@@ -44,18 +46,26 @@ erpnext.setup_clear_button = function() {
</div> </div>
`); `);
$('footer').append($floatingBar); $("footer").append($floatingBar);
$('#clear-demo').on('click', function () { $("#clear-demo").on("click", function () {
frappe.call({ frappe.confirm(
method: "erpnext.setup.demo.clear_demo_data", __("Are you sure you want to clear all demo data?"),
freeze: true, () => {
freeze_message: __('Clearing Demo Data...'), frappe.call({
callback: function(r) { method: "erpnext.setup.demo.clear_demo_data",
frappe.ui.toolbar.clear_cache(); freeze: true,
frappe.show_alert({ message: __('Demo data cleared'), indicator: 'green' }); freeze_message: __("Clearing Demo Data..."),
$('footer').remove($floatingBar); callback: function (r) {
frappe.ui.toolbar.clear_cache();
frappe.show_alert({
message: __("Demo data cleared"),
indicator: "green",
});
$("footer").remove($floatingBar);
},
});
} }
}) );
}); });
} };