Merged direct and indirect association facets

The direct and indirect associations are now displayed in the same
facet. The type of association to be displayed can be selected
using radio buttons.

Ticket #1338
This commit is contained in:
Endi S. Dewata 2011-06-16 16:35:13 -05:00 committed by Adam Young
parent dbeae4e3f4
commit 313f201ea5
4 changed files with 93 additions and 11 deletions

View File

@ -674,7 +674,11 @@ IPA.association_facet = function (spec) {
var that = IPA.facet(spec);
that.attribute_member = spec.attribute_member;
that.indirect_attribute_member = spec.indirect_attribute_member;
that.other_entity = spec.other_entity;
that.association_type = 'direct';
that.facet_group = spec.facet_group;
that.read_only = spec.read_only;
@ -821,6 +825,48 @@ IPA.association_facet = function (spec) {
}
}).appendTo(that.controls);
}
if (that.indirect_attribute_member) {
var span = $('<span/>', {
'class': 'right-aligned-controls'
}).appendTo(that.controls);
span.append('Show Results ');
that.direct_radio = $('<input/>', {
type: 'radio',
name: 'type',
value: 'direct',
click: function() {
that.association_type = $(this).val();
that.refresh();
return true;
}
}).appendTo(span);
span.append(' Direct Enrollment ');
that.indirect_radio = $('<input/>', {
type: 'radio',
name: 'type',
value: 'indirect',
click: function() {
that.association_type = $(this).val();
that.refresh();
return true;
}
}).appendTo(span);
span.append(' Indirect Enrollment');
}
};
that.get_attribute_name = function() {
if (that.association_type == 'direct') {
return that.attribute_member+'_'+that.other_entity;
} else {
return that.indirect_attribute_member+'_'+that.other_entity;
}
};
that.create_content = function(container) {
@ -948,7 +994,7 @@ IPA.association_facet = function (spec) {
that.table.current_page_input.val(that.table.current_page);
that.table.total_pages_span.text(that.table.total_pages);
var pkeys = that.record[that.name];
var pkeys = that.record[that.get_attribute_name()];
if (!pkeys || !pkeys.length) {
that.table.empty();
that.table.summary.text('No entries.');
@ -1003,7 +1049,7 @@ IPA.association_facet = function (spec) {
if (!length) return;
var batch = IPA.batch_command({
'name': that.entity_name+'_'+that.name,
'name': that.entity_name+'_'+that.get_attribute_name(),
'on_success': on_success,
'on_error': on_error
});
@ -1026,12 +1072,22 @@ IPA.association_facet = function (spec) {
that.refresh = function() {
if (that.association_type == 'direct') {
if (that.direct_radio) that.direct_radio.attr('checked', true);
if (that.add_button) that.add_button.css('display', 'inline');
if (that.remove_button) that.remove_button.css('display', 'inline');
} else {
if (that.indirect_radio) that.indirect_radio.attr('checked', true);
if (that.add_button) that.add_button.css('display', 'none');
if (that.remove_button) that.remove_button.css('display', 'none');
}
function on_success(data, text_status, xhr) {
that.record = data.result.result;
that.table.current_page = 1;
var pkeys = that.record[that.name];
var pkeys = that.record[that.get_attribute_name()];
if (pkeys) {
that.table.total_pages =
Math.ceil(pkeys.length / that.table.page_length);

View File

@ -376,7 +376,7 @@ IPA.details_facet = function(spec) {
name: 'expand_all',
href: 'expand_all',
label: 'Expand All',
'class': 'expand-collapse-all',
'class': 'right-aligned-controls',
style: 'display: none;',
click: function() {
that.expand_button.css('display', 'none');
@ -395,7 +395,7 @@ IPA.details_facet = function(spec) {
name: 'collapse_all',
href: 'collapse_all',
label: 'Collapse All',
'class': 'expand-collapse-all',
'class': 'right-aligned-controls',
click: function() {
that.expand_button.css('display', 'inline');
that.collapse_button.css('display', 'none');

View File

@ -795,7 +795,20 @@ IPA.entity_builder = function(){
if (spec.facet_group == 'memberindirect' ||
spec.facet_group == 'memberofindirect') {
spec.read_only = true;
var length = spec.attribute_member.length;
var direct_attribute_member = spec.attribute_member.substring(0, length-8);
var direct_facet_name = direct_attribute_member+'_'+spec.other_entity;
facet = entity.get_facet(direct_facet_name);
if (facet) { // merge into previously created direct facet
facet.indirect_attribute_member = spec.attribute_member;
return that;
} else {
spec.read_only = true;
}
}
spec.label = spec.label ||
@ -823,15 +836,28 @@ IPA.entity_builder = function(){
spec = spec || {};
var attribute_members = entity.metadata.attribute_members;
var direct_associations = [];
var indirect_associations = [];
for (var attribute_member in attribute_members) {
for (var association in entity.metadata.attribute_members) {
if (association == 'memberindirect' ||
association == 'memberofindirect') {
indirect_associations.push(association);
} else {
direct_associations.push(association);
}
}
// make sure direct facets are created first
var attribute_members = direct_associations.concat(indirect_associations);
for (var i=0; i<attribute_members.length; i++) {
var attribute_member = attribute_members[i];
var other_entities = entity.metadata.attribute_members[attribute_member];
for (var i=0; i<other_entities.length; i++) {
for (var j=0; j<other_entities.length; j++) {
var other_entity = other_entities[i];
var other_entity = other_entities[j];
var association_name = attribute_member+'_'+other_entity;
var facet = entity.get_facet(association_name);

View File

@ -1191,7 +1191,7 @@ table.scrollable tbody {
height: 4em;
}
.expand-collapse-all {
.right-aligned-controls {
position: absolute;
right: 0;
padding-right: 1.5em;