From dde15772700da41ec931bb55087fbec6f30fab55 Mon Sep 17 00:00:00 2001 From: Adam Young Date: Tue, 7 Sep 2010 10:08:19 -0400 Subject: associations -Refactored the associations code into a set of objects that are configured by the entities -Added support for associations that can be done in a single rpc -hostgroup to host and group to user associations working -Restructed sampledata so that the file is matched automatically by the RPC method name -The new ipa_cmd/sampledata scheme insists on there being sample data for any commands or the ipa_command fails. -Added sampledata files for all the calls we make -renamed several of the sampledata files to match their rpc calls -Started a pattern of refactoring where all the forms for the entity fall under a single object --- install/static/Makefile.am | 1 + install/static/associate.js | 256 ++ install/static/details.js | 12 +- install/static/group.js | 59 +- install/static/host.js | 16 +- install/static/hostgroup.js | 80 +- install/static/index.xhtml | 31 +- install/static/ipa.js | 14 +- install/static/navigation.js | 37 +- install/static/netgroup.js | 5 +- install/static/sampledata/group_add.json | 31 + install/static/sampledata/group_add_member.json | 25 + install/static/sampledata/group_find.json | 75 + install/static/sampledata/group_show.json | 38 + install/static/sampledata/grouplist.json | 75 - install/static/sampledata/groupshow.json | 38 - install/static/sampledata/host_add.json | 40 + install/static/sampledata/host_find.json | 45 + install/static/sampledata/host_show.json | 56 + install/static/sampledata/hostgroup_add.json | 27 + .../static/sampledata/hostgroup_add_member.json | 37 + install/static/sampledata/hostgroup_find.json | 33 + install/static/sampledata/hostgroup_show.json | 22 + install/static/sampledata/hostgrouplist.json | 33 - install/static/sampledata/hostgroupshow.json | 17 - install/static/sampledata/hostlist.json | 45 - install/static/sampledata/hostshow.json | 56 - install/static/sampledata/json_metadata.json | 3362 ++++++++++++++++++++ install/static/sampledata/metadata.json | 3362 -------------------- install/static/sampledata/netgroup_add.json | 28 + install/static/sampledata/netgroup_find.json | 56 + install/static/sampledata/netgroup_show.json | 26 + install/static/sampledata/netgrouplist.json | 56 - install/static/sampledata/netgroupshow.json | 26 - install/static/sampledata/user_add.json | 50 + install/static/sampledata/user_find.json | 246 ++ install/static/sampledata/user_show.json | 71 + install/static/sampledata/userlist.json | 246 -- install/static/sampledata/usershow.json | 71 - install/static/search.js | 110 +- install/static/user.js | 168 +- 41 files changed, 4767 insertions(+), 4315 deletions(-) create mode 100644 install/static/associate.js create mode 100644 install/static/sampledata/group_add.json create mode 100644 install/static/sampledata/group_add_member.json create mode 100644 install/static/sampledata/group_find.json create mode 100644 install/static/sampledata/group_show.json delete mode 100644 install/static/sampledata/grouplist.json delete mode 100644 install/static/sampledata/groupshow.json create mode 100644 install/static/sampledata/host_add.json create mode 100644 install/static/sampledata/host_find.json create mode 100644 install/static/sampledata/host_show.json create mode 100644 install/static/sampledata/hostgroup_add.json create mode 100644 install/static/sampledata/hostgroup_add_member.json create mode 100644 install/static/sampledata/hostgroup_find.json create mode 100644 install/static/sampledata/hostgroup_show.json delete mode 100644 install/static/sampledata/hostgrouplist.json delete mode 100644 install/static/sampledata/hostgroupshow.json delete mode 100644 install/static/sampledata/hostlist.json delete mode 100644 install/static/sampledata/hostshow.json create mode 100644 install/static/sampledata/json_metadata.json delete mode 100644 install/static/sampledata/metadata.json create mode 100644 install/static/sampledata/netgroup_add.json create mode 100644 install/static/sampledata/netgroup_find.json create mode 100644 install/static/sampledata/netgroup_show.json delete mode 100644 install/static/sampledata/netgrouplist.json delete mode 100644 install/static/sampledata/netgroupshow.json create mode 100644 install/static/sampledata/user_add.json create mode 100644 install/static/sampledata/user_find.json create mode 100644 install/static/sampledata/user_show.json delete mode 100644 install/static/sampledata/userlist.json delete mode 100644 install/static/sampledata/usershow.json (limited to 'install/static') diff --git a/install/static/Makefile.am b/install/static/Makefile.am index 366975ebf..63e58943c 100644 --- a/install/static/Makefile.am +++ b/install/static/Makefile.am @@ -3,6 +3,7 @@ NULL = appdir = $(IPA_DATA_DIR)/static app_DATA = \ add.js \ + associate.js \ but-reset.png \ but-update.png \ but-selected.png \ diff --git a/install/static/associate.js b/install/static/associate.js new file mode 100644 index 000000000..748c40e63 --- /dev/null +++ b/install/static/associate.js @@ -0,0 +1,256 @@ +/* Authors: + * Adam Young + * + * Copyright (C) 2010 Red Hat + * see file 'COPYING' for use and warranty information + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; version 2 only + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* IPA Object Add - creating new instances of entities */ + +/* REQUIRES: ipa.js */ + +function keyForFacet(tab, facet){ + qs = ipa_parse_qs(); + var key = qs['tab'] +'-'+ qs['facet']; + return key; +} + +/** +*This associator is built for the case where each association requires a separate rpc +*/ +function SerialAssociator(form, oneObjPkey, manyObjPkeys){ + this.form = form; + this.manyObjPkeys = manyObjPkeys; + this.oneObjPkey = oneObjPkey; + + this.associateNext = function(){ + var form = this.form; + //TODO assert pre-conditions + var manyObjPkey = manyObjPkeys.shift(); + if (manyObjPkey){ + var options = {}; + options[form.oneObj] = oneObjPkey; + var args = [manyObjPkey]; + var associator = this; + + ipa_cmd( form.method,args, options , + function(){ + associator.associateNext(); + }, + function(response){ + alert("associateFailure"); + }, + form.manyObj ); + }else{ + location.hash="tab="+form.oneObj + +"&facet=details&pkey="+this.oneObjPkey; + } + } + +} + +/** +*This associator is for the common case where all the asociations can be sent +in a single rpc +*/ +function BulkAssociator(form, pkey, manyObjPkeys){ + + this.form = form; + this.pkey =pkey; + this.manyObjPkeys = manyObjPkeys; + + this.associateNext = function(){ + var form = this.form; + var option = manyObjPkeys.shift(); + while(manyObjPkeys.length > 0){ + option += "," + manyObjPkeys.shift(); + } + + var options = { + "all":true + }; + options[form.manyObj] = option; + + var args = [this.pkey]; + + ipa_cmd( form.method,args, options , + function(response){ + var qs = ipa_parse_qs(); + if (response.error){ + alert("error adding memeber"); + }else{ + location.hash="tab=" +form.oneObj + +"&facet=details&pkey="+this.pkey; + } + }, + function(response){ + alert("associateFailure"); + }, + form.oneObj ); + } +} + +/** + * Create a form for a one to many association. + * + */ +function AssociationForm(oneObj, manyObj,facet,facets, searchColumn, headerText , associatorConstructor, method){ + this.oneObj = oneObj; + this.manyObj = manyObj; + this.facet = facet; + this.facets = facets; + this.headerText = headerText; + this.searchColumn = searchColumn; + //An optional parameter to determine what ipa method to call to create + //the association + if (method){ + this.method = method; + }else{ + this.method = 'add_member'; + } + + if (associatorConstructor){ + this.associatorConstructor = associatorConstructor; + }else{ + this.associatorConstructor = SerialAssociator; + } + + this.setup = function(pkey){ + showAssociations(); + qs = ipa_parse_qs(); + $("#availableList").html(""); + $("#enrollments").html(""); + + setupFacetNavigation(this.oneObj,qs['pkey'],qs['facet'],this.facets); + + this.currentUserToEnroll = qs['pkey']; + this.manyObjPkeys = []; + var form = this; + + $('h1').text(this.headerText()); + + + $("#enroll").click(function(){ + form.associate(); + }); + $("#addToList").click(function(){ + $('#availableList :selected').each(function(i, selected){ + $("#enrollments").append(selected); + }); + $('#availableList :selected').remove(); + }); + $("#removeFromList").click(function(){ + $('#enrollments :selected').each(function(i, selected){ + $("#availableList").append(selected); + }); + $('#enrollments :selected').remove(); + }); + $("#find").click(function(){ + form.search(); + }); + } + this.search = function(){ + + var queryFilter = $("#associateFilter").val(); + + var form = this; + ipa_cmd( 'find', [queryFilter], {}, + function(searchResults){ + form.populateSearch(searchResults); + }, + function(){ + alert("associationSearchFailure"); + }, + this.manyObj); + } + + this.associate = function(){ + var manyObjPkeys = []; + $('#enrollments').children().each(function(i, selected){ + manyObjPkeys.push(selected.value); + }); + var pkey = qs['pkey']; + var associator = + new this.associatorConstructor (this, pkey, manyObjPkeys); + associator.associateNext(); + } + this.populateSearch = function(searchResults){ + var results = searchResults.result; + $("#availableList").html(""); + for (var i =0; i != results.count; i++){ + var result = results.result[i]; + $("