Splitting service principal into service name and hostname.

The EntityBuilder has been modified to obtain the pkey value by
invoking getPKey(). This function can be overriden for different
entities.

The addOptionsFunction() has been renamed to getOptions() and it
can be overriden for different entities. Each entity that uses this
function has been modified accordingly.

The addEdit(), addAnother(), add_fail() has been moved into the
EntityBuilder class. The global builders is no longer needed because
a reference to the builder object can be obtained via enclosure.

The ServiceForms has been modified to take service name and
hostname and combine them to generate the service principal by
overriding the getPKey().
This commit is contained in:
Endi DeWata 2010-09-10 12:59:33 -04:00 committed by Adam Young
parent f87bd57c1d
commit fd056918e6
5 changed files with 93 additions and 90 deletions

View File

@ -22,34 +22,31 @@
/* REQUIRES: ipa.js */ /* REQUIRES: ipa.js */
/*
* An associatev array between entity names and their builders
*/
var builders = {} ;
//Process for managing the 'add' functionality
function EntityBuilder(obj,addProperties){
function add_fail(desc){ var builder = this;
this.obj = obj;
this.addProperties = addProperties;
this.getPKey = function(){
return $("#pkey").val();
}
this.getOptions = function(){
return {};
}
this.add_fail = function(desc){
alert(desc); alert(desc);
} }
this.add = function(pkey, on_success){
//Process for managing the 'add' functionality var params = [pkey];
function EntityBuilder(obj,addProperties,addOptionsFunction ){ var options = this.getOptions();
this.obj = obj; ipa_cmd( 'add', params, options, on_success, this.add_fail, this.obj );
this.addProperties = addProperties;
if (addOptionsFunction){
this.addOptionsFunction = addOptionsFunction;
}else{
this.addOptionsFunction = function(){
var options = { };
return options;
}
}
this.add = function(on_success){
var options = this.addOptionsFunction();
var params = [$("#pkey").val()];
ipa_cmd( 'add', params, options, on_success, add_fail, this.obj );
} }
this.setup = function(){ this.setup = function(){
@ -58,24 +55,53 @@ function EntityBuilder(obj,addProperties,addOptionsFunction ){
$("<div id='addForm'> </div>") $("<div id='addForm'> </div>")
.appendTo("#content"); .appendTo("#content");
var label =$("<span>Add and </span>").appendTo("#addForm") var label =$("<span>Add and </span>").appendTo("#addForm")
$("<input \>",
{id:'addEdit', $("<input \>", {
id:'addEdit',
type:'button', type:'button',
value:'Edit', value:'Edit',
click: function(){ click: function(){
var params = ipa_parse_qs(); var params = ipa_parse_qs();
builders[params["tab"]].add (addEdit) var pkey = builder.getPKey();
builder.add(pkey, function(response){
if (response.error){
if (response.error.message) {
alert(response.error.message);
} else {
alert("error adding entry");
}
return;
}
var hash= "tab="
+params["tab"]
+"&facet=details&pkey="
+pkey;
window.location.hash = hash;
});
} }
}).appendTo(label); }).appendTo(label);
$("<input\>", { $("<input\>", {
id:'addAnother', id:'addAnother',
type:'button', type:'button',
value:'Add Another', value:'Add Another',
click: function(){ click: function(){
var params = ipa_parse_qs(); var params = ipa_parse_qs();
builders[params["tab"]].add (addAnother) var pkey = builder.getPKey();
builder.add(pkey, function(response){
if (response.error){
if (response.error.message) {
alert(response.error.message);
} else {
alert("error adding entry");
}
return;
}
builder.setup();
});
} }
}).appendTo(label); }).appendTo(label);
$("<dl id='addProperties' />").appendTo("#addForm"); $("<dl id='addProperties' />").appendTo("#addForm");
for (index = 0; index < this.addProperties.length; index++){ for (index = 0; index < this.addProperties.length; index++){
@ -90,29 +116,7 @@ function EntityBuilder(obj,addProperties,addOptionsFunction ){
title.appendTo("#addProperties"); title.appendTo("#addProperties");
} }
} }
//register the new object with the associatev array of builders.
builders[obj] = this;
} }
function addAnother(response){
if (response.error){
alert("error adding entry");
return;
}
var params = ipa_parse_qs();
builders[params["tab"]].setup();
}
function addEdit(response){
if (response.error){
alert("error adding entry");
return;
}
var params = ipa_parse_qs();
var hash= "tab="
+ params["tab"]
+"&facet=details&pkey="
+$("#pkey").val();
window.location.hash = hash;
}

View File

@ -12,14 +12,6 @@ var hostgroupFacets = ["details","hosts","assignhosts"];
function hostgroupAddOptionsFunction (){
var options = {
name: $('#pkey').val(),
description: $('#description').val()
};
return options;
}
var hostgroupForms = new HostgroupsForms(); var hostgroupForms = new HostgroupsForms();
function HostgroupsForms(){ function HostgroupsForms(){
@ -75,7 +67,15 @@ function HostgroupsForms(){
this.details = new DetailsForm("hostgroup",hostgroup_details_list,"cn",hostgroupFacets) ; this.details = new DetailsForm("hostgroup",hostgroup_details_list,"cn",hostgroupFacets) ;
this.add = new EntityBuilder("hostgroup",this.hostgroupAddProperties,hostgroupAddOptionsFunction); this.add = new EntityBuilder("hostgroup",this.hostgroupAddProperties);
this.add.getOptions = function() {
var options = {
name: $('#pkey').val(),
description: $('#description').val()
};
return options;
}
this.search = new SearchForm("hostgroup", "find", this.hostgroupSearchColumns); this.search = new SearchForm("hostgroup", "find", this.hostgroupSearchColumns);
this.unspecified = this.search; this.unspecified = this.search;

View File

@ -2,14 +2,6 @@ function setupNetgroup(facet){
netgroupForms.setup(facet); netgroupForms.setup(facet);
} }
function netgroupAddOptionsFunction (){
var options = {
name: $('#pkey').val(),
description: $('#description').val()
};
return options;
}
var netgroupForms = new NetgroupForms(); var netgroupForms = new NetgroupForms();
function NetgroupForms(){ function NetgroupForms(){
@ -39,8 +31,16 @@ function NetgroupForms(){
[{title: 'Netgroup Name', id: 'pkey', type: 'text'}, [{title: 'Netgroup Name', id: 'pkey', type: 'text'},
{title: 'Description', id: 'description', type: 'text'}]; {title: 'Description', id: 'description', type: 'text'}];
this.add = new EntityBuilder("netgroup",this.add_properties, this.add = new EntityBuilder("netgroup",this.add_properties);
netgroupAddOptionsFunction);
this.add.getOptions = function() {
var options = {
name: $('#pkey').val(),
description: $('#description').val()
};
return options;
}
this.search = new SearchForm("netgroup", "find", this.netgroupSearchColumns); this.search = new SearchForm("netgroup", "find", this.netgroupSearchColumns);
this.userListColumns = [ {title:"user",column:"memberuser_user", }]; this.userListColumns = [ {title:"user",column:"memberuser_user", }];

View File

@ -55,22 +55,19 @@ function ServiceForms() {
); );
this.addProperties = [ this.addProperties = [
{title: 'Principal', id: 'pkey', type: 'text'} {title: 'Service', id: 'service', type: 'text'},
{title: 'Host Name', id: 'host', type: 'text'}
]; ];
this.addOptionsFunction = function() {
var options = {
name: $('#pkey').val()
};
return options;
};
this.add = new EntityBuilder( this.add = new EntityBuilder(
"service", "service",
this.addProperties, this.addProperties
this.addOptionsFunction
); );
this.add.getPKey = function() {
return $("#service").val()+"/"+$("#host").val();
}
this.searchColumns = [ this.searchColumns = [
{ {
title: "Service", title: "Service",

View File

@ -83,16 +83,18 @@ var userAddProperties = [
{title: 'First Name', id: 'firstname', type:'text'}, {title: 'First Name', id: 'firstname', type:'text'},
{title: 'Last Name', id: 'lastname', type:'text'} {title: 'Last Name', id: 'lastname', type:'text'}
]; ];
var userBuilder = var userBuilder =
new EntityBuilder( new EntityBuilder(
"user", "user",
userAddProperties, userAddProperties);
function(){
var options = { givenname: $("#firstname").val(), userBuilder.getOptions = function() {
var options = {
givenname: $("#firstname").val(),
sn: $("#lastname").val()}; sn: $("#lastname").val()};
return options; return options;
}); }
var userFacets = ["details","group", "groupmembership"]; var userFacets = ["details","group", "groupmembership"];