[FIX] web: create favorite filters in dialogs
Consider the following scenario: open in edit mode a form view containing a many2many field displayed with widget many2many_tags, on the many2many field dropdown, click on 'Search More' (it opens a dialog), and in the dialog, try to save the current search in the searchview's favorite menu. Before this rev., it tried to retrieve the context of the active view in the closest instance of a ViewManager-like widget in the SearchView's ancestors. First, it is wrong as in the given scenario, the requested context is actually the one of the list controller in the dialog, not the one of the form controller in the background. Second, it produces a crash in Studio, when trying to save filters in the dialog opened by clicking on 'Search More' on the groups many2many field in the sidebar. This part of the code can't be tested in this version, but tests will be added in master. Fixes #23293
This commit is contained in:
@@ -15,6 +15,9 @@ var _t = core._t;
|
||||
|
||||
var ViewManager = Widget.extend(ControlPanelMixin, {
|
||||
className: "o_view_manager_content",
|
||||
custom_events: {
|
||||
get_controller_context: '_onGetControllerContext',
|
||||
},
|
||||
/**
|
||||
* Called each time the view manager is attached into the DOM
|
||||
*/
|
||||
@@ -474,6 +477,25 @@ var ViewManager = Widget.extend(ControlPanelMixin, {
|
||||
}
|
||||
return this._super.apply(this, arguments);
|
||||
},
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Handlers
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
// ONLY FORWARDPORT THIS COMMIT UP TO SAAS-15
|
||||
/**
|
||||
* Handles a context request: provides to the caller the context of the
|
||||
* active view.
|
||||
*
|
||||
* @private
|
||||
* @param {OdooEvent} ev
|
||||
* @param {function} ev.data.callback used to send the requested context
|
||||
*/
|
||||
_onGetControllerContext: function (ev) {
|
||||
var controller = this.active_view && this.active_view.controller;
|
||||
var context = controller && controller.get_context();
|
||||
ev.data.callback(context);
|
||||
},
|
||||
});
|
||||
|
||||
return ViewManager;
|
||||
|
||||
@@ -976,6 +976,9 @@ var SelectCreateListView = ListView.extend({
|
||||
* Search dialog (displays a list of records and permits to create a new one by switching to a form view)
|
||||
*/
|
||||
var SelectCreateDialog = ViewDialog.extend({
|
||||
custom_events: {
|
||||
get_controller_context: '_onGetControllerContext',
|
||||
},
|
||||
/**
|
||||
* options:
|
||||
* - initial_ids
|
||||
@@ -1106,6 +1109,23 @@ var SelectCreateDialog = ViewDialog.extend({
|
||||
return new FormViewDialog(this.__parentedParent, this.options).open();
|
||||
},
|
||||
on_view_list_loaded: function() {},
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Handlers
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Handles a context request: provides to the caller the context of the
|
||||
* list view.
|
||||
*
|
||||
* @private
|
||||
* @param {OdooEvent} ev
|
||||
* @param {function} ev.data.callback used to send the requested context
|
||||
*/
|
||||
_onGetControllerContext: function (ev) {
|
||||
var context = this.view_list.get_context();
|
||||
ev.data.callback(context);
|
||||
},
|
||||
});
|
||||
|
||||
var DomainEditorDialog = SelectCreateDialog.extend({
|
||||
|
||||
@@ -93,13 +93,15 @@ return Widget.extend({
|
||||
this.$inputs.first().focus();
|
||||
return;
|
||||
}
|
||||
var search = this.searchview.build_search_data(),
|
||||
view_manager = this.findAncestor(function (a) {
|
||||
// HORRIBLE HACK. PLEASE SAVE ME FROM MYSELF (BUT IN A PAINLESS WAY IF POSSIBLE)
|
||||
return 'active_view' in a;
|
||||
}),
|
||||
view_context = view_manager ? view_manager.active_view.controller.get_context() : {},
|
||||
results = pyeval.sync_eval_domains_and_contexts({
|
||||
var search = this.searchview.build_search_data();
|
||||
// ONLY FORWARDPORT THIS COMMIT UP TO SAAS-15
|
||||
var view_context;
|
||||
this.trigger_up('get_controller_context', {
|
||||
callback: function (ctx) {
|
||||
view_context = ctx;
|
||||
},
|
||||
});
|
||||
var results = pyeval.sync_eval_domains_and_contexts({
|
||||
domains: search.domains,
|
||||
contexts: search.contexts.concat(view_context || []),
|
||||
group_by_seq: search.groupbys || [],
|
||||
|
||||
Reference in New Issue
Block a user