From eb8f091c9bfce3f6d4004bbf214e169aa3f8fe29 Mon Sep 17 00:00:00 2001 From: "Endi S. Dewata" Date: Fri, 11 Feb 2011 18:04:04 -0600 Subject: Fixed association facets. The association config has been removed because it incorrectly assumes there is only one association between two entities. Now each association is defined separately using association facets. The service.py has been modified to specify the correct relationships. The API.txt has been updated. https://fedorahosted.org/freeipa/ticket/960 --- install/ui/associate.js | 134 ++++++++++++++++++++++++------------------------ 1 file changed, 67 insertions(+), 67 deletions(-) (limited to 'install/ui/associate.js') diff --git a/install/ui/associate.js b/install/ui/associate.js index 2d416f0f..c96f5127 100644 --- a/install/ui/associate.js +++ b/install/ui/associate.js @@ -51,7 +51,7 @@ IPA.associator = function (spec) { /** *This associator is built for the case where each association requires a separate rpc */ -function serial_associator(spec) { +IPA.serial_associator = function(spec) { spec = spec || {}; @@ -74,23 +74,27 @@ function serial_associator(spec) { var options = {}; options[that.entity_name] = that.pkey; - IPA.cmd( - that.method, - args, - options, - that.execute, - that.on_error, - that.other_entity); + var command = IPA.command({ + method: that.other_entity+'_'+that.method, + args: args, + options: options, + on_success: that.execute, + on_error: that.on_error + }); + + //alert(JSON.stringify(command.to_json())); + + command.execute(); }; return that; -} +}; /** *This associator is for the common case where all the asociations can be sent in a single rpc */ -function bulk_associator(spec) { +IPA.bulk_associator = function(spec) { spec = spec || {}; @@ -117,17 +121,21 @@ function bulk_associator(spec) { var options = { 'all': true }; options[that.other_entity] = value; - IPA.cmd( - that.method, - args, - options, - that.on_success, - that.on_error, - that.entity_name); + var command = IPA.command({ + method: that.entity_name+'_'+that.method, + args: args, + options: options, + on_success: that.on_success, + on_error: that.on_error + }); + + //alert(JSON.stringify(command.to_json())); + + command.execute(); }; return that; -} +}; /** * This dialog is used for adding associations between two entities. @@ -228,7 +236,7 @@ IPA.association_deleter_dialog = function (spec) { that.on_success = spec.on_success; that.on_error = spec.on_error; - that.remove = function() { + that.execute = function() { var associator = that.associator({ 'entity_name': that.entity_name, @@ -271,7 +279,7 @@ IPA.association_table_widget = function (spec) { that.other_entity = spec.other_entity; that.attribute_member = spec.attribute_member; - that.associator = spec.associator || bulk_associator; + that.associator = spec.associator || IPA.bulk_associator; that.add_method = spec.add_method || 'add_member'; that.remove_method = spec.remove_method || 'remove_member'; @@ -296,16 +304,7 @@ IPA.association_table_widget = function (spec) { that.init = function() { var entity = IPA.get_entity(that.entity_name); - var association = entity.get_association(that.other_entity); var column; - if (association) { - if (association.associator) { - that.associator = association.associator == 'serial' ? serial_associator : bulk_associator; - } - - if (association.add_method) that.add_method = association.add_method; - if (association.remove_method) that.remove_method = association.remove_method; - } // create a column if none defined if (!that.columns.length) { @@ -523,7 +522,7 @@ IPA.association_table_widget = function (spec) { method: that.remove_method }); - dialog.remove = function() { + dialog.execute = function() { that.remove( selected_values, function() { @@ -571,11 +570,14 @@ IPA.association_facet = function (spec) { var that = IPA.facet(spec); - that.other_entity = spec.other_entity; + var index = that.name.indexOf('_'); + that.attribute_member = spec.attribute_member || that.name.substring(0, index); + that.other_entity = spec.other_entity || that.name.substring(index+1); + that.facet_group = spec.facet_group; - that.attribute_member = spec.attribute_member; + that.label = that.label ? that.label : (IPA.metadata[that.other_entity] ? IPA.metadata[that.other_entity].label : that.other_entity); - that.associator = spec.associator || bulk_associator; + that.associator = spec.associator || IPA.bulk_associator; that.add_method = spec.add_method || 'add_member'; that.remove_method = spec.remove_method || 'remove_member'; @@ -620,19 +622,9 @@ IPA.association_facet = function (spec) { that.facet_init(); var entity = IPA.get_entity(that.entity_name); - var association = entity.get_association(that.other_entity); var column; var i; - if (association) { - if (association.associator) { - that.associator = association.associator == 'serial' ? serial_associator : bulk_associator; - } - - if (association.add_method) that.add_method = association.add_method; - if (association.remove_method) that.remove_method = association.remove_method; - } - var label = IPA.metadata[that.other_entity] ? IPA.metadata[that.other_entity].label : that.other_entity; var pkey_name = IPA.metadata[that.other_entity].primary_key; @@ -734,14 +726,11 @@ IPA.association_facet = function (spec) { 'value': IPA.messages.button.remove }).appendTo(li); - /* TODO: genering handling of different relationships */ - if ((relationship[0] == 'Member')||(relationship[0] == 'Member Of')) { - $('', { - 'type': 'button', - 'name': 'add', - 'value': IPA.messages.button.enroll - }).appendTo(li); - } + $('', { + 'type': 'button', + 'name': 'add', + 'value': IPA.messages.button.enroll + }).appendTo(li); }; that.setup = function(container) { @@ -830,23 +819,34 @@ IPA.association_facet = function (spec) { var title = 'Remove '+label+' from '+that.entity_name+' '+pkey; var dialog = IPA.association_deleter_dialog({ - 'title': title, - 'entity_name': that.entity_name, - 'pkey': pkey, - 'other_entity': that.other_entity, - 'values': values, - 'associator': that.associator, - 'method': that.remove_method, - 'on_success': function() { - that.refresh(); - dialog.close(); - }, - 'on_error': function() { - that.refresh(); - dialog.close(); - } + title: title, + entity_name: that.entity_name, + pkey: pkey, + other_entity: that.other_entity, + values: values }); + dialog.execute = function() { + + var associator = that.associator({ + entity_name: that.entity_name, + pkey: pkey, + other_entity: that.other_entity, + values: values, + method: that.remove_method, + on_success: function() { + that.refresh(); + dialog.close(); + }, + on_error: function() { + that.refresh(); + dialog.close(); + } + }); + + associator.execute(); + }; + dialog.init(); dialog.open(that.container); @@ -919,7 +919,7 @@ IPA.association_facet = function (spec) { } var pkey = $.bbq.getState(that.entity_name + '-pkey', true) || ''; - IPA.cmd('show', [pkey], {'rights': true}, on_success, on_error, that.entity_name); + IPA.cmd('show', [pkey], {'all': true, 'rights': true}, on_success, on_error, that.entity_name); }; that.association_facet_init = that.init; -- cgit