[IMP] ActionManager: keepSearchView option
This rev. introduces an option to doAction (keepSearchView). If set to true, the searchView of the current action will be kept and used by the new action (this only works if there is already an action with a searchView, and if the new action is stacked over that one). This is necessary for the new dashboard view. A better solution would have been to export the state of the existing searchView, and import it to the new one, but the current implementation of the searchView doesn't allow to do that easily. This will be done as soon as the searchView will be rewrote.
This commit is contained in:
committed by
Géry Debongnie
parent
5b3cb812be
commit
69c9500e35
@@ -121,6 +121,22 @@ ActionManager.include({
|
||||
* @returns {Deferred} resolved with the search view when it is ready
|
||||
*/
|
||||
_createSearchView: function (action) {
|
||||
// if requested, keep the searchview of the current action instead of
|
||||
// creating a new one
|
||||
if (action._keepSearchView) {
|
||||
var currentAction = this.getCurrentAction();
|
||||
if (currentAction) {
|
||||
action.searchView = currentAction.searchView;
|
||||
action.env = currentAction.env; // make those actions share the same env
|
||||
return $.when(currentAction.searchView);
|
||||
} else {
|
||||
// there is not searchview to keep, so reset the flag to false
|
||||
// to ensure that the one that will be created will be correctly
|
||||
// destroyed
|
||||
action._keepSearchView = false;
|
||||
}
|
||||
}
|
||||
|
||||
// AAB: temporarily create a dataset, until the SearchView is refactored
|
||||
// and stops using it
|
||||
var dataset = new data.DataSetSearch(this, action.res_model, action.context, action.domain);
|
||||
@@ -254,7 +270,7 @@ ActionManager.include({
|
||||
// its reference is removed
|
||||
controllerDef.reject();
|
||||
});
|
||||
if (action.searchView) {
|
||||
if (action.searchView && !action._keepSearchView) {
|
||||
action.searchView.destroy();
|
||||
}
|
||||
},
|
||||
@@ -483,6 +499,20 @@ ActionManager.include({
|
||||
}
|
||||
return this.loadViews(action.res_model, action.context, views, options);
|
||||
},
|
||||
/**
|
||||
* Overrides to handle the 'keepSearchView' option. If set to true, the
|
||||
* search view of the current action will be re-used in the new action, i.e.
|
||||
* the environment (domain, context, groupby) will be shared between both
|
||||
* actions.
|
||||
*
|
||||
* @override
|
||||
*/
|
||||
_preprocessAction: function (action, options) {
|
||||
this._super.apply(this, arguments);
|
||||
if (action.type === 'ir.actions.act_window' && options.keepSearchView) {
|
||||
action._keepSearchView = true;
|
||||
}
|
||||
},
|
||||
/**
|
||||
* Processes the search data sent by the search view.
|
||||
*
|
||||
|
||||
@@ -126,6 +126,9 @@ QUnit.module('ActionManager', {
|
||||
|
||||
// search views
|
||||
'partner,false,search': '<search><field name="foo" string="Foo"/></search>',
|
||||
'partner,1,search': '<search>' +
|
||||
'<filter name="bar" help="Bar" domain="[(\'bar\', \'=\', 1)]"/>' +
|
||||
'</search>',
|
||||
'pony,false,search': '<search></search>',
|
||||
};
|
||||
},
|
||||
@@ -2714,13 +2717,6 @@ QUnit.module('ActionManager', {
|
||||
},
|
||||
});
|
||||
|
||||
_.extend(this.archs, {
|
||||
'partner,7,search':
|
||||
'<search>' +
|
||||
'<filter name="bar" help="Bar" domain="[(\'bar\', \'=\', 1)]"/>' +
|
||||
'</search>',
|
||||
});
|
||||
|
||||
this.actions.push({
|
||||
id: 33,
|
||||
context: {
|
||||
@@ -2728,7 +2724,7 @@ QUnit.module('ActionManager', {
|
||||
},
|
||||
name: 'Partners',
|
||||
res_model: 'partner',
|
||||
search_view_id: [7, 'a custom search view'],
|
||||
search_view_id: [1, 'a custom search view'],
|
||||
type: 'ir.actions.act_window',
|
||||
views: [[false, 'list']],
|
||||
});
|
||||
@@ -2792,6 +2788,46 @@ QUnit.module('ActionManager', {
|
||||
actionManager.destroy();
|
||||
});
|
||||
|
||||
QUnit.test("doAction with option 'keepSearchView'", function (assert) {
|
||||
assert.expect(4);
|
||||
|
||||
this.actions.push({
|
||||
id: 33,
|
||||
name: 'Partners',
|
||||
res_model: 'partner',
|
||||
search_view_id: [1, 'a specific search view'],
|
||||
type: 'ir.actions.act_window',
|
||||
views: [[false, 'list']],
|
||||
});
|
||||
|
||||
var checkRPC = false;
|
||||
var actionManager = createActionManager({
|
||||
actions: this.actions,
|
||||
archs: this.archs,
|
||||
data: this.data,
|
||||
mockRPC: function (route, args) {
|
||||
if (checkRPC && route === '/web/dataset/search_read') {
|
||||
assert.deepEqual(args.domain, [['bar', '=', 1]],
|
||||
"should search with the correct domain");
|
||||
}
|
||||
return this._super.apply(this, arguments);
|
||||
},
|
||||
});
|
||||
|
||||
actionManager.doAction(33);
|
||||
|
||||
checkRPC = true;
|
||||
$('.o_control_panel .o_filters_menu a:contains(Bar)').click(); // filter on bar
|
||||
assert.strictEqual($('.o_control_panel .o_facet_values').text().trim(), 'Bar',
|
||||
"the filter on Bar should appear in the search view");
|
||||
|
||||
actionManager.doAction(3, {keepSearchView: true});
|
||||
assert.strictEqual($('.o_control_panel .o_facet_values').text().trim(), 'Bar',
|
||||
"the filter on Bar should still be in the search view");
|
||||
|
||||
actionManager.destroy();
|
||||
});
|
||||
|
||||
QUnit.module('Actions in target="new"');
|
||||
|
||||
QUnit.test('can execute act_window actions in target="new"', function (assert) {
|
||||
|
||||
Reference in New Issue
Block a user