From 49584d6efc6a10fa0b76ce81b2638d424f2208a8 Mon Sep 17 00:00:00 2001 From: Adam Young Date: Mon, 23 Aug 2010 22:32:23 -0400 Subject: [PATCH] hashchange We now catch the hashchange event and use that to drive most of the site. To trigger page transitions, modify location.hash. Params start with # not ?. Removed user-group.inc. converted tabs to spaces trivial imlementation of add and details for netgroup and hostgroup lots of bug fixes based on routing problems and the refactorings. --- install/static/Makefile.am | 1 + install/static/add.js | 110 +++++++ install/static/details.js | 29 +- install/static/group.js | 73 ++--- install/static/host.js | 50 ++- install/static/hostgroup.js | 59 ++-- install/static/index.xhtml | 55 +++- install/static/ipa.css | 12 +- install/static/ipa.js | 21 +- install/static/navigation.js | 214 ++++++------ install/static/netgroup.js | 55 ++-- install/static/sampledata/hostgroupshow.json | 17 + install/static/sampledata/netgroupshow.json | 26 ++ install/static/search.js | 135 ++++---- install/static/user-groups.inc | 49 --- install/static/user.js | 327 +++++++++---------- 16 files changed, 713 insertions(+), 520 deletions(-) create mode 100644 install/static/add.js create mode 100644 install/static/sampledata/hostgroupshow.json create mode 100644 install/static/sampledata/netgroupshow.json delete mode 100644 install/static/user-groups.inc diff --git a/install/static/Makefile.am b/install/static/Makefile.am index 8e1dc1bcf..366975ebf 100644 --- a/install/static/Makefile.am +++ b/install/static/Makefile.am @@ -2,6 +2,7 @@ NULL = appdir = $(IPA_DATA_DIR)/static app_DATA = \ + add.js \ but-reset.png \ but-update.png \ but-selected.png \ diff --git a/install/static/add.js b/install/static/add.js new file mode 100644 index 000000000..4af6a8e72 --- /dev/null +++ b/install/static/add.js @@ -0,0 +1,110 @@ +/* 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 */ + +/* + * 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 ){ + this.obj = 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(){ + showContent(); + $("

" ,{ html : "Add new " + this.obj } ).appendTo("#content"); + $("
") + .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:'addAnother', + type:'button', + value:'Add Another', + click: function(){ + var params = ipa_parse_qs(); + builders[params["tab"]].add (addAnother) + } + }).appendTo(label); + $("
").appendTo("#addForm"); + + for (index = 0; index < this.addProperties.length; index++){ + var prop = this.addProperties[index]; + var title = $("
",{html:prop.title}); + var definition = $("
"); + $("",{ + id:prop.id, + type:prop.type + }).appendTo(definition); + definition.appendTo(title); + title.appendTo("#addProperties"); + } + } + //register the new object with the associatev array of builders. + builders[obj] = this; +} + + +function addAnother(response){ + var params = ipa_parse_qs(); + builders[params["tab"]].setup(); +} + +function addEdit(response){ + var params = ipa_parse_qs(); + var hash= "tab=" + + params["tab"] + +"&facet=details&pkey=" + +$("#pkey").val(); + window.location.hash = hash; +} \ No newline at end of file diff --git a/install/static/details.js b/install/static/details.js index 03362d833..40d36b6b6 100644 --- a/install/static/details.js +++ b/install/static/details.js @@ -1,5 +1,6 @@ /* Authors: * Pavel Zuna + * Adam Young * * Copyright (C) 2010 Red Hat * see file 'COPYING' for use and warranty information @@ -16,7 +17,7 @@ * 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 Details - populating definiton lists from entry data */ @@ -134,6 +135,7 @@ function ipa_details_update(pkey, on_win, on_fail) modlist['setattr'].push(attr + '=' + values[0]); for (var i = 1; i < values.length; ++i) modlist['addattr'].push(attr + '=' + values[i]); + } _ipa_update_on_win_callback = on_win; @@ -162,6 +164,7 @@ function _ipa_update_on_fail(xhr, text_status, error_thrown) { if (_ipa_update_on_fail_callback) _ipa_update_on_fail_callback(xhr, text_status, error_thrown); + } function ipa_details_create(dls, container) @@ -173,7 +176,7 @@ function ipa_details_create(dls, container) var d = dls[i]; ipa_generate_dl($('#detail-lists hr').last(), d[0], d[1], d[2]); -// ipa_generate_dl($("#detail-lists"), d[0], d[1], d[2]); + // ipa_generate_dl($("#detail-lists"), d[0], d[1], d[2]); } } @@ -332,7 +335,7 @@ function ipa_create_input(attr, value) if (param_info['multivalue'] || param_info['class'] == 'List') { return ( handler(attr, value, param_info) + - _ipa_create_remove_link(attr, param_info) + _ipa_create_remove_link(attr, param_info) ); } return (handler(attr, value, param_info)); @@ -378,6 +381,7 @@ function ipa_details_reset() { if (ipa_details_cache) ipa_details_display(ipa_details_cache); + } /* Event handlers */ @@ -435,3 +439,22 @@ function _h2_on_click(obj) } } +function DetailsForm(obj, details_list, pkeyCol, sampleData ){ + + this.obj = obj; + this.details_list = details_list; + this.sampleData = sampleData; + this.pkeyCol = pkeyCol; + + this.setup= function(key){ + //re initialize global parse of parameters + qs = ipa_parse_qs(); + + showDetails(); + $('h1').text("Managing " + this.obj +": " +qs['pkey'] ); + + ipa_details_init(this.obj); + ipa_details_create(this.details_list, $('#details')); + ipa_details_load(qs.pkey, on_win, null, this.sampleData); + } +} diff --git a/install/static/group.js b/install/static/group.js index beb10879c..981e048b0 100644 --- a/install/static/group.js +++ b/install/static/group.js @@ -1,10 +1,10 @@ function setupGroup(facet){ if (facet == "details"){ - setupGroupDetails(); + setupGroupDetails(); }else if (facet == "add"){ - setupAddGroup(); + setupAddGroup(); }else{ - setupGroupSearch(); + groupSearchForm.setup(); } } @@ -14,15 +14,15 @@ function addGroupFail(desc){ } function addGroup(on_success){ - - var options = { - posix: $('#isposix').is(':checked') ? 1 : 0 , - description: $("#groupdescription").val()}; + + var options = { + posix: $('#isposix').is(':checked') ? 1 : 0 , + description: $("#groupdescription").val()}; - var gid = $("#groupidnumber").val(); + var gid = $("#groupidnumber").val(); if (gid.length > 0){ - options.gidnumber = gid; + options.gidnumber = gid; } var params = [$("#groupname").val()]; @@ -33,7 +33,7 @@ function addGroup(on_success){ function addEditGroup(){ addGroup(function (response){ - location.href="index.xhtml?tab=group&facet=details&pkey="+$("#groupname").val(); + location.hash="tab=group&facet=details&pkey="+$("#groupname").val(); }); } @@ -47,20 +47,20 @@ function setupAddGroup(){ $("

