diff options
author | Petr Vobornik <pvoborni@redhat.com> | 2011-11-22 16:00:48 +0100 |
---|---|---|
committer | Endi S. Dewata <edewata@redhat.com> | 2011-12-05 16:00:44 +0000 |
commit | 6cdf09812dd13531acb29f1413de87ce7cd5218f (patch) | |
tree | 51fe546dd86113f6a6b80a08eeb6b266be71afe1 /install/ui/field.js | |
parent | 863666fbe8875312c490f4747bdd30a3e0f46191 (diff) | |
download | freeipa.git-6cdf09812dd13531acb29f1413de87ce7cd5218f.tar.gz freeipa.git-6cdf09812dd13531acb29f1413de87ce7cd5218f.tar.xz freeipa.git-6cdf09812dd13531acb29f1413de87ce7cd5218f.zip |
Builders and collections for fields and widgets
Introduced IPA.field_container and IPA.widget_container.
IPA.field_container: collection for fields. Can set logical container (facet, dialog...) to fields.
IPA.widget_container: collection for widgets. Has basic searching capability withing widget tree.
Introduced field_builder, widget_builder, section_builder, details_builder. All are used for building fields and widgets. Field_builder and widget_builder have the main building logic. Section_builder can create content based on current section spec. Details builder defines a strategy for building content.
https://fedorahosted.org/freeipa/ticket/2040
Diffstat (limited to 'install/ui/field.js')
-rw-r--r-- | install/ui/field.js | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/install/ui/field.js b/install/ui/field.js index fb14f2eb..c1b74ab5 100644 --- a/install/ui/field.js +++ b/install/ui/field.js @@ -572,6 +572,103 @@ IPA.link_field = function(spec) { return that; }; +IPA.field_container = function(spec) { + + spec = spec || {}; + + var that = {}; + + that.container = spec.container; //usually facet or dialog + + that.fields = $.ordered_map(); + + that.get_field = function(name) { + return that.fields.get(name); + }; + + that.get_fields = function(name) { + return that.fields.values; + }; + + that.add_field = function(field) { + field.container = that.container; + that.fields.put(field.name, field); + }; + + that.widgets_created = function() { + var fields = that.fields.values; + + for (var i=0; i<fields.length; i++) { + fields[i].widgets_created(); + } + }; + + that.container_add_field = that.add_field; + + return that; +}; + +IPA.field_builder = function(spec) { + + spec = spec || {}; + + var that = {}; + + that.default_factory = spec.default_factory || IPA.field; + that.container = spec.container; + that.field_options = spec.field_options || {}; + + that.get_field_factory = function(spec) { + + var factory; + if (spec.factory) { + factory = spec.factory; + } else if(spec.type) { + factory = IPA.field_factories[spec.type]; + } + + if (!factory) { + factory = that.default_factory; + } + + return factory; + }; + + that.build_field = function(spec, container) { + + container = container || that.container; + + if(!(spec instanceof Object)) { + spec = { name: spec }; + } + + if(that.field_options) { + $.extend(spec, that.field_options); + } + + var factory = that.get_field_factory(spec); + + var field = factory(spec); + + if(container) { + container.add_field(field); + } + + return field; + }; + + that.build_fields = function(specs, container) { + + container = container || that.container; + + for(var i=0; i<specs.length; i++) { + that.build_field(specs[i], container); + } + }; + + return that; +}; + IPA.field_factories['field'] = IPA.field; IPA.field_factories['text'] = IPA.field; IPA.field_factories['password'] = IPA.field; |