Entity association configuration.

The ipa_entity_set_association_definition() has been added to configure
the association between 2 entitites. By default the associator is
BulkAssociator and the method is add_member. The entities have been
updated to use the right configurations.

The ipa_cmd() has been modified to detect IPA errors and invoke the
error handler.

A bug in refresh_on_success() has been fixed as well.
This commit is contained in:
Endi S. Dewata
2010-10-01 16:33:57 -05:00
committed by Adam Young
parent aa7ecb6f5f
commit b7097fc8c9
9 changed files with 78 additions and 26 deletions

View File

@@ -42,14 +42,14 @@ function SerialAssociator(form, manyObjPkeys, on_success)
var args = [manyObjPkey];
ipa_cmd( form.method,args, options ,
function(response){
if (response.error){
alert("error adding member: "+response.error.message);
function(data, text_status, xhr) {
if (data.error){
alert("error adding member: "+data.error.message);
}else{
associator.associateNext();
}
},
function(response){
function(xhr, text_status, error_thrown) {
alert("associateFailure");
},
form.manyObj );
@@ -85,14 +85,14 @@ function BulkAssociator(form, manyObjPkeys, on_success)
var args = [form.pkey];
ipa_cmd( form.method,args, options ,
function(response){
if (response.error){
alert("error adding member: "+response.error.message);
function(data, text_status, xhr) {
if (data.error){
alert("error adding member: "+data.error.message);
}else{
associator.on_success();
}
},
function(response){
function(xhr, text_status, error_thrown) {
alert("associateFailure");
},
form.oneObj );
@@ -124,7 +124,7 @@ function AssociationForm(oneObj, pkey, manyObj, on_success, associatorConstructo
if (associatorConstructor)
this.associatorConstructor = associatorConstructor;
else
this.associatorConstructor = SerialAssociator;
this.associatorConstructor = BulkAssociator;
this.setup = function() {
var label = ipa_objs[form.manyObj].label;
@@ -212,7 +212,7 @@ function AssociationForm(oneObj, pkey, manyObj, on_success, associatorConstructo
/**
A modfied version of search. It shows the associations for an object.
*/
function AssociationList(obj, pkey, manyObj, associationColumns, jobj)
function AssociationList(obj, pkey, manyObj, associationColumns, jobj, associationConstructor, method)
{
var form = this;
@@ -220,20 +220,22 @@ function AssociationList(obj, pkey, manyObj, associationColumns, jobj)
this.pkey = pkey;
this.associationColumns = associationColumns;
this.manyObj = manyObj;
this.parentTab = jobj;
this.container = jobj;
this.associationConstructor = associationConstructor;
this.method = method;
this.refresh = function() {
function refresh_on_success(userData) {
var tbody = this.parentTab.find('.search-table tbody');
tbody.empty();
var associationList = userData.result.result[this.associationColumns[0].column];
for (var j = 0; j < associationList.length; j++){
function refresh_on_success(data, text_status, xhr) {
var tbody = form.container.find('.search-table tbody');
tbody.empty();
var associationList = data.result.result[form.associationColumns[0].column];
for (var j = 0; j < associationList.length; j++){
var row = $("<tr/>").appendTo(tbody);
for (var k = 0; k < associationColumns.length ;k++){
var column = this.associationColumns[k].column;
var column = form.associationColumns[k].column;
$("<td></td>",{
html: userData.result.result[column][j]
html: data.result.result[column][j]
}).appendTo(row);
}
}
@@ -249,17 +251,17 @@ function AssociationList(obj, pkey, manyObj, associationColumns, jobj)
}
this.setup = function() {
association_list_create(this.obj, this.parentTab);
this.parentTab.find(".search-filter").css("display", "none");
this.parentTab.find(".search-buttons").html("");
association_list_create(this.obj, this.container);
this.container.find(".search-filter").css("display", "none");
this.container.find(".search-buttons").html("");
$("<input/>", {
type: 'button',
value: 'enroll',
click: function() {
form.show_enrollment_dialog();
}
}).appendTo(this.parentTab.find(".search-buttons"));
var header = $("<tr></tr>").appendTo(this.parentTab.find('.search-table thead:last'));
}).appendTo(this.container.find(".search-buttons"));
var header = $("<tr></tr>").appendTo(this.container.find('.search-table thead:last'));
for (var i =0 ; i != associationColumns.length ;i++){
$("<th></th>",{
html: associationColumns[i].title
@@ -277,7 +279,9 @@ function AssociationList(obj, pkey, manyObj, associationColumns, jobj)
function() {
form.refresh();
enrollment_dialog.close();
}
},
this.associationConstructor,
this.method
);
enrollment_dialog.setup();
}

View File

@@ -1,5 +1,6 @@
/* Authors:
* Pavel Zuna <pzuna@redhat.com>
* Endi S. Dewata <edewata@redhat.com>
*
* Copyright (C) 2010 Red Hat
* see file 'COPYING' for use and warranty information
@@ -23,6 +24,7 @@
var ipa_entity_search_list = {};
var ipa_entity_add_list = {};
var ipa_entity_details_list = {};
var ipa_entity_association_list = {};
/* use this to track individual changes between two hashchange events */
var window_hash_cache = {};
@@ -42,6 +44,11 @@ function ipa_entity_set_details_definition(obj_name, data)
ipa_entity_details_list[obj_name] = data;
}
function ipa_entity_set_association_definition(obj_name, data)
{
ipa_entity_association_list[obj_name] = data;
}
function ipa_entity_setup(container)
{
var id = container.attr('id');
@@ -151,7 +158,17 @@ function _ipa_entity_setup(jobj) {
column: attr + '_' + enroll_obj_name
}
];
var frm = new AssociationList(obj_name, pkey, enroll_obj_name, columns, jobj);
var association = ipa_entity_association_list[obj_name];
var association_config = association ? association[enroll_obj_name] : null;
var associator = association_config ? association_config.associator : null;
var method = association_config ? association_config.method : null;
var frm = new AssociationList(
obj_name, pkey, enroll_obj_name, columns, jobj,
associator, method
);
ipa_entity_generate_views(obj_name, jobj, switch_view);
frm.setup();
};

View File

@@ -44,6 +44,12 @@ ipa_entity_set_details_definition('group', [
]]
]);
ipa_entity_set_association_definition('group', {
'netgroup': { associator: SerialAssociator },
'rolegroup': { associator: SerialAssociator },
'taskgroup': { associator: SerialAssociator }
});
function f_posix(dlg, mode)
{
function checkbox_on_click() {

View File

@@ -42,3 +42,7 @@ ipa_entity_set_details_definition('host', [
]]
]);
ipa_entity_set_association_definition('host', {
'hostgroup': { associator: SerialAssociator },
'rolegroup': { associator: SerialAssociator }
});

View File

@@ -39,4 +39,3 @@ ipa_entity_set_details_definition('hostgroup', [
['description', 'Description', null]
]]
]);

View File

@@ -83,6 +83,13 @@ function ipa_cmd(name, args, options, win_callback, fail_callback, objname)
}
ipa_error_handler(xhr, text_status, error_thrown);
} else if (data.error) {
var error_thrown = {
name: 'IPA Error '+data.error.code,
message: data.error.message
}
ipa_error_handler(xhr, text_status, error_thrown);
} else if (win_callback) {
win_callback(data, text_status, xhr);
}

View File

@@ -39,3 +39,7 @@ ipa_entity_set_details_definition('rolegroup', [
['description', 'Description', null],
]]
]);
ipa_entity_set_association_definition('rolegroup', {
'taskgroup': { associator: SerialAssociator }
});

View File

@@ -47,3 +47,7 @@ function service_add_krbprincipalname(add_dialog, flag) {
}
return null;
}
ipa_entity_set_association_definition('service', {
'host': { method: 'add_host' }
});

View File

@@ -74,6 +74,13 @@ ipa_entity_set_details_definition('user', [
]]
]);
ipa_entity_set_association_definition('user', {
'group': { associator: SerialAssociator },
'netgroup': { associator: SerialAssociator },
'rolegroup': { associator: SerialAssociator },
'taskgroup': { associator: SerialAssociator }
});
/* Account status Toggle button */
function toggle_on_click(obj)