From abdb5455d1954f2fab4d5def42c6b99590067eae Mon Sep 17 00:00:00 2001 From: Petr Vobornik Date: Fri, 5 Apr 2013 18:38:02 +0200 Subject: Add pre and post build operations https://fedorahosted.org/freeipa/ticket/3235 --- install/ui/src/freeipa/_base/Builder.js | 76 ++++++++++--- install/ui/src/freeipa/_base/Construct_registry.js | 125 ++++++++++++++++++--- install/ui/src/freeipa/_base/construct.js | 20 ++++ 3 files changed, 190 insertions(+), 31 deletions(-) (limited to 'install/ui/src') diff --git a/install/ui/src/freeipa/_base/Builder.js b/install/ui/src/freeipa/_base/Builder.js index d7503526..10c544cc 100644 --- a/install/ui/src/freeipa/_base/Builder.js +++ b/install/ui/src/freeipa/_base/Builder.js @@ -41,17 +41,19 @@ define(['dojo/_base/declare', /** * Build object based on spec. * - * @param spec {String|Function|Object} Build spec + * @param {String|Function|Object} Build spec * * String: type name, queries registry * Function: factory or constructor * Object: spec object * * Build control properies of spec object: - * constructor: Function - * factory: Function - * mixim_spec: Boolean - * type: String + * $constructor: Function + * $factory: Function + * $mixim_spec: Boolean + * $type: String + * $pre_ops: [] + * $post_ops: [] * * All other properties will be passed to object construction method. */ @@ -78,16 +80,20 @@ define(['dojo/_base/declare', // spec is type name cs = this._query_registry(spec); } else if (typeof spec === 'object') { - var c = spec.constructor, - f = spec.factory, - m = spec.mixim_spec, - t = spec.type; + var c = spec.$constructor, + f = spec.$factory, + m = spec.$mixim_spec, + t = spec.$type, + pre = spec.$pre_ops, + post = spec.$post_ops; var s = lang.clone(spec); - delete s.constructor; - delete s.factory; - delete s.mixim_spec; - delete s.type; + delete s.$constructor; + delete s.$factory; + delete s.$mixim_spec; + delete s.$type; + delete s.$pre_ops; + delete s.$post_ops; if (c) { cs.constructor = c; @@ -105,19 +111,30 @@ define(['dojo/_base/declare', cs.spec = s; } } + + cs.pre_ops = cs.pre_ops || []; + cs.post_ops = cs.post_ops || []; + if (pre) cs.pre_ops.push.call(cs.pre_ops, pre); + if (pre) cs.post_ops.push.call(cs.post_ops, post); } return cs; }, + /** + * Queries registry and returns copy of construction specification + */ _query_registry: function(type) { if (this.registry) { - return this.registry.get(type); + var cs = this.registry.get(type); + if (!cs) throw construct.no_cs_for_type_error(type); + cs = construct.copy_cs(cs); + return cs; } else { throw { error: 'Build error: construct registry required', - spec: type + builder: this }; } }, @@ -125,7 +142,22 @@ define(['dojo/_base/declare', _build: function(construction_spec) { var cs = construction_spec, - obj = null; + obj = null, + i; + + if (cs.pre_ops) { + for (i=0; i