From 5fc064f13e44812042a617a322bcd6111d2b39b2 Mon Sep 17 00:00:00 2001 From: "Endi S. Dewata" Date: Mon, 7 Nov 2011 14:21:45 -0600 Subject: Refactored entity object resolution. The IPA.get_entity() has been modified to accept either entity name or entity object. If it receives an entity object it will return the object itself. Otherwise, it will resolve the name in the entity registry. The other_entity variables have been modified to store a reference to the entity object instead of its name. The test cases have been modified to use real entity objects instead of just the names. Ticket #2042 --- install/ui/association.js | 123 ++++++++++++++++++++++++---------------------- 1 file changed, 63 insertions(+), 60 deletions(-) (limited to 'install/ui/association.js') diff --git a/install/ui/association.js b/install/ui/association.js index 553e2bce..ed274eb4 100644 --- a/install/ui/association.js +++ b/install/ui/association.js @@ -30,10 +30,10 @@ IPA.associator = function (spec) { var that = {}; - that.entity = spec.entity; + that.entity = IPA.get_entity(spec.entity); that.pkey = spec.pkey; - that.other_entity = spec.other_entity; + that.other_entity = IPA.get_entity(spec.other_entity); that.values = spec.values; that.method = spec.method; @@ -77,7 +77,7 @@ IPA.serial_associator = function(spec) { options[that.entity.name] = that.pkey; command = IPA.command({ - entity: that.other_entity, + entity: that.other_entity.name, method: that.method, args: args, options: options @@ -122,7 +122,7 @@ IPA.bulk_associator = function(spec) { var args = [that.pkey]; var options = { 'all': true }; - options[that.other_entity] = value; + options[that.other_entity.name] = value; var command = IPA.command({ entity: that.entity.name, @@ -150,19 +150,21 @@ IPA.association_adder_dialog = function(spec) { var that = IPA.adder_dialog(spec); - that.entity = spec.entity; + that.entity = IPA.get_entity(spec.entity); that.pkey = spec.pkey; - that.other_entity = spec.other_entity; + + that.other_entity = IPA.get_entity(spec.other_entity); that.attribute_member = spec.attribute_member; + that.exclude = spec.exclude || []; var init = function() { if (!that.get_columns().length) { - var pkey_name = IPA.metadata.objects[spec.other_entity].primary_key; + var pkey_name = that.other_entity.metadata.primary_key; that.create_column({ entity: that.entity, name: pkey_name, - label: IPA.metadata.objects[spec.other_entity].label, + label: that.other_entity.metadata.label, primary_key: true, width: '600px' }); @@ -174,13 +176,12 @@ IPA.association_adder_dialog = function(spec) { that.clear_available_values(); - var other_entity = IPA.get_entity(that.other_entity); - var pkey_attr = other_entity.metadata.primary_key; + var pkey_attr = that.other_entity.metadata.primary_key; var selected = that.get_selected_values(); var results = data.result; - var same_entity = that.entity.name === other_entity.name; + var same_entity = that.entity === that.other_entity; for (var i=0; i', { @@ -880,9 +881,9 @@ IPA.association_facet = function (spec) { that.get_attribute_name = function() { if (that.association_type == 'direct') { - return that.attribute_member+'_'+that.other_entity; + return that.attribute_member+'_'+that.other_entity.name; } else { - return that.indirect_attribute_member+'_'+that.other_entity; + return that.indirect_attribute_member+'_'+that.other_entity.name; } }; @@ -895,13 +896,14 @@ IPA.association_facet = function (spec) { that.show_add_dialog = function() { + var entity_label = that.entity.metadata.label_singular; var pkey = IPA.nav.get_state(that.entity.name+'-pkey'); - var label = IPA.metadata.objects[that.other_entity] ? IPA.metadata.objects[that.other_entity].label : that.other_entity; + var other_entity_label = that.other_entity.metadata.label; var title = that.add_title; - title = title.replace('${entity}', that.entity.metadata.label_singular); + title = title.replace('${entity}', entity_label); title = title.replace('${primary_key}', pkey); - title = title.replace('${other_entity}', label); + title = title.replace('${other_entity}', other_entity_label); var pkeys = that.data.result.result[that.get_attribute_name()]; @@ -924,16 +926,16 @@ IPA.association_facet = function (spec) { var pkey = IPA.nav.get_state(that.entity.name+'-pkey'); var associator = that.associator({ - 'entity': that.entity, - 'pkey': pkey, - 'other_entity': that.other_entity, - 'values': dialog.get_selected_values(), - 'method': that.add_method, - 'on_success': function() { + entity: that.entity, + pkey: pkey, + other_entity: that.other_entity, + values: dialog.get_selected_values(), + method: that.add_method, + on_success: function() { that.refresh(); dialog.close(); }, - 'on_error': function() { + on_error: function() { that.refresh(); dialog.close(); } @@ -947,7 +949,6 @@ IPA.association_facet = function (spec) { that.show_remove_dialog = function() { - var label = IPA.metadata.objects[that.other_entity] ? IPA.metadata.objects[that.other_entity].label : that.other_entity; var values = that.table.get_selected_values(); if (!values.length) { @@ -956,12 +957,14 @@ IPA.association_facet = function (spec) { return; } + var entity_label = that.entity.metadata.label_singular; var pkey = IPA.nav.get_state(that.entity.name+'-pkey'); + var other_entity_label = that.other_entity.metadata.label; var title = that.remove_title; - title = title.replace('${entity}', that.entity.metadata.label_singular); + title = title.replace('${entity}', entity_label); title = title.replace('${primary_key}', pkey); - title = title.replace('${other_entity}', label); + title = title.replace('${other_entity}', other_entity_label); var dialog = IPA.association_deleter_dialog({ title: title, @@ -1042,7 +1045,7 @@ IPA.association_facet = function (spec) { var pkey = IPA.nav.get_state(that.entity.name+'-pkey'); if (that.pkey !== pkey) return true; - var page = parseInt(IPA.nav.get_state(that.entity_name+'-page'), 10) || 1; + var page = parseInt(IPA.nav.get_state(that.entity.name+'-page'), 10) || 1; if (that.table.current_page !== page) return true; return false; -- cgit