From 27ea90792fb06e7e62f81c352936232ee10894ff Mon Sep 17 00:00:00 2001 From: Petr Vobornik Date: Mon, 10 Oct 2011 13:34:15 +0200 Subject: Circular entity dependency https://fedorahosted.org/freeipa/ticket/1531 Each entity is created together with its dependent objects (e.g. facets and dialog boxes). This causes a circular dependency problem because some of the objects need to obtain a reference to another entity that has not been created. Currently this is handled by storing only the other entity name and resolve it when needed (e.g. during rendering stage). In IPA.search_facet this delays the creation of the table widget, making it more difficult to customize. One solution is to do the object creation in 2 steps: * create all entity objects only * create the dependent objects in each entity Implemented solution: * all entities are created on application start * dependant objects (facets and dialogs) are created at once on their first use in entity. --- install/ui/entity.js | 340 ++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 244 insertions(+), 96 deletions(-) (limited to 'install/ui/entity.js') diff --git a/install/ui/entity.js b/install/ui/entity.js index 374236011..c82f4a8df 100644 --- a/install/ui/entity.js +++ b/install/ui/entity.js @@ -128,7 +128,7 @@ IPA.facet = function (spec) { that.redirect = function() { var entity = that.entity; while (entity.containing_entity) { - entity = entity.containing_entity; + entity = entity.get_containing_entity(); } IPA.nav.show_page( @@ -192,13 +192,13 @@ IPA.facet_header = function(spec) { if (!that.facet.disable_breadcrumb) { var breadcrumb = []; - var entity = that.facet.entity.containing_entity; + var entity = that.facet.entity.get_containing_entity(); while (entity) { breadcrumb.unshift($('', { 'class': 'breadcrumb-element', text: IPA.nav.get_state(entity.name+'-pkey'), - title: entity.name, + title: entity.metadata.label_singular, click: function(entity) { return function() { IPA.nav.show_page(entity.name, 'default'); @@ -207,7 +207,7 @@ IPA.facet_header = function(spec) { }(entity) })); - entity = entity.containing_entity; + entity = entity.get_containing_entity(); } that.path.empty(); @@ -293,7 +293,9 @@ IPA.facet_header = function(spec) { }).appendTo(that.breadcrumb); var entity = that.facet.entity; - while (entity.containing_entity) entity = entity.containing_entity; + while (entity.containing_entity) { + entity = entity.get_containing_entity(); + } $('', { text: entity.metadata.label, @@ -453,9 +455,13 @@ IPA.entity = function (spec) { that.title = spec.title || that.label; that.dialogs = $.ordered_map(); + that.dialog_specs = spec.dialogs || []; + that.dialogs_created = false; that.facets = $.ordered_map(); that.facet_groups = $.ordered_map(); + that.facet_specs = spec.facets || []; + that.facets_created = false; // current facet that.facet = null; @@ -463,7 +469,20 @@ IPA.entity = function (spec) { that.redirect_facet = spec.redirect_facet; that.containing_entity = null; + that.get_containing_entity = function() { + return that.containing_entity ? + IPA.get_entity(that.containing_entity) : null; + }; + that.get_dialog = function(name) { + + //build all dialogs on the first time + if(!that.dialogs_created) { + var builder = IPA.dialog_builder(that); + builder.build_dialogs(); + that.dialogs_created = true; + } + return that.dialogs.get(name); }; @@ -490,6 +509,14 @@ IPA.entity = function (spec) { }; that.get_facet = function(name) { + + //build all facets on the first time + if(!that.facets_created) { + var builder = IPA.facet_builder(that); + builder.build_facets(); + that.facets_created = true; + } + if (name === undefined) { // return the current facet if (that.facet) return that.facet; @@ -570,14 +597,14 @@ IPA.entity = function (spec) { that.get_primary_key_prefix = function() { var pkey = []; var current_entity = that; - current_entity = current_entity.containing_entity; + current_entity = current_entity.get_containing_entity(); while(current_entity !== null){ var key = IPA.nav.get_state(current_entity.name+'-pkey'); if (key){ pkey.unshift(key); } - current_entity = current_entity.containing_entity; + current_entity = current_entity.get_containing_entity(); } return pkey; }; @@ -734,20 +761,19 @@ IPA.entity_builder = function(){ }; that.facet = function(spec) { + spec.entity = entity; - facet = spec.factory(spec); - entity.add_facet(facet); + entity.facet_specs.push(spec); + return that; }; that.search_facet = function(spec) { - spec.entity = entity; - spec.title = spec.title || entity.metadata.label; - spec.label = spec.label || IPA.messages.facets.search; - var factory = spec.factory || IPA.search_facet; - facet = factory(spec); - entity.add_facet(facet); + spec.type = spec.type || 'search'; + + that.facet(spec); + add_redirect_info(); return that; @@ -755,81 +781,27 @@ IPA.entity_builder = function(){ that.nested_search_facet = function(spec) { - spec.entity = entity; - spec.title = spec.title || entity.metadata.label_singular; - spec.label = spec.label || IPA.messages.facets.search; + spec.type = spec.type || 'nested_search'; - var factory = spec.factory || IPA.nested_search_facet; - facet = factory(spec); - entity.add_facet(facet); + that.facet(spec); return that; }; that.details_facet = function(spec) { - var sections = spec.sections; - spec.entity = entity; - spec.sections = null; - spec.title = spec.title || entity.metadata.label_singular; - spec.label = spec.label || IPA.messages.facets.details; - - var factory = spec.factory || IPA.details_facet; - facet = factory(spec); - entity.add_facet(facet); + spec.type = spec.type || 'details'; - if (sections) { - for (var i=0; i -1) { + var direct_attribute_member = attribute_member.substring(0, index); + return get_spec_by_name(facets, + direct_attribute_member+'_'+other_entity); } - facet.add_section(section); - }; + + return null; + } function add_redirect_info(facet_name){ if (!entity.redirect_facet){ @@ -900,30 +891,31 @@ IPA.entity_builder = function(){ that.containing_entity = function(entity_name) { add_redirect_info(); - entity.containing_entity = IPA.get_entity(entity_name); + entity.containing_entity = entity_name; return that; }; that.dialog = function(spec) { - var dialog; + if (spec instanceof Object) { - var factory = spec.factory || IPA.dialog; + spec.factory = spec.factory || IPA.dialog; spec.entity = entity; - dialog = factory(spec); + } else { - dialog = IPA.dialog({ + spec = { + factory: IPA.dialog, name: spec, entity: entity - }); + }; } - entity.dialog(dialog); + + entity.dialog_specs.push(spec); return that; }; that.adder_dialog = function(spec) { spec.factory = spec.factory || IPA.add_dialog; spec.name = spec.name || 'add'; - spec.entity = entity; if (!spec.title) { var title = IPA.messages.dialogs.add_title; @@ -944,8 +936,164 @@ IPA.entity_builder = function(){ that.build = function(){ var item = entity; entity = null; + return item; }; return that; }; + +IPA.facet_builder = function(entity) { + + var that = {}; + + 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.build_facets = function() { + + if(entity.facet_specs && entity.facet_specs.length) { + var facets = entity.facet_specs; + for(var i=0; i -1) { + return true; + } + } + return false; + }; + + init(); + + return that; +}; + +IPA.dialog_builder = function(entity) { + + var that = {}; + + that.build_dialogs = function() { + + if(entity.dialog_specs && entity.dialog_specs.length) { + var dialogs = entity.dialog_specs; + for(var i=0; i