diff --git a/addons/web/static/src/js/widgets/domain_selector.js b/addons/web/static/src/js/widgets/domain_selector.js index dab0c97108b..948706cbd07 100644 --- a/addons/web/static/src/js/widgets/domain_selector.js +++ b/addons/web/static/src/js/widgets/domain_selector.js @@ -59,6 +59,8 @@ var DomainNode = Widget.extend({ * @param {Array|string} domain - the prefix representation of the domain * @param {Object} [options] - an object with possible values: * @param {boolean} [options.readonly=true] - true if is readonly + * @param {Array} [options.default] - default domain used when creating a + * new node * @param {string[]} [options.operators=null] * a list of available operators (null = all of supported ones) * @param {boolean} [options.debugMode=false] - true if should be in debug @@ -409,7 +411,7 @@ var DomainTree = DomainNode.extend({ * @param {OdooEvent} e */ _onNodeAdditionAsk: function (e) { - var domain = [["id", "=", 1]]; + var domain = this.options.default || [["id", "=", 1]]; if (e.data.newBranch) { domain = [this.operator === "&" ? "|" : "&"].concat(domain).concat(domain); } @@ -548,7 +550,7 @@ var DomainSelector = DomainTree.extend({ * node */ _onAddFirstButtonClick: function () { - this._addChild([["id", "=", 1]]); + this._addChild(this.options.default || [["id", "=", 1]]); }, /** * Called when the debug input value is changed -> constructs the tree diff --git a/addons/web/static/tests/widgets/domain_selector_tests.js b/addons/web/static/tests/widgets/domain_selector_tests.js index aca017e831c..20ea5d86297 100644 --- a/addons/web/static/tests/widgets/domain_selector_tests.js +++ b/addons/web/static/tests/widgets/domain_selector_tests.js @@ -213,6 +213,32 @@ QUnit.module('DomainSelector', { domainSelector.destroy(); }); + + QUnit.test("creating a domain with a default option", function (assert) { + assert.expect(1); + + var $target = $("#qunit-fixture"); + + // Create the domain selector and its mock environment + var domainSelector = new DomainSelector(null, "partner", [], { + readonly: false, + debugMode: true, + default: [["foo","=","kikou"]], + }); + testUtils.addMockEnvironment(domainSelector, {data: this.data}); + domainSelector.appendTo($target); + + // Clicking on the button should add a visible field selector in the + // widget so that the user can change the field chain + domainSelector.$(".o_domain_add_first_node_button:visible").click(); + + assert.strictEqual( + domainSelector.$(".o_domain_debug_input").val(), + '[["foo","=","kikou"]]', + "the domain input should contain the default domain"); + + domainSelector.destroy(); + }); }); }); });