diff options
author | Petr Vobornik <pvoborni@redhat.com> | 2012-08-02 17:37:12 +0200 |
---|---|---|
committer | Martin Kosek <mkosek@redhat.com> | 2012-08-14 08:09:43 +0200 |
commit | 5d2b0fecd57b18b647ff9f243196cf98ead2d9fd (patch) | |
tree | 3a990bedba331edbd7869e34c63213710fbb7df6 /install/ui | |
parent | 7c99e2d6617a397e4f8f1185032e17b779245181 (diff) | |
download | freeipa-5d2b0fecd57b18b647ff9f243196cf98ead2d9fd.tar.gz freeipa-5d2b0fecd57b18b647ff9f243196cf98ead2d9fd.tar.xz freeipa-5d2b0fecd57b18b647ff9f243196cf98ead2d9fd.zip |
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
Diffstat (limited to 'install/ui')
-rw-r--r-- | install/ui/add.js | 5 | ||||
-rw-r--r-- | install/ui/association.js | 255 | ||||
-rw-r--r-- | install/ui/entity.js | 9 | ||||
-rw-r--r-- | install/ui/facet.js | 16 |
4 files changed, 276 insertions, 9 deletions
diff --git a/install/ui/add.js b/install/ui/add.js index 4ca0f0418..caa1ab5a0 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 be8b8459d..a30ca5328 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 || {}; @@ -131,6 +131,50 @@ IPA.bulk_associator = function(spec) { }; /** + * 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. */ IPA.association_adder_dialog = function(spec) { @@ -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<pkeys.length; i++) { + var pkey = pkeys[i]; + var record = {}; + record[that.attribute] = pkey; + records_map.put(pkey, record); + } + + return records_map; + }; + + that.refresh = function() { + + var pkey = that.entity.get_primary_key(); + + var command = IPA.command({ + entity: that.entity.name, + method: 'show', + args: pkey + }); + + command.on_success = function(data, text_status, xhr) { + that.load(data); + that.show_content(); + }; + + command.on_error = function(xhr, text_status, error_thrown) { + that.redirect_error(error_thrown); + that.report_error(error_thrown); + }; + + command.execute(); + }; + + that.clear = function() { + that.header.clear(); + that.table.clear(); + }; + + that.needs_update = function() { + if (that._needs_update !== undefined) return that._needs_update; + + 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; + if (that.table.current_page !== page) return true; + + return that.facet_needs_update(); + }; + + that.show_add_dialog = function() { + + var dialog = IPA.attribute_adder_dialog({ + attribute: spec.attribute, + entity: that.entity + }); + + dialog.open(that.container); + }; + + that.show_remove_dialog = function() { + + var selected_values = that.get_selected_values(); + + if (!selected_values.length) { + var message = IPA.messages.dialogs.remove_empty; + alert(message); + return; + } + + var dialog = IPA.deleter_dialog({ + entity: that.entity, + values: selected_values + }); + + dialog.execute = function() { + that.remove( + selected_values, + function(data) { + that.load(data); + that.show_content(); + dialog.close(); + }, + function() { + that.refresh(); + dialog.close(); + } + ); + }; + + + dialog.open(that.container); + }; + + that.remove = function(values, on_success, on_error) { + + var pkey = that.entity.get_primary_key(); + + var command = IPA.command({ + entity: that.entity.name, + method: that.remove_method, + args: pkey, + on_success: on_success, + on_error: on_error + }); + + command.set_option(that.attribute, values); + + command.execute(); + }; + + + that.init_attribute_facet = function() { + + that.init_facet(); + that.init_table_columns(); + that.init_table(that.entity); + }; + + if (!no_init) that.init_attribute_facet(); + + return that; +};
\ No newline at end of file diff --git a/install/ui/entity.js b/install/ui/entity.js index 49f30b0b2..d474ad95b 100644 --- a/install/ui/entity.js +++ b/install/ui/entity.js @@ -420,6 +420,15 @@ IPA.entity_builder = function() { return that; }; + that.attribute_facet = function(spec) { + + spec.type = spec.type || 'attribute'; + + that.facet(spec); + + return that; + }; + that.standard_association_facets = function(spec) { spec = spec || {}; diff --git a/install/ui/facet.js b/install/ui/facet.js index 3f6d559ea..267fc3332 100644 --- a/install/ui/facet.js +++ b/install/ui/facet.js @@ -747,6 +747,8 @@ IPA.table_facet = function(spec, no_init) { that.row_disabled_attribute = spec.row_disabled_attribute; that.details_facet_name = spec.details_facet || 'default'; + that.table_name = spec.table_name; + that.columns = $.ordered_map(); that.get_columns = function() { @@ -1003,7 +1005,7 @@ IPA.table_facet = function(spec, no_init) { that.table = IPA.table_widget({ 'class': 'content-table', - name: entity.metadata.primary_key, + name: that.table_name || entity.metadata.primary_key, label: entity.metadata.label, entity: entity, pagination: true, @@ -1125,6 +1127,7 @@ IPA.facet_builder = function(entity) { 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.prepare_methods.attribute = that.prepare_attribute_spec; } that.build_facets = function() { @@ -1195,6 +1198,17 @@ IPA.facet_builder = function(entity) { return spec; }; + that.prepare_attribute_spec = function(spec) { + spec.title = spec.title || entity.metadata.label_singular; + spec.label = spec.label || entity.metadata.label_singular; + + var attr_metadata = IPA.get_entity_param(entity.name, spec.attribute); + spec.tab_label = spec.tab_label || attr_metadata.label; + spec.factory = spec.factory || IPA.attribute_facet; + + return spec; + }; + that.prepare_association_spec = function(spec) { spec.entity = entity; |