diff options
| author | Christophe Matthieu <chm@odoo.com> | 2018-07-25 11:51:20 +0200 |
|---|---|---|
| committer | Christophe Matthieu <chm@odoo.com> | 2018-08-13 17:09:28 +0200 |
| commit | 32b269d3d55e423604d093db4d98e6c56cab672d (patch) | |
| tree | e200b484fe5ae638a2600dcad991f4850801916d /addons/web/static | |
| parent | 061175e598939ff30c992bf606f5c9e200854072 (diff) | |
[IMP] web: add `default` option to DomainSelector
This option is used to set a default domain value when creating a new node
(instead of [['id', '=', 1]]).
Diffstat (limited to 'addons/web/static')
| -rw-r--r-- | addons/web/static/src/js/widgets/domain_selector.js | 6 | ||||
| -rw-r--r-- | addons/web/static/tests/widgets/domain_selector_tests.js | 26 |
2 files changed, 30 insertions, 2 deletions
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(); + }); }); }); }); |
