From 5d2b0fecd57b18b647ff9f243196cf98ead2d9fd Mon Sep 17 00:00:00 2001 From: Petr Vobornik Date: Thu, 2 Aug 2012 17:37:12 +0200 Subject: Attribute facet Created new type of facet: attribute facet. This facet is similar to association facet but it serves for displaying object's multivalued attributes which behaves like association attributes. It will serve as a basis for displaying group's externalmember attribute. https://fedorahosted.org/freeipa/ticket/2895 --- install/ui/association.js | 255 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 250 insertions(+), 5 deletions(-) (limited to 'install/ui/association.js') diff --git a/install/ui/association.js b/install/ui/association.js index be8b8459..a30ca532 100644 --- a/install/ui/association.js +++ b/install/ui/association.js @@ -50,8 +50,8 @@ IPA.associator = function (spec) { /** -*This associator is built for the case where each association requires a separate rpc -*/ + * This associator is built for the case where each association requires a separate rpc + */ IPA.serial_associator = function(spec) { spec = spec || {}; @@ -95,9 +95,9 @@ IPA.serial_associator = function(spec) { }; /** -*This associator is for the common case where all the asociations can be sent -in a single rpc -*/ + * This associator is for the common case where all the asociations can be sent + * in a single rpc + */ IPA.bulk_associator = function(spec) { spec = spec || {}; @@ -130,6 +130,50 @@ IPA.bulk_associator = function(spec) { return that; }; +/** + * This dialog is for adding value of multivalued attribute which behaves like + * association attribute. + */ +IPA.attribute_adder_dialog = function(spec) { + + spec = spec || {}; + + spec.name = spec.name || 'attr_adder_dialog'; + spec.method = spec.method || 'add_member'; + + var metadata = IPA.get_command_option(spec.entity.name+'_'+spec.method, spec.attribute); + + spec.fields = spec.fields || [ + { + name: spec.attribute, + metadata: metadata, + required: true + } + ]; + spec.title = spec.title || IPA.messages.dialogs.add_title.replace('${entity}', metadata.label); + spec.subject = metadata.label; + + var that = IPA.entity_adder_dialog(spec); + + that.create_add_command = function(record) { + + var command = that.entity_adder_dialog_create_add_command(record); + + command.add_args(that.entity.get_primary_key()); + + return command; + }; + + that.create_buttons = function() { + + that.buttons.remove('add_and_edit'); + }; + + that.create_buttons(); + + return that; +}; + /** * This dialog is used for adding associations between two entities. */ @@ -1093,3 +1137,204 @@ IPA.association_facet = function (spec, no_init) { return that; }; + +IPA.attribute_facet = function(spec, no_init) { + + spec = spec || {}; + + //default buttons and their actions + spec.actions = spec.actions || []; + spec.actions.unshift( + IPA.refresh_action, + { + name: 'remove', + hide_cond: ['read-only'], + enable_cond: ['item-selected'], + handler: function(facet) { + facet.show_remove_dialog(); + } + }, + { + name: 'add', + hide_cond: ['read-only'], + handler: function(facet) { + facet.show_add_dialog(); + } + } + ); + + spec.control_buttons = spec.control_buttons || []; + spec.control_buttons.unshift( + { + name: 'refresh', + label: IPA.messages.buttons.refresh, + icon: 'reset-icon' + }, + { + name: 'remove', + label: IPA.messages.buttons.remove, + icon: 'remove-icon' + }, + { + name: 'add', + label: IPA.messages.buttons.add, + icon: 'add-icon' + }); + + spec.state = spec.state || {}; + spec.state.evaluators = spec.state.evaluators || []; + spec.state.evaluators.push( + IPA.selected_state_evaluator, + IPA.read_only_state_evaluator); + + spec.columns = spec.columns || [ spec.attribute ]; + spec.table_name = spec.table_name || spec.attribute; + + var that = IPA.table_facet(spec, true); + + that.attribute = spec.attribute; + + that.add_method = spec.add_method || 'add_member'; + that.remove_method = spec.remove_method || 'remove_member'; + + that.create_header = function(container) { + + that.facet_create_header(container); + that.create_control_buttons(that.controls); + }; + + that.show = function() { + that.facet_show(); + + that.pkey = IPA.nav.get_state(that.entity.name+'-pkey'); + that.header.set_pkey(that.pkey); + }; + + that.get_records_map = function(data) { + + var records_map = $.ordered_map(); + var pkeys = data.result.result[that.attribute]; + + for (var i=0; pkeys && i