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/add.js | 5 +- install/ui/association.js | 255 +++++++++++++++++++++++++++++++++++++++++++++- install/ui/entity.js | 9 ++ install/ui/facet.js | 16 ++- 4 files changed, 276 insertions(+), 9 deletions(-) (limited to 'install') diff --git a/install/ui/add.js b/install/ui/add.js index 4ca0f041..caa1ab5a 100644 --- a/install/ui/add.js +++ b/install/ui/add.js @@ -36,6 +36,7 @@ IPA.entity_adder_dialog = function(spec) { that.retry = typeof spec.retry !== 'undefined' ? spec.retry : true; that.command = null; that.added = IPA.observer(); + that.subject = spec.subject || that.entity.metadata.label_singular; that.show_edit_page = spec.show_edit_page || show_edit_page; @@ -64,9 +65,8 @@ IPA.entity_adder_dialog = function(spec) { that.add( function(data, text_status, xhr) { that.added.notify(); - var label = that.entity.metadata.label_singular; var message = IPA.messages.dialogs.add_confirmation; - message = message.replace('${entity}', label); + message = message.replace('${entity}', that.subject); that.show_message(message); var facet = IPA.current_entity.get_facet(); @@ -184,4 +184,3 @@ IPA.entity_adder_dialog = function(spec) { return that; }; - 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