diff options
author | Petr Vobornik <pvoborni@redhat.com> | 2013-04-18 12:37:40 +0200 |
---|---|---|
committer | Petr Vobornik <pvoborni@redhat.com> | 2013-05-06 16:22:28 +0200 |
commit | 2182c93e2f4d009d87313a347840c3d8de5178e3 (patch) | |
tree | f6948ef897988d61944a1da3cea6cc4fec559c41 | |
parent | 790853c5870fc82989692e9e63f3e829f124595b (diff) | |
download | freeipa-2182c93e2f4d009d87313a347840c3d8de5178e3.tar.gz freeipa-2182c93e2f4d009d87313a347840c3d8de5178e3.tar.xz freeipa-2182c93e2f4d009d87313a347840c3d8de5178e3.zip |
Entity registry and builder which allow definition by spec
https://fedorahosted.org/freeipa/ticket/3235
-rw-r--r-- | install/ui/src/freeipa/entity.js | 80 | ||||
-rw-r--r-- | install/ui/src/freeipa/ipa.js | 10 |
2 files changed, 75 insertions, 15 deletions
diff --git a/install/ui/src/freeipa/entity.js b/install/ui/src/freeipa/entity.js index 417d0672b..7dd4f66ab 100644 --- a/install/ui/src/freeipa/entity.js +++ b/install/ui/src/freeipa/entity.js @@ -23,15 +23,19 @@ define([ 'dojo/_base/lang', + './_base/Singleton_registry', './builder', './ipa', './jquery', + './reg', './text', './facets', './facet'], - function(lang, builder, IPA, $, text, facet_reg) { + function(lang, Singleton_registry, builder, IPA, $, reg, text, facet_reg) { -IPA.entity = function(spec) { +var exp = {}; + +exp.entity = IPA.entity = function(spec) { spec = spec || {}; @@ -218,7 +222,7 @@ IPA.entity = function(spec) { return that; }; -IPA.entity_builder = function(entity) { +exp.entity_builder =IPA.entity_builder = function(entity) { var that = IPA.object(); @@ -450,7 +454,51 @@ IPA.entity_builder = function(entity) { return that; }; -IPA.entity_policy = function(spec) { +exp.entity_post_ops = { + + init: function(entity, spec, context) { + + if (entity.init) { + entity.init(spec, context); + } + return entity; + }, + + containing_entity: function(entity, spec, context) { + if (spec.containing_entity) { + entity.builder.containing_entity(spec.containing_entity); + } + return entity; + }, + + standard_association_facets: function(entity, spec, context) { + var saf = spec.standard_association_facets; + if (saf) { + var facet_spec; + if (typeof saf === 'object') facet_spec = saf; + entity.builder.standard_association_facets(facet_spec); + } + return entity; + }, + + adder_dialog: function(entity, spec, context) { + + if (spec.adder_dialog) { + entity.builder.adder_dialog(spec.adder_dialog); + } + return entity; + }, + + deleter_dialog: function(entity, spec, context) { + + if (spec.deleter_dialog) { + entity.builder.deleter_dialog(spec.deleter_dialog); + } + return entity; + } +}; + +exp.entity_policy = IPA.entity_policy = function(spec) { spec = spec || {}; @@ -464,7 +512,7 @@ IPA.entity_policy = function(spec) { return that; }; -IPA.entity_policies = function(spec) { +exp.entity_policies = IPA.entity_policies = function(spec) { var that = IPA.object(); @@ -500,7 +548,7 @@ IPA.entity_policies = function(spec) { return that; }; -IPA.facet_update_policy = function(spec) { +exp.facet_update_policy = IPA.facet_update_policy = function(spec) { spec = spec || {}; @@ -537,7 +585,7 @@ IPA.facet_update_policy = function(spec) { return that; }; -IPA.adder_facet_update_policy = function(spec) { +exp.adder_facet_update_policy = IPA.adder_facet_update_policy = function(spec) { spec = spec || {}; @@ -574,7 +622,7 @@ IPA.adder_facet_update_policy = function(spec) { return that; }; -IPA.search_facet_update_policy = function(spec) { +exp.search_facet_update_policy = IPA.search_facet_update_policy = function(spec) { spec = spec || {}; spec.source_facet = 'search'; @@ -583,7 +631,7 @@ IPA.search_facet_update_policy = function(spec) { return IPA.facet_update_policy(spec); }; -IPA.details_facet_update_policy = function(spec) { +exp.details_facet_update_policy =IPA.details_facet_update_policy = function(spec) { spec = spec || {}; spec.source_facet = 'details'; @@ -592,5 +640,17 @@ IPA.details_facet_update_policy = function(spec) { return IPA.facet_update_policy(spec); }; -return {}; +// Entity builder and registry +var registry = new Singleton_registry(); +reg.set('entity', registry); +builder.set('entity', registry.builder); +registry.builder.factory = exp.entity; +registry.builder.post_ops.push( + exp.entity_post_ops.init, + exp.entity_post_ops.containing_entity, + exp.entity_post_ops.standard_association_facets, + exp.entity_post_ops.adder_dialog, + exp.entity_post_ops.deleter_dialog); + +return exp; });
\ No newline at end of file diff --git a/install/ui/src/freeipa/ipa.js b/install/ui/src/freeipa/ipa.js index fec27d9e5..701ed2398 100644 --- a/install/ui/src/freeipa/ipa.js +++ b/install/ui/src/freeipa/ipa.js @@ -27,9 +27,9 @@ define(['./jquery', './_base/i18n', './_base/metadata_provider', './builder', - './entities', + './reg', './text'], - function($, JSON, i18n, metadata_provider, builder, entities, text) { + function($, JSON, i18n, metadata_provider, builder, reg, text) { var IPA = function() { @@ -219,8 +219,8 @@ var IPA = function() { }; that.register = function(name, factory) { - entities.remove(name); - entities.register({ + reg.entity.remove(name); + reg.entity.register({ type: name, factory: factory, spec: { name: name } @@ -228,7 +228,7 @@ var IPA = function() { }; that.get_entity = function(name) { - return entities.get(name); + return reg.entity.get(name); }; that.display_activity_icon = function() { |