diff --git a/install/static/add.js b/install/static/add.js index 97f7666a1..fcbcc5293 100644 --- a/install/static/add.js +++ b/install/static/add.js @@ -22,34 +22,31 @@ /* REQUIRES: ipa.js */ -/* - * An associatev array between entity names and their builders - */ -var builders = {} ; - - -function add_fail(desc){ - alert(desc); -} - //Process for managing the 'add' functionality -function EntityBuilder(obj,addProperties,addOptionsFunction ){ +function EntityBuilder(obj,addProperties){ + + var builder = this; + this.obj = obj; this.addProperties = addProperties; - if (addOptionsFunction){ - this.addOptionsFunction = addOptionsFunction; - }else{ - this.addOptionsFunction = function(){ - var options = { }; - return options; - } + + this.getPKey = function(){ + return $("#pkey").val(); } - 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.getOptions = function(){ + return {}; + } + + this.add_fail = function(desc){ + alert(desc); + } + + this.add = function(pkey, on_success){ + var params = [pkey]; + var options = this.getOptions(); + ipa_cmd( 'add', params, options, on_success, this.add_fail, this.obj ); } this.setup = function(){ @@ -58,24 +55,53 @@ function EntityBuilder(obj,addProperties,addOptionsFunction ){ $("
") .appendTo("#content"); var label =$("Add and ").appendTo("#addForm") - $("", - {id:'addEdit', - type:'button', - value:'Edit', - click: function(){ - var params = ipa_parse_qs(); - builders[params["tab"]].add (addEdit) - } - }).appendTo(label); + + $("", { + id:'addEdit', + type:'button', + value:'Edit', + click: function(){ + var params = ipa_parse_qs(); + 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); + $("", { id:'addAnother', type:'button', value:'Add Another', click: function(){ - var params = ipa_parse_qs(); - builders[params["tab"]].add (addAnother) + var params = ipa_parse_qs(); + 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("#addForm"); for (index = 0; index < this.addProperties.length; index++){ @@ -90,29 +116,7 @@ function EntityBuilder(obj,addProperties,addOptionsFunction ){ 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; -} diff --git a/install/static/hostgroup.js b/install/static/hostgroup.js index 2f40f0b3f..3872d125d 100644 --- a/install/static/hostgroup.js +++ b/install/static/hostgroup.js @@ -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(); function HostgroupsForms(){ @@ -75,7 +67,15 @@ function HostgroupsForms(){ 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.unspecified = this.search; diff --git a/install/static/netgroup.js b/install/static/netgroup.js index 295e41366..4fcaffa98 100644 --- a/install/static/netgroup.js +++ b/install/static/netgroup.js @@ -2,14 +2,6 @@ function setupNetgroup(facet){ netgroupForms.setup(facet); } -function netgroupAddOptionsFunction (){ - var options = { - name: $('#pkey').val(), - description: $('#description').val() - }; - return options; -} - var netgroupForms = new NetgroupForms(); function NetgroupForms(){ @@ -39,8 +31,16 @@ function NetgroupForms(){ [{title: 'Netgroup Name', id: 'pkey', type: 'text'}, {title: 'Description', id: 'description', type: 'text'}]; - this.add = new EntityBuilder("netgroup",this.add_properties, - netgroupAddOptionsFunction); + this.add = new EntityBuilder("netgroup",this.add_properties); + + this.add.getOptions = function() { + var options = { + name: $('#pkey').val(), + description: $('#description').val() + }; + return options; + } + this.search = new SearchForm("netgroup", "find", this.netgroupSearchColumns); this.userListColumns = [ {title:"user",column:"memberuser_user", }]; diff --git a/install/static/service.js b/install/static/service.js index 467e56a81..852415ffb 100644 --- a/install/static/service.js +++ b/install/static/service.js @@ -55,22 +55,19 @@ function ServiceForms() { ); 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( "service", - this.addProperties, - this.addOptionsFunction + this.addProperties ); + this.add.getPKey = function() { + return $("#service").val()+"/"+$("#host").val(); + } + this.searchColumns = [ { title: "Service", diff --git a/install/static/user.js b/install/static/user.js index a0087e278..dca999a1a 100644 --- a/install/static/user.js +++ b/install/static/user.js @@ -83,16 +83,18 @@ var userAddProperties = [ {title: 'First Name', id: 'firstname', type:'text'}, {title: 'Last Name', id: 'lastname', type:'text'} ]; + var userBuilder = new EntityBuilder( "user", - userAddProperties, - function(){ - var options = { givenname: $("#firstname").val(), - sn: $("#lastname").val()}; - return options; - }); + userAddProperties); +userBuilder.getOptions = function() { + var options = { + givenname: $("#firstname").val(), + sn: $("#lastname").val()}; + return options; +} var userFacets = ["details","group", "groupmembership"];