From 1221fca6628450c6cd3031b377c7426fa4b1b0ad Mon Sep 17 00:00:00 2001 From: Petr Vobornik Date: Tue, 16 Apr 2013 12:55:36 +0200 Subject: Builder: allow string spec as spec property instead of type https://fedorahosted.org/freeipa/ticket/3235 --- install/ui/src/freeipa/_base/Builder.js | 42 +++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) (limited to 'install/ui/src/freeipa/_base') diff --git a/install/ui/src/freeipa/_base/Builder.js b/install/ui/src/freeipa/_base/Builder.js index 124d5ddb4..cfbda097c 100644 --- a/install/ui/src/freeipa/_base/Builder.js +++ b/install/ui/src/freeipa/_base/Builder.js @@ -55,6 +55,28 @@ define(['dojo/_base/declare', pre_ops: null, + /** + * Controls what builder do when spec is a string. Possible values: + * * 'type' + * * 'property' + * Type: + * Spec is type. Queries registry for obtaining construction spec. + * + * Property: + * Spec is a property of spec, name of property is set in + * `string_property`. This mode should be combined with default + * factory or ctor otherwise the build will fail. + * + * @type {String} + */ + string_mode: 'type', + + /** + * Property name for `string_mode` == `property` + * @type {String} + */ + string_property: '', + /** * Build object based on spec. * @@ -141,8 +163,8 @@ define(['dojo/_base/declare', cs.factory = spec; } } else if (typeof spec === 'string') { - // spec is type name - cs = this._query_registry(spec); + // spec is type name or spec property + cs = this._get_cs_string(spec); } else if (typeof spec === 'object') { var c = spec.$ctor, f = spec.$factory, @@ -206,6 +228,22 @@ define(['dojo/_base/declare', } }, + /** + * Get cs from string according to string mode + */ + _get_cs_string: function(spec) { + + var cs; + if (this.string_mode === 'type') { + cs = this._query_registry(spec); + } else { + var sp = {}; + sp[this.string_property] = spec; + cs = { spec: sp }; + } + return cs; + }, + _build_core: function(construction_spec, context) { var cs = construction_spec, -- cgit