summaryrefslogtreecommitdiffstats
path: root/install/ui/ipa.js
diff options
context:
space:
mode:
authorPetr Vobornik <pvoborni@redhat.com>2012-04-04 16:23:16 +0200
committerPetr Vobornik <pvoborni@redhat.com>2012-05-11 18:30:48 +0200
commit12401fe4da9620ce7dae3339f9928f9d2a770fbd (patch)
tree855ddbc9d93206becca336777b8b48079df63a9b /install/ui/ipa.js
parent58732a83bc4ea99ce9894f07232b890ae26682ef (diff)
downloadfreeipa-12401fe4da9620ce7dae3339f9928f9d2a770fbd.tar.gz
freeipa-12401fe4da9620ce7dae3339f9928f9d2a770fbd.tar.xz
freeipa-12401fe4da9620ce7dae3339f9928f9d2a770fbd.zip
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
Diffstat (limited to 'install/ui/ipa.js')
-rw-r--r--install/ui/ipa.js67
1 files changed, 67 insertions, 0 deletions
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<specs.length; i++) {
+ var spec = specs[i];
+ var obj = that.build(spec);
+ objects.push(obj);
+ }
+
+ return objects;
+ };
+
+ return that;
+};
+
+IPA.build = function(spec, builder_fac) {
+
+ if (!spec) return null;
+
+ if (!builder_fac) builder_fac = IPA.builder;
+
+ var builder = builder_fac();
+ var product;
+
+ if ($.isArray(spec)) {
+ product = builder.build_objects(spec);
+ } else {
+ product = builder.build(spec);
+ }
+
+ return product;
+};
+
+IPA.default_factory = function(spec) {
+
+ spec = spec || {};
+
+ var that = {};
+
+ $.extend(that, spec);
+
+ return that;
+};
+
/* helper function used to retrieve information about an attribute */
IPA.get_entity_param = function(entity_name, name) {