mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
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>
This commit is contained in:
@@ -188,21 +188,13 @@ define(['dojo/_base/declare',
|
||||
},
|
||||
|
||||
/**
|
||||
* Build single object
|
||||
* @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
|
||||
*/
|
||||
_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) {
|
||||
|
||||
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;
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user