From 12401fe4da9620ce7dae3339f9928f9d2a770fbd Mon Sep 17 00:00:00 2001 From: Petr Vobornik Date: Wed, 4 Apr 2012 16:23:16 +0200 Subject: [PATCH] General builder support Web UI mainly uses declarative way of defining UI structure. When a new object type is created it is often required to create a new builder which would build the objects from spec file. The builders' logic is mostly the same. This patch adds a general builder with some extendability capabilities. Now it is possible to: 1) define spec for single object and build it by calling IPA.build(spec, /* optional */ builder_fac) 2) define an array of specs and build the objects by the same call Prerequisite for following action list patches. https://fedorahosted.org/freeipa/ticket/2707 --- install/ui/ipa.js | 67 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/install/ui/ipa.js b/install/ui/ipa.js index ed380d9cb..4470d9484 100644 --- a/install/ui/ipa.js +++ b/install/ui/ipa.js @@ -964,6 +964,73 @@ IPA.concurrent_command = function(spec) { return that; }; +IPA.builder = function(spec) { + + spec = spec || {}; + + var that = {}; + + that.factory = spec.factory || IPA.default_factory; + + that.build = function(spec) { + + var factory = spec.factory || that.factory; + + //when spec is a factory function + if (!spec.factory && typeof spec === 'function') { + factory = spec; + spec = {}; + } + + var obj = factory(spec); + return obj; + }; + + that.build_objects = function(specs) { + + var objects = []; + + for (var i=0; i