diff --git a/frappe/core/doctype/communication/communication.js b/frappe/core/doctype/communication/communication.js index 86ef59f994..d6103636e8 100644 --- a/frappe/core/doctype/communication/communication.js +++ b/frappe/core/doctype/communication/communication.js @@ -211,8 +211,7 @@ frappe.ui.form.on("Communication", { ], primary_action_label: __("Move"), primary_action(values) { - d.hide(); - frappe.call({ + return frappe.call({ method: "frappe.email.inbox.move_email", args: { communication: frm.doc.name, @@ -220,6 +219,7 @@ frappe.ui.form.on("Communication", { }, freeze: true, callback: function () { + d.hide(); window.history.back(); }, }); diff --git a/frappe/core/doctype/doctype/doctype_list.js b/frappe/core/doctype/doctype/doctype_list.js index 46b5e5b99d..3bb353c266 100644 --- a/frappe/core/doctype/doctype/doctype_list.js +++ b/frappe/core/doctype/doctype/doctype_list.js @@ -103,7 +103,7 @@ frappe.listview_settings["DocType"] = { primary_action_label: __("Create & Continue"), primary_action(values) { if (!values.istable) values.editable_grid = 0; - frappe.db + return frappe.db .insert({ doctype: "DocType", ...values, diff --git a/frappe/core/doctype/user/user.js b/frappe/core/doctype/user/user.js index 4be1cfadec..3e9ff32d5e 100644 --- a/frappe/core/doctype/user/user.js +++ b/frappe/core/doctype/user/user.js @@ -201,18 +201,19 @@ frappe.ui.form.on("User", { }, ], primary_action: (values) => { - d.hide(); if (values.new_password !== values.confirm_password) { frappe.throw(__("Passwords do not match!")); } - frappe.call( - "frappe.integrations.doctype.ldap_settings.ldap_settings.reset_password", - { - user: frm.doc.email, - password: values.new_password, - logout: values.logout_sessions, - } - ); + return frappe + .call( + "frappe.integrations.doctype.ldap_settings.ldap_settings.reset_password", + { + user: frm.doc.email, + password: values.new_password, + logout: values.logout_sessions, + } + ) + .then(() => d.hide()); }, }); d.show(); diff --git a/frappe/core/report/database_storage_usage_by_tables/database_storage_usage_by_tables.js b/frappe/core/report/database_storage_usage_by_tables/database_storage_usage_by_tables.js index 5a1ae6f87a..093016705e 100644 --- a/frappe/core/report/database_storage_usage_by_tables/database_storage_usage_by_tables.js +++ b/frappe/core/report/database_storage_usage_by_tables/database_storage_usage_by_tables.js @@ -25,7 +25,7 @@ frappe.query_reports["Database Storage Usage By Tables"] = { size: "small", primary_action_label: "Optimize", primary_action(values) { - frappe.call({ + return frappe.call({ method: "frappe.core.report.database_storage_usage_by_tables.database_storage_usage_by_tables.optimize_doctype", args: { doctype_name: values.doctype_name, @@ -38,9 +38,9 @@ frappe.query_reports["Database Storage Usage By Tables"] = { ) ); } + d.hide(); }, }); - d.hide(); }, }); d.show(); diff --git a/frappe/public/js/frappe/file_uploader/FileUploader.vue b/frappe/public/js/frappe/file_uploader/FileUploader.vue index 10012c82ad..f21d925efe 100644 --- a/frappe/public/js/frappe/file_uploader/FileUploader.vue +++ b/frappe/public/js/frappe/file_uploader/FileUploader.vue @@ -514,22 +514,7 @@ function check_restrictions(file) { return is_correct_type && valid_file_size; } -function set_loading_state(dialog, loading) { - let $btn = dialog?.get_primary_btn(); - if (loading) { - $btn?.css("width", $btn.outerWidth()); - $btn?.html(``); - $btn?.prop("disabled", true); - dialog?.get_secondary_btn().prop("disabled", true); - } else { - $btn?.css("width", ""); - $btn?.html(__("Upload")); - $btn?.prop("disabled", false); - dialog?.get_secondary_btn().prop("disabled", false); - } -} -function upload_files(dialog) { - set_loading_state(dialog, true); +function upload_files() { if (show_file_browser.value) { promise = upload_via_file_browser(); } else if (show_web_link.value) { @@ -542,7 +527,7 @@ function upload_files(dialog) { } else { promise = frappe.run_serially(files.value.map((file, i) => () => upload_file(file, i))); } - return promise.finally(() => set_loading_state(dialog, false)); + return promise; } function upload_via_file_browser() { let selected_file = file_browser.value.selected_node; diff --git a/frappe/public/js/frappe/file_uploader/file_uploader.bundle.js b/frappe/public/js/frappe/file_uploader/file_uploader.bundle.js index 44e9d9add6..999cc675ea 100644 --- a/frappe/public/js/frappe/file_uploader/file_uploader.bundle.js +++ b/frappe/public/js/frappe/file_uploader/file_uploader.bundle.js @@ -151,6 +151,7 @@ class FileUploader { const dialog_opts = { title: title || __("Upload"), primary_action_label: __("Upload"), + primary_action_loading_label: __("Uploading"), primary_action: () => this.upload_files(), on_page_show: () => { this.uploader.wrapper_ready = true; diff --git a/frappe/public/js/frappe/form/reminders.js b/frappe/public/js/frappe/form/reminders.js index 5c8fa16060..667ca805d6 100644 --- a/frappe/public/js/frappe/form/reminders.js +++ b/frappe/public/js/frappe/form/reminders.js @@ -48,8 +48,7 @@ export class ReminderManager { ], primary_action_label: __("Create"), primary_action: () => { - this.create_reminder(); - this.dialog.hide(); + return this.create_reminder().then(() => this.dialog.hide()); }, secondary_action_label: __("Cancel"), secondary_action: () => { @@ -84,7 +83,7 @@ export class ReminderManager { } create_reminder() { - frappe + return frappe .xcall("frappe.automation.doctype.reminder.reminder.create_new_reminder", { remind_at: this.dialog.get_value("remind_at"), description: this.dialog.get_value("description"), diff --git a/frappe/public/js/frappe/form/sidebar/assign_to.js b/frappe/public/js/frappe/form/sidebar/assign_to.js index 6b867fdf51..4b487f2c08 100644 --- a/frappe/public/js/frappe/form/sidebar/assign_to.js +++ b/frappe/public/js/frappe/form/sidebar/assign_to.js @@ -114,9 +114,7 @@ frappe.ui.form.AssignToDialog = class AssignToDialog { let args = me.dialog.get_values(); if (args && args.assign_to) { - me.dialog.set_message("Assigning..."); - - frappe.call({ + return frappe.call({ method: me.method, args: $.extend(args, { doctype: me.doctype, @@ -125,15 +123,12 @@ frappe.ui.form.AssignToDialog = class AssignToDialog { bulk_assign: me.bulk_assign || false, re_assign: me.re_assign || false, }), - btn: me.dialog.get_primary_btn(), callback: function (r) { if (!r.exc) { if (me.callback) { me.callback(r); } me.dialog && me.dialog.hide(); - } else { - me.dialog.clear_message(); } }, }); diff --git a/frappe/public/js/frappe/list/bulk_operations.js b/frappe/public/js/frappe/list/bulk_operations.js index dd85c3da0d..0b794a03c3 100644 --- a/frappe/public/js/frappe/list/bulk_operations.js +++ b/frappe/public/js/frappe/list/bulk_operations.js @@ -452,9 +452,7 @@ export default class BulkOperations { primary_action: () => { let args = dialog.get_values(); if (args && args.tags) { - dialog.set_message("Adding Tags..."); - - frappe.call({ + return frappe.call({ method: "frappe.desk.doctype.tag.tag.add_tags", args: { tags: args.tags, diff --git a/frappe/public/js/frappe/list/list_filter.js b/frappe/public/js/frappe/list/list_filter.js index e46c59eca9..f3ff15587b 100644 --- a/frappe/public/js/frappe/list/list_filter.js +++ b/frappe/public/js/frappe/list/list_filter.js @@ -120,7 +120,7 @@ export default class ListFilter { fields: fields, primary_action_label: __("Create"), primary_action: (values) => { - this.bind_save_filter(dialog, values.filter_name, values?.is_global); + return this.bind_save_filter(dialog, values.filter_name, values?.is_global); }, }); dialog.show(); @@ -138,7 +138,7 @@ export default class ListFilter { dialog.fields_dict.filter_name.set_description(__("Duplicate Filter Name")); return; } - this.save_filter(value, is_global).then(() => { + return this.save_filter(value, is_global).then(() => { this.refresh_list_filter(); dialog.hide(); }); diff --git a/frappe/public/js/frappe/ui/address_autocomplete/autocomplete_dialog.js b/frappe/public/js/frappe/ui/address_autocomplete/autocomplete_dialog.js index 53d8405ceb..3fb854c15d 100644 --- a/frappe/public/js/frappe/ui/address_autocomplete/autocomplete_dialog.js +++ b/frappe/public/js/frappe/ui/address_autocomplete/autocomplete_dialog.js @@ -48,9 +48,6 @@ frappe.ui.AddressAutocompleteDialog = class AddressAutocompleteDialog { ], primary_action_label: __("Create Address"), primary_action: () => { - // Insert the address into the database - dialog.hide(); - const address = this.parse_selected_value(); address["doctype"] = "Address"; address["links"] = [ @@ -59,7 +56,8 @@ frappe.ui.AddressAutocompleteDialog = class AddressAutocompleteDialog { link_name: this.link_name, }, ]; - frappe.db.insert(address).then((doc) => { + return frappe.db.insert(address).then((doc) => { + dialog.hide(); this.after_insert && this.after_insert(doc); }); }, diff --git a/frappe/public/js/frappe/ui/dialog.js b/frappe/public/js/frappe/ui/dialog.js index 036dc0c1cd..40a491a03d 100644 --- a/frappe/public/js/frappe/ui/dialog.js +++ b/frappe/public/js/frappe/ui/dialog.js @@ -207,6 +207,7 @@ frappe.ui.Dialog = class Dialog extends frappe.ui.FieldGroup { this.has_primary_action = true; var me = this; const primary_btn = this.get_primary_btn().removeClass("hide").html(label); + const spinner = ``; if (typeof click == "function") { primary_btn.off("click").on("click", function () { me.primary_action_fulfilled = true; @@ -215,7 +216,35 @@ frappe.ui.Dialog = class Dialog extends frappe.ui.FieldGroup { // if no values then return var values = me.get_values(); if (!values) return; - click && click.apply(me, [values]); + const action = click.apply(me, [values]); + if (action && typeof action.then === "function") { + const loading_label = me.primary_action_loading_label; + primary_btn + .css({ + "min-width": primary_btn.outerWidth(), + "min-height": primary_btn.outerHeight(), + }) + .prop("disabled", true) + .addClass("btn-primary-dark") + .html( + `