summaryrefslogtreecommitdiffstats
path: root/install/static/associate.js
diff options
context:
space:
mode:
authorEndi S. Dewata <edewata@redhat.com>2010-11-19 23:52:33 -0600
committerAdam Young <ayoung@redhat.com>2010-11-30 14:58:30 -0500
commitc90bff232dcc9dbab2cd6d5a1bb482cb1c5f16f9 (patch)
treee270c50dbff183e94590bd20d0d8e42100abc390 /install/static/associate.js
parentd644d17adf117321747db1e4e22a771fbea3b09e (diff)
downloadfreeipa-c90bff232dcc9dbab2cd6d5a1bb482cb1c5f16f9.tar.gz
freeipa-c90bff232dcc9dbab2cd6d5a1bb482cb1c5f16f9.tar.xz
freeipa-c90bff232dcc9dbab2cd6d5a1bb482cb1c5f16f9.zip
Multicolumn association facet
The association facet has been modified to support multiple columns. By default the facet will have one column which is the primary key of the associated object (e.g. username of a group member), so the existing code will work like before. Other fields (e.g. user's full name) can be added by subclassing the ipa_association_facet class and specifying the additional columns to display. These additional fields will be retrieved using a batch operation. Previously a single association facet instance will be used for all associations in an entity. Now each association will have its own association facet. This way each association facet can be customized differently as needed. The <entity>-enroll URL parameter has been removed because it's no longer needed. The ipa_entity.create_association_facets() is provided to generate the default association facets with one column for the primary key. The column click handler has been moved out of ipa_column to provide more flexibility for customization. The get_action_panel() and get_client_area() have been modified to search within the entity's container. The group entity has been fully converted to use the new UI framework. Association facets that have been modified to use multiple columns are: - User Group's member_user - HBAC Service Group's member_hbacsvc - SUDO Command Group's member_sudocmd - Service's managedby_host New test data files have been added. Unit tests have been updated.
Diffstat (limited to 'install/static/associate.js')
-rw-r--r--install/static/associate.js153
1 files changed, 120 insertions, 33 deletions
diff --git a/install/static/associate.js b/install/static/associate.js
index ddfd78c29..fbd1c63c9 100644
--- a/install/static/associate.js
+++ b/install/static/associate.js
@@ -147,17 +147,25 @@ function ipa_association_adder_dialog(spec) {
that.on_success = spec.on_success;
that.on_error = spec.on_error;
+ that.init = function() {
+ if (!that.columns.length) {
+ var pkey_name = IPA.metadata[that.other_entity].primary_key;
+ that.create_column({
+ name: pkey_name,
+ primary_key: true
+ });
+ }
+ };
+
that.search = function() {
function on_success(data, text_status, xhr) {
var results = data.result;
that.clear_available_values();
- var pkey = IPA.metadata[that.other_entity].primary_key;
-
for (var i=0; i<results.count; i++){
var result = results.result[i];
- that.add_available_value(result[pkey][0]);
+ that.add_available_value(result);
}
}
@@ -235,7 +243,7 @@ function ipa_association_config(spec) {
return that;
}
-function ipa_association_widget(spec) {
+function ipa_association_table_widget(spec) {
spec = spec || {};
@@ -251,20 +259,41 @@ function ipa_association_widget(spec) {
that.member_attribute = ipa_get_member_attribute(
that.entity_name, that.other_entity);
- that.create_column({
- name: that.member_attribute + '_' + that.other_entity,
- other_entity : that.other_entity,
- label: IPA.metadata[that.other_entity].label,
- primary_key: true,
- link: true
- });
+ if (!that.columns.length) {
+ var pkey_name = IPA.metadata[that.other_entity].primary_key;
+
+ var column = that.create_column({
+ name: pkey_name,
+ label: IPA.metadata[that.other_entity].label,
+ primary_key: true
+ });
+
+ column.setup = function(container, record) {
+ container.empty();
+
+ var value = record[column.name];
+ value = value ? value.toString() : '';
+
+ $('<a/>', {
+ 'href': '#'+value,
+ 'html': value,
+ 'click': function (value) {
+ return function() {
+ var state = IPA.tab_state(that.other_entity);
+ state[that.other_entity + '-facet'] = 'details';
+ state[that.other_entity + '-pkey'] = value;
+ $.bbq.pushState(state);
+ return false;
+ }
+ }(value)
+ }).appendTo(container);
+ };
+ }
that.superior_create(container);
var action_panel = that.facet.get_action_panel();
-
- var ul = $('ul', action_panel);
- var li = $('<li/>').prependTo(ul);
+ var li = $('.action-controls', action_panel);
// creating generic buttons for layout
$('<input/>', {
@@ -381,23 +410,59 @@ function ipa_association_widget(spec) {
dialog.open(that.container);
};
+ that.get_records = function(pkeys, on_success, on_error) {
+
+ var batch = ipa_batch_command({
+ 'name': that.entity_name+'_'+that.name,
+ 'on_success': on_success,
+ 'on_error': on_error
+ });
+
+ for (var i=0; i<pkeys.length; i++) {
+ var pkey = pkeys[i];
+
+ var command = ipa_command({
+ 'method': that.other_entity+'_show',
+ 'args': [pkey],
+ 'options': {
+ 'all': true,
+ 'rights': true
+ }
+ });
+
+ batch.add_command(command);
+ }
+
+ batch.execute();
+ };
+
that.refresh = function() {
function on_success(data, text_status, xhr) {
that.tbody.empty();
- var column_name = that.columns[0].name;
- var values = data.result.result[column_name];
- //TODO, this is masking an error where the wrong
- //direction association is presented upon page reload.
- //if the values is unset, it is because
- //form.associationColumns[0] doesn't exist in the results
- if (!values) return;
-
- for (var i = 0; i<values.length; i++){
- var record = that.get_record(data.result.result, i);
- that.add_row(record);
+ var pkeys = data.result.result[that.name];
+
+ if (that.columns.length == 1) { // show pkey only
+ var name = that.columns[0].name;
+ for (var i=0; i<pkeys.length; i++) {
+ var record = {};
+ record[name] = pkeys[i];
+ that.add_row(record);
+ }
+
+ } else { // get and show additional fields
+ that.get_records(
+ pkeys,
+ function(data, text_status, xhr) {
+ var results = data.result.results;
+ for (var i=0; i<results.length; i++) {
+ var record = results[i].result;
+ that.add_row(record);
+ }
+ }
+ );
}
}
@@ -421,18 +486,35 @@ function ipa_association_facet(spec) {
var that = ipa_facet(spec);
- that.other_entity = null;
+ that.other_entity = spec.other_entity;
+
+ that.columns = [];
+ that.columns_by_name = {};
+
+ that.get_column = function(name) {
+ return that.columns_by_name[name];
+ };
+
+ that.add_column = function(column) {
+ column.entity_name = that.entity_name;
+ that.columns.push(column);
+ that.columns_by_name[column.name] = column;
+ };
+
+ that.create_column = function(spec) {
+ var column = ipa_column(spec);
+ that.add_column(column);
+ return column;
+ };
that.is_dirty = function() {
var pkey = $.bbq.getState(that.entity_name + '-pkey', true) || '';
- var other_entity = $.bbq.getState(that.entity_name + '-enroll', true) || '';
return pkey != that.pkey || other_entity != that.other_entity;
};
that.create = function(container) {
that.pkey = $.bbq.getState(that.entity_name + '-pkey', true) || '';
- that.other_entity = $.bbq.getState(that.entity_name + '-enroll', true) || '';
var label = IPA.metadata[that.other_entity] ? IPA.metadata[that.other_entity].label : that.other_entity;
@@ -445,15 +527,19 @@ function ipa_association_facet(spec) {
html: $('<h2/>',{ html: header_message })
}).appendTo(container);
- that.table = ipa_association_widget({
+ that.table = ipa_association_table_widget({
'id': that.entity_name+'-'+that.other_entity,
- 'name': that.other_entity,
+ 'name': that.name,
'label': label,
'entity_name': that.entity_name,
'other_entity': that.other_entity,
'facet': that
});
+ if (that.columns.length) {
+ that.table.set_columns(that.columns);
+ }
+
var span = $('<span/>', { 'name': 'association' }).appendTo(container);
that.table.create(span);
@@ -466,12 +552,13 @@ function ipa_association_facet(spec) {
var span = $('span[name=association]', that.container);
that.table.setup(span);
- that.table.refresh();
};
- //TODO find out why this is needed
that.refresh = function(){
- }
+ that.table.refresh();
+ };
+
+ that.association_facet_init = that.init;
return that;
}