diff options
author | Petr Vobornik <pvoborni@redhat.com> | 2015-04-28 14:22:31 +0200 |
---|---|---|
committer | Petr Vobornik <pvoborni@redhat.com> | 2015-05-20 14:04:10 +0200 |
commit | de374a0d3a1147a650b63bb5c267a857fba015dd (patch) | |
tree | ef95e1450c3e63706532b28dd337ccfb8d6e2cdf | |
parent | c352616ac9fbb1685adcbe8834143b24f6e8b5d4 (diff) | |
download | freeipa-de374a0d3a1147a650b63bb5c267a857fba015dd.tar.gz freeipa-de374a0d3a1147a650b63bb5c267a857fba015dd.tar.xz freeipa-de374a0d3a1147a650b63bb5c267a857fba015dd.zip |
webui: register construction spec based on existing spec
Useful for declarative inheritance. E.g. base new facet on details
facet with all registered preops and default spec object.
Reviewed-By: David Kupka <dkupka@redhat.com>
Reviewed-By: Thierry Bordaz <tbordaz@redhat.com>
-rw-r--r-- | install/ui/src/freeipa/_base/Builder.js | 41 | ||||
-rw-r--r-- | install/ui/src/freeipa/_base/Singleton_registry.js | 32 |
2 files changed, 50 insertions, 23 deletions
diff --git a/install/ui/src/freeipa/_base/Builder.js b/install/ui/src/freeipa/_base/Builder.js index 9433a8126..029f8947f 100644 --- a/install/ui/src/freeipa/_base/Builder.js +++ b/install/ui/src/freeipa/_base/Builder.js @@ -188,21 +188,13 @@ define(['dojo/_base/declare', }, /** - * Build single object - * @protected - */ - _build: function(spec, context) { - var cs = this._get_construction_spec(spec); - var obj = this._build_core(cs, context); - return obj; - }, - - /** - * Normalizes construction specification - * @protected + * Create new construction spec from an existing one based on object + * specification object and save the new construction spec + * + * @param {Object} spec Specification object + * @return {Object} Construction specification */ - _get_construction_spec: function(spec) { - + merge_spec: function(spec, force_mixin) { var cs = {}; if (typeof spec === 'function') { @@ -219,7 +211,7 @@ define(['dojo/_base/declare', } else if (typeof spec === 'object') { var c = spec.$ctor, f = spec.$factory, - m = spec.$mixim_spec, + m = spec.$mixim_spec || force_mixin, t = spec.$type, pre = spec.$pre_ops, post = spec.$post_ops; @@ -251,7 +243,26 @@ define(['dojo/_base/declare', if (pre) cs.pre_ops.push.apply(cs.pre_ops, pre); if (post) cs.post_ops.push.apply(cs.post_ops, post); } + return cs; + }, + + /** + * Build single object + * @protected + */ + _build: function(spec, context) { + var cs = this._get_construction_spec(spec); + var obj = this._build_core(cs, context); + return obj; + }, + + /** + * Normalizes construction specification + * @protected + */ + _get_construction_spec: function(spec) { + var cs = this.merge_spec(spec); cs.spec = cs.spec || {}; if (!cs.factory && !cs.ctor) { if (this.ctor) cs.ctor = this.ctor; diff --git a/install/ui/src/freeipa/_base/Singleton_registry.js b/install/ui/src/freeipa/_base/Singleton_registry.js index 6aa105456..0c89e65bf 100644 --- a/install/ui/src/freeipa/_base/Singleton_registry.js +++ b/install/ui/src/freeipa/_base/Singleton_registry.js @@ -106,13 +106,7 @@ define(['dojo/_base/declare', * @return {Object} */ register: function(type, func, default_spec) { - if (!lang.exists('builder.registry', this)) { - throw { - error: 'Object Initialized Exception: builder not initalized', - context: this - }; - } - + this._check_builder(); this.builder.registry.register(type, func, default_spec); }, @@ -125,13 +119,35 @@ define(['dojo/_base/declare', * @param {Object} construct_spec Construction specification */ copy: function(org_type, new_type, construct_spec) { + this._check_builder(); + this.builder.registry.copy(org_type, new_type, construct_spec); + }, + + /** + * Create new construction specification based on an existing one and + * a specification object. Save it as a new type. + * @param {string|Function} type New type or a callback to get + * the type: `callback(spec)` + * @param {Object} spec Construction specification + */ + register_from_spec: function(type, spec) { + this._check_builder(); + var cs = this.builder.merge_spec(spec, true); + if (typeof type === 'function') { + cs.type = type(cs.spec); + } else { + cs.type = type; + } + this.builder.registry.register(cs); + }, + + _check_builder: function() { if (!lang.exists('builder.registry', this)) { throw { error: 'Object Initialized Exception: builder not initalized', context: this }; } - this.builder.registry.copy(org_type, new_type, construct_spec); }, constructor: function(spec) { |