mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
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
This commit is contained in:
committed by
Endi S. Dewata
parent
863666fbe8
commit
6cdf09812d
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user