Add new Group

").appendTo("#content"); $("
") - .appendTo("#content"); - + .appendTo("#content"); + $("").appendTo("#addGroupForm"); $("
").appendTo("#addGroupForm"); - + $("
Name
") - .appendTo("#groupProperties"); + .appendTo("#groupProperties"); $("
Description
") - .appendTo("#groupProperties"); + .appendTo("#groupProperties"); $("
Is this a posix Group
") - .appendTo("#groupProperties"); + .appendTo("#groupProperties"); $("
GID
") - .appendTo("#groupProperties"); + .appendTo("#groupProperties"); $("#addEdit").click(addEditGroup); @@ -70,20 +70,15 @@ function setupAddGroup(){ var group_details_list = [['identity', 'Group Details', [ - ['cn', 'Group Name'], - ['description', 'Description'], - ['gidnumber', 'Group ID']]]]; + ['cn', 'Group Name'], + ['description', 'Description'], + ['gidnumber', 'Group ID']]]]; function setupGroupDetails(group){ - window.location.hash="#tab=user&facet=details&pkey="+group; - //re initialize global parse of parameters qs = ipa_parse_qs(); - //TODO make this work for more than just user details - user_details_lists; - showDetails(); ipa_details_init('group'); @@ -103,29 +98,21 @@ function renderGroupDetails(group) function renderGroupDetailColumn(current,cell){ $("",{ - href:"#tab=group&facet=details&pkey="+current.cn, - html: ""+ current[this.column], - click: function(){ setupGroupDetails(current.cn)}, + href:"#tab=group&facet=details&pkey="+current.cn, + html: ""+ current[this.column], + //click: function(){ setupGroupDetails(current.cn)}, }).appendTo(cell); } -function setupGroupSearch(){ - var columns = [ - {title:"Group Name", column:"cn",render: renderGroupDetailColumn}, - {title:"GID", column:"gidnumber",render: renderSimpleColumn}, - {title:"Description", column:"description",render: renderSimpleColumn} - ]; +var groupSearchColumns = [ + {title:"Group Name", column:"cn",render: renderGroupDetailColumn}, + {title:"GID", column:"gidnumber",render: renderSimpleColumn}, + {title:"Description", column:"description",render: renderSimpleColumn} +]; + +var groupSearchForm = new SearchForm("group", "find", groupSearchColumns ,"sampledata/grouplist.json"); - var groupSearchForm = new SearchForm("group", "find", columns,"sampledata/grouplist.json"); - - $("#query").unbind(); - $("#query").click(function(){ - executeSearch(groupSearchForm); - }); - $("#new").unbind(); - $("#new").click( setupAddGroup ); -} diff --git a/install/static/host.js b/install/static/host.js index b6881d836..b249c9b5e 100644 --- a/install/static/host.js +++ b/install/static/host.js @@ -1,38 +1,32 @@ function setupHost(facet){ if (facet == "details"){ - setupHostDetails(); + hostDetailsForm.setup(); + }else if (facet == "add"){ + hostBuilder.setup(); }else{ - setupHostSearch(); + hostSearchForm.setup(); } } -function setupHostDetails(){ - var detailsForm = new DetailsForm(); -} +var hostAddProperties = [{title: 'Domain Name', id: 'pkey', type: 'text'}]; +var hostBuilder = new EntityBuilder("host",hostAddProperties); -function setupHostSearch(){ - sampleData = "sampledata/hostlist.json"; - var columns = [ - {title:"Host",column:"fqdn",render: function(current,cell){ - renderDetailColumn(current,cell,current[this.column],"group"); - }}, - {title:"Comment", column: "description", render: renderSimpleColumn}, - {title:"Enrolled?", render: renderUnknownColumn}, - {title:"Manages?", render: renderUnknownColumn} - ]; +var host_details_list = [['host', 'Host Details', [ + ['fqdn', 'Fully Qualified Domain Name'], + ['krbprincipalname', 'Kerberos Principal'], + ['serverhostname', 'Server Host Name'] +]]]; + +var hostDetailsForm = new DetailsForm("host",host_details_list,"fqdn","sampledata/hostshow.json") ; - var hostSearchForm = new SearchForm("host", "find", columns); - $("#query").unbind(); - $("#query").click(function(){ - sampleData = "sampledata/hostlist.json"; - executeSearch(hostSearchForm); - }); - - $("#new").unbind(); - $("#new").click( function() { - alert("New Host..."); - }); - -} +var hostDetailsColumns = [ + {title:"Host",column:"fqdn",render: function(current,cell){ + renderPkeyColumn(hostDetailsForm,current,cell); + }}, + {title:"Comment", column: "description", render: renderSimpleColumn}, + {title:"Enrolled?", render: renderUnknownColumn}, + {title:"Manages?", render: renderUnknownColumn} +]; +var hostSearchForm = new SearchForm("host", "find", hostDetailsColumns,"sampledata/hostlist.json"); diff --git a/install/static/hostgroup.js b/install/static/hostgroup.js index 64eeb3afc..290460d81 100644 --- a/install/static/hostgroup.js +++ b/install/static/hostgroup.js @@ -1,35 +1,48 @@ function setupHostgroup(facet){ if (facet == "details"){ - setupHostgroupDetails(); + hostgroupDetailsForm.setup(); + }else if (facet == "add"){ + hostgroupBuilder.setup(); }else{ - setupHostgroupSearch(); + hostgroupSearchForm.setup(); } } -function setupHostgroupDetails(){ - var detailsForm = new DetailsForm(); +var hostgroup_details_list = + [['identity', 'Hostgroup Details', [ + ['cn', 'Hostgroup Name'], + ['description', 'Description']]]]; + + +var hostgroupDetailsForm = new DetailsForm("hostgroup",hostgroup_details_list,"cn","sampledata/hostgroupshow.json") ; + + + +function hostgroupAddOptionsFunction (){ + var options = { + name: $('#pkey').val(), + description: $('#description').val() + }; + return options; } +var hostgroupAddProperties = + [{title: 'Hostgroup Name', id: 'pkey', type: 'text'}, + {title: 'Description', id: 'description', type: 'text'}]; -function setupHostgroupSearch(){ +var hostgroupBuilder = new EntityBuilder("hostgroup",hostgroupAddProperties,hostgroupAddOptionsFunction); - var columns = [ - {title:"Hostgroup",column:"cn",render: function(current,cell){ - renderDetailColumn(current,cell,current[this.column],"hostgroup"); - }}, - {title:"Description", column:"description",render: renderSimpleColumn}]; - var hostgroupSearchForm = new SearchForm("hostgroup", "find", columns); +var hostgroupSearchColumns = [ + { + title:"Hostgroup", + column:"cn", + render: function(current,cell){ + renderPkeyColumn(hostgroupDetailsForm, current,cell); + } + }, + {title:"Description", column:"description",render: renderSimpleColumn}]; - $("#query").unbind(); - - $("#query").click(function(){ - sampleData = "sampledata/hostgrouplist.json"; - executeSearch(hostgroupSearchForm); - }); - $("#new").unbind(); - $("#new").click( function() { - alert("New Hostgroup..."); - }); - -} +var hostgroupSearchForm = + new SearchForm("hostgroup", "find", hostgroupSearchColumns, + "sampledata/hostgrouplist.json"); diff --git a/install/static/index.xhtml b/install/static/index.xhtml index 422538c9a..489f192b6 100644 --- a/install/static/index.xhtml +++ b/install/static/index.xhtml @@ -20,6 +20,7 @@ + @@ -70,14 +71,6 @@

@@ -89,7 +82,7 @@