Refactored entity object resolution.

The IPA.get_entity() has been modified to accept either entity name
or entity object. If it receives an entity object it will return
the object itself. Otherwise, it will resolve the name in the entity
registry.

The other_entity variables have been modified to store a reference
to the entity object instead of its name. The test cases have been
modified to use real entity objects instead of just the names.

Ticket #2042
This commit is contained in:
Endi S. Dewata
2011-11-07 14:21:45 -06:00
committed by Petr Vobornik
parent 49e5555b11
commit 5fc064f13e
24 changed files with 157 additions and 154 deletions

View File

@@ -353,6 +353,8 @@ IPA.aci.delegation_entity = function(spec) {
var that = IPA.entity(spec);
that.group_entity = IPA.get_entity(spec.group_entity || 'group');
that.init = function() {
that.entity_init();
@@ -370,13 +372,13 @@ IPA.aci.delegation_entity = function(spec) {
{
type: 'entity_select',
name: 'group',
other_entity: 'group',
other_entity: that.group_entity,
other_field: 'cn'
},
{
type: 'entity_select',
name: 'memberof',
other_entity: 'group',
other_entity: that.group_entity,
other_field: 'cn',
join: true
},
@@ -397,13 +399,13 @@ IPA.aci.delegation_entity = function(spec) {
{
type: 'entity_select',
name: 'group',
other_entity: 'group',
other_entity: that.group_entity,
other_field: 'cn'
},
{
type: 'entity_select',
name: 'memberof',
other_entity: 'group',
other_entity: that.group_entity,
other_field: 'cn',
join: true
},
@@ -591,6 +593,8 @@ IPA.permission_target_widget = function(spec) {
var that = factory(spec);
that.group_entity = IPA.get_entity(spec.group_entity || 'group');
that.targets = [ 'filter', 'subtree', 'targetgroup', 'type' ];
that.target = that.targets[0];
that.show_target = spec.show_target;
@@ -638,7 +642,7 @@ IPA.permission_target_widget = function(spec) {
that.group_select = IPA.entity_select_widget({
entity: that.entity,
name: 'targetgroup',
other_entity: 'group',
other_entity: that.group_entity,
other_field: 'cn',
hidden: true
});

View File

@@ -30,10 +30,10 @@ IPA.associator = function (spec) {
var that = {};
that.entity = spec.entity;
that.entity = IPA.get_entity(spec.entity);
that.pkey = spec.pkey;
that.other_entity = spec.other_entity;
that.other_entity = IPA.get_entity(spec.other_entity);
that.values = spec.values;
that.method = spec.method;
@@ -77,7 +77,7 @@ IPA.serial_associator = function(spec) {
options[that.entity.name] = that.pkey;
command = IPA.command({
entity: that.other_entity,
entity: that.other_entity.name,
method: that.method,
args: args,
options: options
@@ -122,7 +122,7 @@ IPA.bulk_associator = function(spec) {
var args = [that.pkey];
var options = { 'all': true };
options[that.other_entity] = value;
options[that.other_entity.name] = value;
var command = IPA.command({
entity: that.entity.name,
@@ -150,19 +150,21 @@ IPA.association_adder_dialog = function(spec) {
var that = IPA.adder_dialog(spec);
that.entity = spec.entity;
that.entity = IPA.get_entity(spec.entity);
that.pkey = spec.pkey;
that.other_entity = spec.other_entity;
that.other_entity = IPA.get_entity(spec.other_entity);
that.attribute_member = spec.attribute_member;
that.exclude = spec.exclude || [];
var init = function() {
if (!that.get_columns().length) {
var pkey_name = IPA.metadata.objects[spec.other_entity].primary_key;
var pkey_name = that.other_entity.metadata.primary_key;
that.create_column({
entity: that.entity,
name: pkey_name,
label: IPA.metadata.objects[spec.other_entity].label,
label: that.other_entity.metadata.label,
primary_key: true,
width: '600px'
});
@@ -174,13 +176,12 @@ IPA.association_adder_dialog = function(spec) {
that.clear_available_values();
var other_entity = IPA.get_entity(that.other_entity);
var pkey_attr = other_entity.metadata.primary_key;
var pkey_attr = that.other_entity.metadata.primary_key;
var selected = that.get_selected_values();
var results = data.result;
var same_entity = that.entity.name === other_entity.name;
var same_entity = that.entity === that.other_entity;
for (var i=0; i<results.count; i++) {
var result = results.result[i];
var pkey = result[pkey_attr][0];
@@ -194,7 +195,7 @@ IPA.association_adder_dialog = function(spec) {
}
var options = { all: true };
var relationships = IPA.metadata.objects[that.other_entity].relationships;
var relationships = that.other_entity.metadata.relationships;
/* TODO: better generic handling of different relationships! */
var other_attribute_member = '';
@@ -214,7 +215,7 @@ IPA.association_adder_dialog = function(spec) {
}
IPA.command({
entity: that.other_entity,
entity: that.other_entity.name,
method: 'find',
args: [that.get_filter()],
options: options,
@@ -237,9 +238,10 @@ IPA.association_deleter_dialog = function (spec) {
var that = IPA.deleter_dialog(spec);
that.entity = spec.entity;
that.entity = IPA.get_entity(spec.entity);
that.pkey = spec.pkey;
that.other_entity = spec.other_entity;
that.other_entity = IPA.get_entity(spec.other_entity);
that.values = spec.values;
that.associator = spec.associator;
@@ -289,11 +291,11 @@ IPA.association_table_widget = function (spec) {
spec.attribute_member = spec.attribute_member || spec.name.substring(0, index);
spec.other_entity = spec.other_entity || spec.name.substring(index+1);
spec.managed_entity_name = spec.other_entity;
spec.managed_entity = IPA.get_entity(spec.other_entity);
var that = IPA.table_widget(spec);
that.other_entity = spec.other_entity;
that.other_entity = IPA.get_entity(spec.other_entity);
that.attribute_member = spec.attribute_member;
that.associator = spec.associator || IPA.bulk_associator;
@@ -316,7 +318,7 @@ IPA.association_table_widget = function (spec) {
};
that.create_adder_column = function(spec) {
spec.entity_name = that.other_entity;
spec.entity = that.other_entity;
var column = IPA.column(spec);
that.add_adder_column(column);
return column;
@@ -328,7 +330,7 @@ IPA.association_table_widget = function (spec) {
that.create_column({
name: that.name,
label: that.label,
entity_name: that.other_entity,
entity: that.other_entity,
primary_key: true,
link: true
});
@@ -340,11 +342,11 @@ IPA.association_table_widget = function (spec) {
var columns = that.columns.values;
for (var i=0; i<columns.length; i++) {
column = columns[i];
column.entity = IPA.get_entity(that.other_entity);
column.entity = that.other_entity;
if (column.link) {
column.link_handler = function(value) {
IPA.nav.show_page(that.other_entity, 'default', value);
IPA.nav.show_page(that.other_entity.name, 'default', value);
return false;
};
}
@@ -356,7 +358,7 @@ IPA.association_table_widget = function (spec) {
var adder_columns = that.adder_columns.values;
for (var j=0; j<adder_columns.length; j++) {
column = adder_columns[j];
column.entity_name = that.other_entity;
column.entity = that.other_entity;
}
};
@@ -497,7 +499,7 @@ IPA.association_table_widget = function (spec) {
var entity_label = that.entity.metadata.label_singular;
var pkey = IPA.nav.get_state(that.entity.name+'-pkey');
var other_entity_label = IPA.metadata.objects[that.other_entity].label;
var other_entity_label = that.other_entity.metadata.label;
var title = that.add_title;
title = title.replace('${entity}', entity_label);
@@ -552,7 +554,7 @@ IPA.association_table_widget = function (spec) {
on_success: on_success,
on_error: on_error
});
command.set_option(that.other_entity, values.join(','));
command.set_option(that.other_entity.name, values.join(','));
command.execute();
};
@@ -567,20 +569,21 @@ IPA.association_table_widget = function (spec) {
return;
}
var entity_label = that.entity.metadata.label_singular;
var pkey = IPA.nav.get_state(that.entity.name+'-pkey');
var label = IPA.metadata.objects[that.other_entity].label;
var other_entity_label = that.other_entity.metadata.label;
var title = that.remove_title;
title = title.replace('${entity}', that.entity.metadata.label_singular);
title = title.replace('${entity}', entity_label);
title = title.replace('${primary_key}', pkey);
title = title.replace('${other_entity}', label);
title = title.replace('${other_entity}', other_entity_label);
var dialog = IPA.association_deleter_dialog({
'title': title,
'entity': that.entity,
'pkey': pkey,
'other_entity': that.other_entity,
'values': selected_values,
title: title,
entity: that.entity,
pkey: pkey,
other_entity: that.other_entity,
values: selected_values,
method: that.remove_method
});
@@ -614,7 +617,7 @@ IPA.association_table_widget = function (spec) {
on_error: on_error
});
command.set_option(that.other_entity, values.join(','));
command.set_option(that.other_entity.name, values.join(','));
command.execute();
};
@@ -629,8 +632,7 @@ IPA.association_table_widget = function (spec) {
var i;
if (spec.columns){
for (i = 0; i < spec.columns.length; i+= 1){
spec.columns[i].entity_name = spec.columns[i].entity_name ||
that.other_entity;
spec.columns[i].entity = spec.columns[i].entity || that.other_entity;
that.create_column(spec.columns[i]);
}
}
@@ -700,14 +702,14 @@ IPA.association_facet = function (spec) {
link must be set before the call to the base class, to affect the table.
*/
spec.link = spec.link === undefined ? true : spec.link;
spec.managed_entity_name = spec.other_entity;
spec.managed_entity = IPA.get_entity(spec.other_entity);
var that = IPA.table_facet(spec);
that.attribute_member = spec.attribute_member;
that.indirect_attribute_member = spec.indirect_attribute_member;
that.other_entity = spec.other_entity;
that.other_entity = IPA.get_entity(spec.other_entity);
that.association_type = 'direct';
that.facet_group = spec.facet_group;
@@ -728,7 +730,7 @@ IPA.association_facet = function (spec) {
};
that.add_adder_column = function(column) {
column.entity_name = that.managed_entity_name;
column.entity = that.other_entity;
that.adder_columns.put(column.name, column);
};
@@ -742,7 +744,7 @@ IPA.association_facet = function (spec) {
factory = IPA.column;
spec = { name: spec };
}
spec.entity_name = that.other_entity;
spec.entity = that.other_entity;
column = factory(spec);
that.add_adder_column(column);
return column;
@@ -755,7 +757,7 @@ IPA.association_facet = function (spec) {
var pkey_name;
if (that.other_entity) {
pkey_name = IPA.metadata.objects[that.other_entity].primary_key;
pkey_name = that.other_entity.metadata.primary_key;
}
if (!that.columns.length){
@@ -770,8 +772,7 @@ IPA.association_facet = function (spec) {
column.link = spec.link;
}
var other_entity = IPA.get_entity(that.other_entity);
that.init_table(other_entity);
that.init_table(that.other_entity);
var adder_columns = spec.adder_columns || [];
for (i=0; i<adder_columns.length; i++) {
@@ -788,7 +789,7 @@ IPA.association_facet = function (spec) {
adder_columns = that.adder_columns.values;
for (i=0; i<adder_columns.length; i++) {
column = adder_columns[i];
column.entity_name = that.other_entity;
column.entity = that.other_entity;
}
};
@@ -835,7 +836,7 @@ IPA.association_facet = function (spec) {
span.append(IPA.messages.association.show_results);
span.append(' ');
var name = that.entity.name+'-'+that.attribute_member+'-'+that.other_entity+'-type-radio';
var name = that.entity.name+'-'+that.attribute_member+'-'+that.other_entity.name+'-type-radio';
var direct_id = name + '-direct';
that.direct_radio = $('<input/>', {
@@ -880,9 +881,9 @@ IPA.association_facet = function (spec) {
that.get_attribute_name = function() {
if (that.association_type == 'direct') {
return that.attribute_member+'_'+that.other_entity;
return that.attribute_member+'_'+that.other_entity.name;
} else {
return that.indirect_attribute_member+'_'+that.other_entity;
return that.indirect_attribute_member+'_'+that.other_entity.name;
}
};
@@ -895,13 +896,14 @@ IPA.association_facet = function (spec) {
that.show_add_dialog = function() {
var entity_label = that.entity.metadata.label_singular;
var pkey = IPA.nav.get_state(that.entity.name+'-pkey');
var label = IPA.metadata.objects[that.other_entity] ? IPA.metadata.objects[that.other_entity].label : that.other_entity;
var other_entity_label = that.other_entity.metadata.label;
var title = that.add_title;
title = title.replace('${entity}', that.entity.metadata.label_singular);
title = title.replace('${entity}', entity_label);
title = title.replace('${primary_key}', pkey);
title = title.replace('${other_entity}', label);
title = title.replace('${other_entity}', other_entity_label);
var pkeys = that.data.result.result[that.get_attribute_name()];
@@ -924,16 +926,16 @@ IPA.association_facet = function (spec) {
var pkey = IPA.nav.get_state(that.entity.name+'-pkey');
var associator = that.associator({
'entity': that.entity,
'pkey': pkey,
'other_entity': that.other_entity,
'values': dialog.get_selected_values(),
'method': that.add_method,
'on_success': function() {
entity: that.entity,
pkey: pkey,
other_entity: that.other_entity,
values: dialog.get_selected_values(),
method: that.add_method,
on_success: function() {
that.refresh();
dialog.close();
},
'on_error': function() {
on_error: function() {
that.refresh();
dialog.close();
}
@@ -947,7 +949,6 @@ IPA.association_facet = function (spec) {
that.show_remove_dialog = function() {
var label = IPA.metadata.objects[that.other_entity] ? IPA.metadata.objects[that.other_entity].label : that.other_entity;
var values = that.table.get_selected_values();
if (!values.length) {
@@ -956,12 +957,14 @@ IPA.association_facet = function (spec) {
return;
}
var entity_label = that.entity.metadata.label_singular;
var pkey = IPA.nav.get_state(that.entity.name+'-pkey');
var other_entity_label = that.other_entity.metadata.label;
var title = that.remove_title;
title = title.replace('${entity}', that.entity.metadata.label_singular);
title = title.replace('${entity}', entity_label);
title = title.replace('${primary_key}', pkey);
title = title.replace('${other_entity}', label);
title = title.replace('${other_entity}', other_entity_label);
var dialog = IPA.association_deleter_dialog({
title: title,
@@ -1042,7 +1045,7 @@ IPA.association_facet = function (spec) {
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;
var page = parseInt(IPA.nav.get_state(that.entity.name+'-page'), 10) || 1;
if (that.table.current_page !== page) return true;
return false;

View File

@@ -245,10 +245,10 @@ IPA.automount_key_column = function(spec) {
href: '#'+key,
text: key,
click: function() {
var state = IPA.nav.get_path_state(that.entity_name);
state[that.entity_name + '-facet'] = 'default';
state[that.entity_name + '-info'] = info;
state[that.entity_name + '-pkey'] = key;
var state = IPA.nav.get_path_state(that.entity.name);
state[that.entity.name + '-facet'] = 'default';
state[that.entity.name + '-info'] = info;
state[that.entity.name + '-pkey'] = key;
IPA.nav.push_state(state);
return false;
}

View File

@@ -234,7 +234,7 @@ IPA.details_facet = function(spec) {
var that = IPA.facet(spec);
that.entity = spec.entity;
that.entity = IPA.get_entity(spec.entity);
that.update_command_name = spec.update_command_name || 'mod';
that.command_mode = spec.command_mode || 'save'; // [save, info]

View File

@@ -59,7 +59,7 @@ IPA.dialog = function(spec) {
var that = {};
that.entity = spec.entity;
that.entity = IPA.get_entity(spec.entity);
that.name = spec.name;
that.id = spec.id;
that.title = spec.title;

View File

@@ -72,8 +72,7 @@ IPA.entity = function(spec) {
};
that.get_containing_entity = function() {
return that.containing_entity ?
IPA.get_entity(that.containing_entity) : null;
return that.containing_entity;
};
that.get_dialog = function(name) {
@@ -93,7 +92,7 @@ IPA.entity = function(spec) {
};
that.dialog = function(dialog) {
dialog.entity_name = that.name;
dialog.entity = that;
that.dialogs.put(dialog.name, dialog);
return that;
};
@@ -143,7 +142,6 @@ IPA.entity = function(spec) {
};
that.add_facet = function(facet) {
facet.entity_name = that.name;
facet.entity = that;
that.facets.put(facet.name, facet);
@@ -321,6 +319,7 @@ IPA.entity_builder = function() {
} else {
spec = { name: spec };
}
spec.builder = that;
entity = factory(spec);
@@ -495,7 +494,7 @@ IPA.entity_builder = function() {
that.containing_entity = function(entity_name) {
add_redirect_info();
entity.containing_entity = entity_name;
entity.containing_entity = IPA.get_entity(entity_name);
return that;
};

View File

@@ -31,7 +31,7 @@ IPA.facet = function(spec) {
var that = {};
that.entity = spec.entity;
that.entity = IPA.get_entity(spec.entity);
that.name = spec.name;
that.label = spec.label;
@@ -43,7 +43,6 @@ IPA.facet = function(spec) {
that.header = spec.header || IPA.facet_header({ facet: that });
that.entity_name = spec.entity_name;
that._needs_update = spec.needs_update;
that.dialogs = $.ordered_map();
@@ -407,7 +406,7 @@ IPA.table_facet = function(spec) {
var that = IPA.facet(spec);
that.managed_entity_name = spec.managed_entity_name || that.entity.name;
that.managed_entity = spec.managed_entity ? IPA.get_entity(spec.managed_entity) : that.entity;
that.pagination = spec.pagination === undefined ? true : spec.pagination;
that.search_all = spec.search_all;
@@ -431,7 +430,7 @@ IPA.table_facet = function(spec) {
};
that.add_column = function(column) {
column.entity_name = that.managed_entity_name;
column.entity = that.managed_entity;
that.columns.put(column.name, column);
};
@@ -444,7 +443,7 @@ IPA.table_facet = function(spec) {
spec = { name: spec };
}
spec.entity_name = that.managed_entity_name;
spec.entity = that.managed_entity;
column = factory(spec);
that.add_column(column);
@@ -523,13 +522,13 @@ IPA.table_facet = function(spec) {
delete that.table.current_page;
var state = {};
var page = parseInt(IPA.nav.get_state(that.entity_name+'-page'), 10) || 1;
var page = parseInt(IPA.nav.get_state(that.entity.name+'-page'), 10) || 1;
if (page < 1) {
state[that.entity_name+'-page'] = 1;
state[that.entity.name+'-page'] = 1;
IPA.nav.push_state(state);
return;
} else if (page > that.table.total_pages) {
state[that.entity_name+'-page'] = that.table.total_pages;
state[that.entity.name+'-page'] = that.table.total_pages;
IPA.nav.push_state(state);
return;
}
@@ -597,7 +596,7 @@ IPA.table_facet = function(spec) {
};
that.get_records_command_name = function() {
return that.managed_entity_name+'_get_records';
return that.managed_entity.name+'_get_records';
};
that.get_records = function(on_success, on_error) {
@@ -682,7 +681,7 @@ IPA.table_facet = function(spec) {
that.table.prev_page = function() {
if (that.table.current_page > 1) {
var state = {};
state[that.entity_name+'-page'] = that.table.current_page - 1;
state[that.entity.name+'-page'] = that.table.current_page - 1;
IPA.nav.push_state(state);
}
};
@@ -690,7 +689,7 @@ IPA.table_facet = function(spec) {
that.table.next_page = function() {
if (that.table.current_page < that.table.total_pages) {
var state = {};
state[that.entity_name+'-page'] = that.table.current_page + 1;
state[that.entity.name+'-page'] = that.table.current_page + 1;
IPA.nav.push_state(state);
}
};
@@ -702,7 +701,7 @@ IPA.table_facet = function(spec) {
page = that.total_pages;
}
var state = {};
state[that.entity_name+'-page'] = page;
state[that.entity.name+'-page'] = page;
IPA.nav.push_state(state);
};
};

View File

@@ -29,7 +29,7 @@ IPA.field = function(spec) {
var that = {};
that.entity = spec.entity;
that.entity = IPA.get_entity(spec.entity);
that.container = null;
that.name = spec.name;
that.label = spec.label;
@@ -532,7 +532,7 @@ IPA.link_field = function(spec) {
var that = IPA.field(spec);
var other_entity = spec.other_entity;
that.other_entity = IPA.get_entity(spec.other_entity);
function other_pkeys () {
return that.entity.get_primary_key();
@@ -542,7 +542,7 @@ IPA.link_field = function(spec) {
that.on_link_clicked = function() {
IPA.nav.show_entity_page(
IPA.get_entity(other_entity),
that.other_entity,
'default',
that.other_pkeys());
};
@@ -556,7 +556,7 @@ IPA.link_field = function(spec) {
that.check_entity_link = function() {
IPA.command({
entity: other_entity,
entity: that.other_entity.name,
method: 'show',
args: that.other_pkeys(),
options: {},

View File

@@ -40,7 +40,7 @@ IPA.hbac.test_entity = function(spec) {
factory: IPA.hbac.test_select_facet,
name: 'user',
label: IPA.messages.objects.hbacrule.user,
managed_entity_name: 'user',
managed_entity: 'user',
disable_breadcrumb: true,
facet_group: 'default',
columns: [
@@ -53,7 +53,7 @@ IPA.hbac.test_entity = function(spec) {
factory: IPA.hbac.test_select_facet,
name: 'targethost',
label: IPA.messages.objects.hbacrule.host,
managed_entity_name: 'host',
managed_entity: 'host',
disable_breadcrumb: true,
facet_group: 'default',
columns: [
@@ -70,7 +70,7 @@ IPA.hbac.test_entity = function(spec) {
factory: IPA.hbac.test_select_facet,
name: 'service',
label: IPA.messages.objects.hbacrule.service,
managed_entity_name: 'hbacsvc',
managed_entity: 'hbacsvc',
disable_breadcrumb: true,
facet_group: 'default',
columns: [
@@ -82,7 +82,7 @@ IPA.hbac.test_entity = function(spec) {
factory: IPA.hbac.test_select_facet,
name: 'sourcehost',
label: IPA.messages.objects.hbacrule.sourcehost,
managed_entity_name: 'host',
managed_entity: 'host',
disable_breadcrumb: true,
facet_group: 'default',
columns: [
@@ -99,7 +99,7 @@ IPA.hbac.test_entity = function(spec) {
factory: IPA.hbac.test_rules_facet,
name: 'rules',
label: IPA.messages.objects.hbactest.rules,
managed_entity_name: 'hbacrule',
managed_entity: 'hbacrule',
disable_breadcrumb: true,
facet_group: 'default',
columns: [
@@ -115,7 +115,7 @@ IPA.hbac.test_entity = function(spec) {
factory: IPA.hbac.test_run_facet,
name: 'run_test',
label: IPA.messages.objects.hbactest.run_test,
managed_entity_name: 'hbacrule',
managed_entity: 'hbacrule',
disable_breadcrumb: true,
facet_group: 'default',
columns: [
@@ -145,13 +145,13 @@ IPA.hbac.test_facet = function(spec) {
var init = function() {
that.managed_entity = IPA.get_entity(that.managed_entity_name);
that.managed_entity = IPA.get_entity(that.managed_entity);
var columns = that.columns.values;
for (var i=0; i<columns.length; i++) {
var column = columns[i];
var metadata = IPA.get_entity_param(that.managed_entity_name, column.name);
var metadata = IPA.get_entity_param(that.managed_entity.name, column.name);
column.primary_key = metadata && metadata.primary_key;
column.link = column.primary_key;
}
@@ -753,7 +753,7 @@ IPA.hbac.test_run_facet = function(spec) {
if (!that.show_matched && that.show_unmatched) {
return 'hbactest_unmatched';
}
return that.managed_entity_name+'_get_records';
return that.managed_entity.name+'_get_records';
};
that.load_records = function(records) {
@@ -761,7 +761,7 @@ IPA.hbac.test_run_facet = function(spec) {
that.table.empty();
for (var i=0; i<records.length; i++) {
var record = records[i];
var pkey = record[pkey_name];
var pkey = record[pkey_name][0];
record.matched = that.matched[pkey];
that.table.add_record(record);
}

View File

@@ -432,7 +432,7 @@ IPA.dnszone_select_widget = function(spec) {
that.create_search_command = function(filter) {
return IPA.command({
entity: that.other_entity,
entity: that.other_entity.name,
method: 'find',
args: [filter],
options: {

View File

@@ -187,12 +187,11 @@ var IPA = function() {
if (!factory) return null;
try {
var builder = that.entity_builder();
var builder = IPA.entity_builder();
builder.entity({
factory: factory,
name: name,
builder: builder
name: name
});
var entity = builder.build();
@@ -222,6 +221,7 @@ var IPA = function() {
};
that.get_entity = function(name) {
if (typeof name === 'object') return name;
var entity = that.entities.get(name);
if (!entity) {
entity = that.create_entity(name);

View File

@@ -121,7 +121,7 @@ IPA.rule_association_table_widget = function(spec) {
that.create_column({
name: that.external,
label: IPA.messages.objects.sudorule.external,
entity_name: that.other_entity,
entity: that.other_entity,
format: IPA.boolean_format,
width: '200px'
});
@@ -133,7 +133,7 @@ IPA.rule_association_table_widget = function(spec) {
var entity_label = that.entity.metadata.label_singular;
var pkey = IPA.nav.get_state(that.entity.name+'-pkey');
var other_entity_label = IPA.metadata.objects[that.other_entity].label;
var other_entity_label = that.other_entity.metadata.label;
var title = that.add_title;
title = title.replace('${entity}', entity_label);
@@ -213,7 +213,7 @@ IPA.rule_association_table_field = function(spec) {
options: {all: true, rights: true}
});
command.set_option(that.widget.other_entity, values.join(','));
command.set_option(that.widget.other_entity.name, values.join(','));
update_info.append_command(command, that.priority);
}
}
@@ -240,7 +240,7 @@ IPA.rule_association_adder_dialog = function(spec) {
that.selected_table.add_rows(rows);
if (that.external) {
var pkey_name = IPA.metadata.objects[that.other_entity].primary_key;
var pkey_name = that.other_entity.metadata.primary_key;
var value = that.external_field.val();
if (!value) return;

View File

@@ -29,7 +29,7 @@ IPA.search_facet = function(spec) {
spec = spec || {};
spec.name = spec.name || 'search';
spec.managed_entity_name = spec.managed_entity_name || spec.entity.name;
spec.managed_entity = spec.managed_entity ? IPA.get_entity(spec.managed_entity) : spec.entity;
spec.disable_breadcrumb =
spec.disable_breadcrumb === undefined ? true : spec.disable_breadcrumb;
@@ -46,8 +46,6 @@ IPA.search_facet = function(spec) {
var init = function() {
that.managed_entity = IPA.get_entity(that.managed_entity_name);
that.init_table(that.managed_entity);
};
@@ -160,7 +158,7 @@ IPA.search_facet = function(spec) {
that.find = function() {
var filter = that.filter.val();
var state = {};
state[that.managed_entity_name + '-filter'] = filter;
state[that.managed_entity.name + '-filter'] = filter;
IPA.nav.push_state(state);
};
@@ -311,7 +309,7 @@ IPA.nested_search_facet = function(spec) {
spec = spec || {};
spec.managed_entity_name = spec.nested_entity;
spec.managed_entity = IPA.get_entity(spec.nested_entity);
spec.disable_breadcrumb = false;
spec.disable_facet_tabs = false;
@@ -325,7 +323,7 @@ IPA.nested_search_facet = function(spec) {
IPA.nav.get_state(IPA.current_entity.name+'-pkey'));
if (that.filter) {
var filter = IPA.nav.get_state(that.managed_entity_name+'-filter');
var filter = IPA.nav.get_state(that.managed_entity.name+'-filter');
that.filter.val(filter);
}
};

View File

@@ -658,7 +658,7 @@ IPA.sudo.options_section = function(spec) {
that.table.create_column({
name: 'ipasudoopt',
label: IPA.get_command_option('sudorule_add_option', 'ipasudoopt').label,
entity_name:that.entity.name,
entity: that.entity,
primary_key: true
});

View File

@@ -20,7 +20,6 @@
<script type="text/javascript" src="../association.js"></script>
<script type="text/javascript" src="../navigation.js"></script>
<script type="text/javascript" src="../aci.js"></script>
<script type="text/javascript" src="aci_tests.js"></script>
</head>
<body>

View File

@@ -22,7 +22,8 @@
var target_container;
var target_widget;
var target_facet;
var entity = IPA.entity({ name:'bogus', metadata: {} });
var entity = IPA.entity({ name: 'bogus' });
var group_entity = IPA.entity({ name: 'group' });
module('aci', {
setup: function() {
@@ -74,6 +75,7 @@ module('aci', {
{
type: 'permission_target',
container_factory: IPA.details_table_section,
group_entity: group_entity,
name: 'target',
label: 'Target',
show_target: false

View File

@@ -13,6 +13,7 @@
<script type="text/javascript" src="../search.js"></script>
<script type="text/javascript" src="../add.js"></script>
<script type="text/javascript" src="../association.js"></script>
<script type="text/javascript" src="../entity.js"></script>
<script type="text/javascript" src="association_tests.js"></script>
</head>
<body>

View File

@@ -27,11 +27,14 @@ test("Testing serial_associator().", function() {
var orig_ipa_batch_command = IPA.batch_command;
var user = IPA.entity({ name: 'user' });
var group = IPA.entity({ name: 'group' });
var params = {
method: 'add_member',
pkey: 'test',
entity: {name:'user'},
other_entity: 'group'
entity: user,
other_entity: group
};
params.values = ['user1', 'user2', 'user3'];
@@ -50,7 +53,7 @@ test("Testing serial_associator().", function() {
command = that.commands[i];
equals(
command.entity, params.other_entity,
command.entity, params.other_entity.name,
'Checking IPA.command() parameter: entity');
equals(
@@ -86,11 +89,14 @@ test("Testing bulk_associator().", function() {
var counter = 0;
var user = IPA.entity({ name: 'user' });
var group = IPA.entity({ name: 'group' });
var params = {
method: "add_member",
pkey: "test",
entity: {name:"user"},
other_entity: "group"
method: 'add_member',
pkey: 'test',
entity: user,
other_entity: group
};
params.values = ['user1', 'user2', 'user3'];
@@ -111,7 +117,7 @@ test("Testing bulk_associator().", function() {
'Checking IPA.command() parameter: primary key');
equals(
that.options[params.other_entity], 'user1,user2,user3',
that.options[params.other_entity.name], 'user1,user2,user3',
'Checking IPA.command() parameter: options[\""+params.other_entity+"\"]');
that.on_success({});

View File

@@ -15,7 +15,6 @@
<script type="text/javascript" src="../details.js"></script>
<script type="text/javascript" src="../facet.js"></script>
<script type="text/javascript" src="../entity.js"></script>
<script type="text/javascript" src="details_tests.js"></script>
</head>
<body>

View File

@@ -4,7 +4,6 @@
<title>Core Test Suite</title>
<link rel="stylesheet" href="qunit.css" type="text/css" media="screen">
<link rel="stylesheet" type="text/css" href="../jquery-ui.css" />
<script type="text/javascript" src="qunit.js"></script>
<script type="text/javascript" src="../jquery.js"></script>
<script type="text/javascript" src="../jquery.ba-bbq.js"></script>

View File

@@ -4,7 +4,6 @@
<title>Ordered Map Test Suite</title>
<link rel="stylesheet" href="qunit.css" type="text/css" media="screen">
<link rel="stylesheet" type="text/css" href="../jquery-ui.css" />
<script type="text/javascript" src="qunit.js"></script>
<script type="text/javascript" src="../jquery.js"></script>
<script type="text/javascript" src="../jquery.ordered-map.js"></script>

View File

@@ -4,16 +4,13 @@
<title>Widget Test Suite</title>
<link rel="stylesheet" href="qunit.css" type="text/css" media="screen">
<script type="text/javascript" src="qunit.js"></script>
<script type="text/javascript" src="../jquery.js"></script>
<script type="text/javascript" src="../jquery.ba-bbq.js"></script>
<script type="text/javascript" src="../jquery-ui.js"></script>
<script type="text/javascript" src="../jquery.ordered-map.js"></script>
<script type="text/javascript" src="../ipa.js"></script>
<script type="text/javascript" src="../widget.js"></script>
<script type="text/javascript" src="../entity.js"></script>
<script type="text/javascript" src="widget_tests.js"></script>
</head>
<body>

View File

@@ -55,7 +55,6 @@ function base_widget_test(value){
widget = factory(spec);
var entity_name = 'user';
var field_name = widget.name;
ok (widget, "Created Widget");
@@ -151,16 +150,14 @@ test("IPA.table_widget" ,function(){
name:'uid',
label:'User ID',
primary_key:'uid',
width:'20em',
entity_name:'user'
width:'20em'
}));
widget.add_column(IPA.column({
entity: spec.entity,
name:'title',
lable:'Title',
primary_key:'uid',
width:'20em',
entity_name:'user'
width:'20em'
}));
ok(!widget.container,'widget has no container before create');
@@ -269,13 +266,14 @@ test("IPA.select_widget" ,function(){
});
test("IPA.entity_select_widget" ,function(){
test("IPA.entity_select_widget" ,function() {
var user = IPA.entity({ name: 'user' });
factory = IPA.entity_select_widget;
spec = {
name: 'uid',
other_entity:'user',
field_name:'uid',
other_field: 'uid' };
other_entity: user,
other_field: 'uid'
};
base_widget_test('test_value');
var mock_record = { uid: ['kfrog']};

View File

@@ -36,7 +36,7 @@ IPA.widget = function(spec) {
that.id = spec.id;
that.label = spec.label;
that.tooltip = spec.tooltip;
that.entity = spec.entity; //some old widgets still need it
that.entity = IPA.get_entity(spec.entity); //some old widgets still need it
that.create = function(container) {
container.addClass('widget');
@@ -932,20 +932,20 @@ IPA.column = function (spec) {
var that = {};
that.entity = IPA.get_entity(spec.entity);
that.name = spec.name;
that.label = spec.label;
that.width = spec.width;
that.entity_name = spec.entity ? spec.entity.name : spec.entity_name;
that.primary_key = spec.primary_key;
that.link = spec.link;
that.format = spec.format;
if (!that.entity_name){
var except = {
if (!that.entity) {
throw {
expected: false,
message:'Column created without an entity_name.'
message: 'Column created without an entity.'
};
throw except;
}
that.setup = function(container, record, suppress_link) {
@@ -978,8 +978,8 @@ IPA.column = function (spec) {
/*column initialization*/
if (that.entity_name && !that.label) {
var metadata = IPA.get_entity_param(that.entity_name, that.name);
if (that.entity && !that.label) {
var metadata = IPA.get_entity_param(that.entity.name, that.name);
if (metadata) {
that.label = metadata.label;
}
@@ -1726,14 +1726,14 @@ IPA.entity_select_widget = function(spec) {
var that = IPA.combobox_widget(spec);
that.other_entity = spec.other_entity;
that.other_entity = IPA.get_entity(spec.other_entity);
that.other_field = spec.other_field;
that.options = spec.options || [];
that.create_search_command = function(filter) {
return IPA.command({
entity: that.other_entity,
entity: that.other_entity.name,
method: 'find',
args: [filter]
});