[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]]).
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user