diff options
author | Petr Vobornik <pvoborni@redhat.com> | 2013-04-12 17:29:29 +0200 |
---|---|---|
committer | Petr Vobornik <pvoborni@redhat.com> | 2013-05-06 16:22:25 +0200 |
commit | ffeafa6ec2974de5e3f2303fa8ffccf1638e9254 (patch) | |
tree | 5c7d4593c6555453d9b4df8419401ae109fc19af /install/ui | |
parent | f14393f427948169c596ddadc307074656b40631 (diff) | |
download | freeipa-ffeafa6ec2974de5e3f2303fa8ffccf1638e9254.tar.gz freeipa-ffeafa6ec2974de5e3f2303fa8ffccf1638e9254.tar.xz freeipa-ffeafa6ec2974de5e3f2303fa8ffccf1638e9254.zip |
Replace IPA.facet_builder with facets.builder
https://fedorahosted.org/freeipa/ticket/3235
Diffstat (limited to 'install/ui')
-rw-r--r-- | install/ui/src/freeipa/entity.js | 36 | ||||
-rw-r--r-- | install/ui/src/freeipa/facet.js | 170 | ||||
-rw-r--r-- | install/ui/test/details_tests.js | 19 | ||||
-rw-r--r-- | install/ui/test/entity_tests.js | 15 |
4 files changed, 133 insertions, 107 deletions
diff --git a/install/ui/src/freeipa/entity.js b/install/ui/src/freeipa/entity.js index 2d0e97f84..e20efc0f4 100644 --- a/install/ui/src/freeipa/entity.js +++ b/install/ui/src/freeipa/entity.js @@ -21,7 +21,8 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -define(['./ipa', './jquery', './text', './facet'], function(IPA, $, text) { +define(['./ipa', './jquery', './text', './facets', './facet'], + function(IPA, $, text, facet_reg) { IPA.entity = function(spec) { @@ -117,12 +118,26 @@ IPA.entity = function(spec) { that.facet_groups.empty(); }; + that.add_redirect_info = function(facet_name) { + if (!that.redirect_facet && facet_name){ + that.redirect_facet = facet_name; + } + }; + that.get_facet = function(name) { + var i, facets; + //build all facets on the first time if(!that.facets_created) { - var builder = IPA.facet_builder(that); - builder.build_facets(); + facets = facet_reg.builder.build(that.facet_specs, { entity: that }); + for (i=0; i<facets.length; i++) { + var facet = facets[i]; + that.add_facet(facet); + if (facet.name === 'search') { + that.add_redirect_info(facet.name); + } + } that.facets_created = true; that.policies.facets_created(); } @@ -137,9 +152,9 @@ IPA.entity = function(spec) { } else if (name === 'default') { // return the first facet in the first facet group var facet_groups = that.facet_groups.values; - for (var i=0; i<facet_groups.length; i++) { + for (i=0; i<facet_groups.length; i++) { var facet_group = facet_groups[i]; - var facets = facet_group.facets.values; + facets = facet_group.facets.values; if (!facets.length) continue; return facets[0]; } @@ -232,7 +247,6 @@ IPA.entity_builder = function() { that.facet = function(spec) { - spec.entity = entity; entity.facet_specs.push(spec); return that; @@ -240,7 +254,7 @@ IPA.entity_builder = function() { that.search_facet = function(spec) { - spec.type = spec.type || 'search'; + spec.$type = spec.$type || 'search'; that.facet(spec); @@ -251,7 +265,7 @@ IPA.entity_builder = function() { that.nested_search_facet = function(spec) { - spec.type = spec.type || 'nested_search'; + spec.$type = spec.$type || 'nested_search'; that.facet(spec); @@ -260,7 +274,7 @@ IPA.entity_builder = function() { that.details_facet = function(spec) { - spec.type = spec.type || 'details'; + spec.$type = spec.$type || 'details'; that.facet(spec); @@ -269,7 +283,7 @@ IPA.entity_builder = function() { that.association_facet = function(spec) { - spec.type = spec.type || 'association'; + spec.$type = spec.$type || 'association'; that.facet(spec); @@ -278,7 +292,7 @@ IPA.entity_builder = function() { that.attribute_facet = function(spec) { - spec.type = spec.type || 'attribute'; + spec.$type = spec.$type || 'attribute'; that.facet(spec); diff --git a/install/ui/src/freeipa/facet.js b/install/ui/src/freeipa/facet.js index 3afe76e04..3e4474580 100644 --- a/install/ui/src/freeipa/facet.js +++ b/install/ui/src/freeipa/facet.js @@ -29,15 +29,18 @@ define([ 'dojo/Stateful', 'dojo/Evented', './_base/Builder', + './facets', './ipa', './jquery', './navigation', + './phases', + './spec_util', './text', './dialog', './field', './widget' ], function(declare, lang, construct, on, Stateful, Evented, - Builder, IPA, $, navigation, text) { + Builder, facets, IPA, $, navigation, phases, su, text) { /** * Facet represents the content of currently displayed page. @@ -1462,95 +1465,53 @@ exp.facet_group = IPA.facet_group = function(spec) { return that; }; -exp.facet_builder = IPA.facet_builder = function(entity) { +exp.facet_preops = { + search: function(spec, context) { - var that = IPA.object(); - - that.prepare_methods = {}; - - function init() { - that.prepare_methods.search = that.prepare_search_spec; - that.prepare_methods.nested_search = that.prepare_nested_search_spec; - that.prepare_methods.details = that.prepare_details_spec; - that.prepare_methods.association = that.prepare_association_spec; - that.prepare_methods.attribute = that.prepare_attribute_spec; - } - - that.build_facets = function() { - - if(entity.facet_specs && entity.facet_specs.length) { - var facets = entity.facet_specs; - for(var i=0; i<facets.length; i++) { - var facet_spec = facets[i]; - that.build_facet(facet_spec); - } - } - }; - - that.build_facet = function(spec) { - - //do common logic - spec.entity = entity; - - //prepare spec based on type - var type = spec.type; - if (type) { - var prepare_method = that.prepare_methods[type]; - if (prepare_method) { - prepare_method.call(that, spec); - } - } - - //add facet - var facet = spec.$factory(spec); - entity.add_facet(facet); - }; - - function add_redirect_info(facet_name) { - - facet_name = facet_name || 'search'; - if (!entity.redirect_facet){ - entity.redirect_facet = facet_name; - } - } - - that.prepare_search_spec = function(spec) { + var entity = context.entity; + su.context_entity(spec, context); spec.title = spec.title || entity.metadata.label; spec.label = spec.label || entity.metadata.label; spec.tab_label = spec.tab_label || '@i18n:facets.search'; - spec.$factory = spec.$factory || IPA.search_facet; - add_redirect_info(); return spec; - }; + }, - that.prepare_nested_search_spec = function(spec) { + nested_search: function(spec, context) { + + var entity = context.entity; + su.context_entity(spec, context); spec.title = spec.title || entity.metadata.label_singular; spec.label = spec.label || entity.metadata.label; spec.tab_label = spec.tab_label || '@i18n:facets.search'; - spec.$factory = spec.$factory || IPA.nested_search_facet; return spec; - }; + }, + + details: function(spec, context) { + + var entity = context.entity; + su.context_entity(spec, context); - that.prepare_details_spec = function(spec) { spec.title = spec.title || entity.metadata.label_singular; spec.label = spec.label || entity.metadata.label_singular; spec.tab_label = spec.tab_label || '@i18n:facets.details'; - spec.$factory = spec.$factory || IPA.details_facet; return spec; - }; + }, + + attribute: function(spec, context) { + + var entity = context.entity; + su.context_entity(spec, context); - that.prepare_attribute_spec = function(spec) { spec.title = spec.title || entity.metadata.label_singular; spec.label = spec.label || entity.metadata.label_singular; var attr_metadata = IPA.get_entity_param(entity.name, spec.attribute); spec.tab_label = spec.tab_label || attr_metadata.label; - spec.$factory = spec.$factory || IPA.attribute_facet; entity.policies.add_policy(IPA.build({ $factory: IPA.facet_update_policy, @@ -1559,10 +1520,23 @@ exp.facet_builder = IPA.facet_builder = function(entity) { })); return spec; - }; + }, + + association: function(spec, context) { - that.prepare_association_spec = function(spec) { + var has_indirect_attribute_member = function(spec) { + var indirect_members = entity.metadata.attribute_members[spec.attribute_member + 'indirect']; + if (indirect_members) { + if (indirect_members.indexOf(spec.other_entity) > -1) { + return true; + } + } + return false; + }; + + var entity = context.entity; + su.context_entity(spec, context); spec.entity = entity; var index = spec.name.indexOf('_'); @@ -1576,14 +1550,12 @@ exp.facet_builder = IPA.facet_builder = function(entity) { spec.facet_group = spec.facet_group || spec.attribute_member; - spec.$factory = spec.$factory || IPA.association_facet; - spec.label = spec.label || entity.metadata.label_singular; spec.tab_label = spec.tab_label || (IPA.metadata.objects[spec.other_entity] ? IPA.metadata.objects[spec.other_entity].label : spec.other_entity); - if (that.has_indirect_attribute_member(spec)) { + if (has_indirect_attribute_member(spec)) { spec.indirect_attribute_member = spec.attribute_member + 'indirect'; } @@ -1601,24 +1573,52 @@ exp.facet_builder = IPA.facet_builder = function(entity) { })); return spec; - }; - - that.has_indirect_attribute_member = function(spec) { - - var indirect_members = entity.metadata.attribute_members[spec.attribute_member + 'indirect']; - if (indirect_members) { - if (indirect_members.indexOf(spec.other_entity) > -1) { - return true; - } - } - return false; - }; - - init(); - - return that; + } }; +phases.on('registration', function() { + + facets.register({ + type: 'search', + factory: IPA.search_facet, + pre_ops: [ + exp.facet_preops.search + ] + }); + + facets.register({ + type: 'nested_search', + factory: IPA.nested_search_facet, + pre_ops: [ + exp.facet_preops.nested_search + ] + }); + + facets.register({ + type: 'details', + factory: IPA.details_facet, + pre_ops: [ + exp.facet_preops.details + ] + }); + + facets.register({ + type: 'association', + factory: IPA.association_facet, + pre_ops: [ + exp.facet_preops.association + ] + }); + + facets.register({ + type: 'attribute', + factory: IPA.attribute_facet, + pre_ops: [ + exp.facet_preops.attribute + ] + }); +}); + exp.action = IPA.action = function(spec) { spec = spec || {}; diff --git a/install/ui/test/details_tests.js b/install/ui/test/details_tests.js index 7326d553c..1d4530838 100644 --- a/install/ui/test/details_tests.js +++ b/install/ui/test/details_tests.js @@ -18,8 +18,8 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -define(['freeipa/ipa', 'freeipa/jquery', 'freeipa/details', - 'freeipa/entity'], function(IPA, $) { +define(['freeipa/ipa', 'freeipa/jquery','freeipa/facet', 'freeipa/facets', 'freeipa/details', + 'freeipa/entity'], function(IPA, $, mod_facet, facets) { return function() { var details_container; @@ -29,6 +29,14 @@ module('details', { setup: function() { IPA.ajax_options.async = false; + facets.register({ + type: 'details', + factory: IPA.details_facet, + pre_ops: [ + mod_facet.facet_preops.details + ] + }); + IPA.init({ url: 'data', on_error: function(xhr, text_status, error_thrown) { @@ -36,12 +44,6 @@ module('details', { } }); - IPA.nav = {}; - - IPA.nav.get_state = function(key){ - return $.bbq.getState(key); - }; - details_container = $('<div id="details"/>').appendTo(document.body); IPA.register('user', function(spec) { @@ -54,6 +56,7 @@ module('details', { }, teardown: function() { details_container.remove(); + facets.remove('details'); } }); diff --git a/install/ui/test/entity_tests.js b/install/ui/test/entity_tests.js index 26d73090c..c9b7a1047 100644 --- a/install/ui/test/entity_tests.js +++ b/install/ui/test/entity_tests.js @@ -19,8 +19,9 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -define(['freeipa/ipa', 'freeipa/jquery', 'freeipa/entity', 'freeipa/search', - 'freeipa/details'], function(IPA, $) { +define(['freeipa/ipa', 'freeipa/jquery','freeipa/facet', 'freeipa/facets', + 'freeipa/entity', 'freeipa/search', + 'freeipa/details'], function(IPA, $, mod_facet, facets) { return function() { var container; @@ -30,6 +31,14 @@ module('entity',{ IPA.ajax_options.async = false; + facets.register({ + type: 'search', + factory: IPA.search_facet, + pre_ops: [ + mod_facet.facet_preops.search + ] + }); + IPA.init({ url: 'data', on_success: function(data, text_status, xhr) { @@ -59,7 +68,7 @@ module('entity',{ }, teardown: function() { container.remove(); - + facets.remove('search'); } }); |