diff --git a/frappe/public/js/frappe/list/base_list.js b/frappe/public/js/frappe/list/base_list.js index c725b774de..18d4257876 100644 --- a/frappe/public/js/frappe/list/base_list.js +++ b/frappe/public/js/frappe/list/base_list.js @@ -6,7 +6,11 @@ frappe.views.BaseList = class BaseList { } show() { - this.init().then(() => this.refresh()); + frappe.run_serially([ + () => this.init(), + () => this.before_refresh(), + () => this.refresh() + ]); } init() { @@ -344,6 +348,11 @@ frappe.views.BaseList = class BaseList { }; } + before_refresh() { + // modify args here just before making the request + // see list_view.js + } + refresh() { this.freeze(true); // fetch data from server diff --git a/frappe/public/js/frappe/list/list_view.js b/frappe/public/js/frappe/list/list_view.js index 8a633ac7d3..433dd286a3 100644 --- a/frappe/public/js/frappe/list/list_view.js +++ b/frappe/public/js/frappe/list/list_view.js @@ -34,7 +34,7 @@ frappe.views.ListView = class ListView extends frappe.views.BaseList { return; } - this.init().then(() => this.refresh()); + super.show(); } get view_name() { @@ -48,25 +48,6 @@ frappe.views.ListView = class ListView extends frappe.views.BaseList { setup_defaults() { super.setup_defaults(); - if (frappe.route_options) { - // Priority 1: route filters - this.filters = this.parse_filters_from_route_options(); - } else if (this.view_user_settings.filters) { - // Priority 2: saved filters - const saved_filters = this.view_user_settings.filters; - this.filters = this.validate_filters(saved_filters); - } else { - // Priority 3: filters in listview_settings - const filters = (this.settings.filters || []).map(f => { - if (f.length === 3) { - f = [this.doctype, f[0], f[1], f[2]]; - } - return f; - }); - - this.filters = filters; - } - // initialize with saved order by this.sort_by = this.view_user_settings.sort_by || 'modified'; this.sort_order = this.view_user_settings.sort_order || 'desc'; @@ -283,6 +264,32 @@ frappe.views.ListView = class ListView extends frappe.views.BaseList { }); } + before_refresh() { + if (frappe.route_options) { + // Priority 1: route filters + this.filters = this.parse_filters_from_route_options(); + } else if (this.view_user_settings.filters) { + // Priority 2: saved filters + const saved_filters = this.view_user_settings.filters; + this.filters = this.validate_filters(saved_filters); + } else { + // Priority 3: filters in listview_settings + this.filters = (this.settings.filters || []).map(f => { + if (f.length === 3) { + f = [this.doctype, f[0], f[1], f[2]]; + } + return f; + }); + } + + if (this.filters.length) { + return this.filter_area.clear(false) + .then(() => this.filter_area.set(this.filters)); + } + + return Promise.resolve(); + } + toggle_result_area() { super.toggle_result_area(); this.toggle_actions_menu_button(