Hi,

Please review the attached patch. Thanks!

The entity.default_facet has been removed, instead the first facet
registered to the entity will be considered as the default facet.
So, the 'setup' parameter has been removed from tab definitions
because it's no longer necessary. The ipa_details_only_setup() has
been removed as well.

An 'entity' parameter has been added to tab definitions to specify
which entity corresponds to a tab item. The tab label has been
changed to use entity label if available.

Some hard-coded labels have been removed. The unit tests have been
updated.

--
Endi S. Dewata
From 29a88b81877b254c4cbb055531a90ef32cf487c9 Mon Sep 17 00:00:00 2001
From: Endi S. Dewata <edew...@redhat.com>
Date: Tue, 7 Dec 2010 12:17:12 -0600
Subject: [PATCH] Navigation updates

The entity.default_facet has been removed, instead the first facet
registered to the entity will be considered as the default facet.
So, the 'setup' parameter has been removed from tab definitions
because it's no longer necessary. The ipa_details_only_setup() has
been removed as well.

An 'entity' parameter has been added to tab definitions to specify
which entity corresponds to a tab item. The tab label has been
changed to use entity label if available.

Some hard-coded labels have been removed. The unit tests have been
updated.
---
 install/static/details.js               |    2 -
 install/static/entity.js                |   14 +++++---
 install/static/navigation.js            |   19 +++++------
 install/static/policy.js                |    2 -
 install/static/serverconfig.js          |   24 +++++++--------
 install/static/test/details_tests.js    |   50 +++++++++++++++---------------
 install/static/test/navigation_tests.js |   26 ++++++++++------
 install/static/webui.js                 |   38 ++++++++++++------------
 8 files changed, 89 insertions(+), 86 deletions(-)

diff --git a/install/static/details.js b/install/static/details.js
index cc1a4e19d6872f3ca676905c3ca85e906f3ebcae..d9dc96bce4faa86ca81a069bb2108936b2d156ac 100644
--- a/install/static/details.js
+++ b/install/static/details.js
@@ -533,10 +533,8 @@ function ipa_details_setup(container) {
 function ipa_details_refresh() {
 
     var that = this;
-    var entity = IPA.get_entity(that.entity_name);
 
     that.pkey = $.bbq.getState(that.entity_name + '-pkey', true) || '';
-    if (!that.pkey && !entity.default_facet) return;
 
     function on_success(data, text_status, xhr) {
         that.load(data.result.result);
diff --git a/install/static/entity.js b/install/static/entity.js
index 9372d917ed98fa150abf4930d1e923ad9556adcf..340490ac81eaeac46f8ae143f511453d8d861161 100644
--- a/install/static/entity.js
+++ b/install/static/entity.js
@@ -189,6 +189,10 @@ function ipa_entity(spec) {
 
     that.init = function() {
 
+        if (!that.label) {
+            that.label = IPA.metadata[that.name].label;
+        }
+
         if (that.autogenerate_associations) {
             that.create_association_facets();
         }
@@ -332,12 +336,12 @@ function ipa_entity_set_facet_definition(entity_name, list) {
     }
 }
 
-function ipa_details_only_setup(container){
-    ipa_entity_setup.call(this, container, 'details');
-}
-
 function ipa_current_facet(entity){
-    return $.bbq.getState(entity.name + '-facet', true) || entity.default_facet || 'search';
+    var facet_name = $.bbq.getState(entity.name + '-facet', true);
+    if (!facet_name && entity.facets.length) {
+        facet_name = entity.facets[0].name;
+    }
+    return facet_name;
 }
 
 function ipa_entity_setup(container) {
diff --git a/install/static/navigation.js b/install/static/navigation.js
index aa03becc4882b88f0138a0a047dc7162be122547..8089e2eaf487825b2616a5bce1f2b58a621ef8b8 100644
--- a/install/static/navigation.js
+++ b/install/static/navigation.js
@@ -76,8 +76,9 @@ function nav_generate_tabs(nls, container, tabclass, depth)
         var tab = nls[i];
 
         var label = tab.name;
-        if ((IPA.metadata[tab.name]) && (IPA.metadata[tab.name].label)){
-            label = IPA.metadata[tab.name].label;
+        if (tab.entity) {
+            var entity = IPA.get_entity(tab.entity);
+            label = entity.label;
         }
 
         var li = nav_create_tab_li(tab.name, label);
@@ -86,14 +87,12 @@ function nav_generate_tabs(nls, container, tabclass, depth)
         var div = nav_create_tab_div(tab.name);
         container.append(div);
 
+        if (tab.entity) {
+            div.addClass('entity-container');
+        }
+
         if (tab.children && depth === 1) {
             nav_generate_tabs(tab.children, div, tabclass, depth +1 );
-        } else {
-            div.addClass('entity-container');
-
-            var entity = ipa_get_entity(tab.name);
-            entity.label = tab.label;
-            entity.setup = tab.setup;
         }
     }
 }
@@ -133,8 +132,8 @@ function _nav_update_tabs(nls, container,depth)
     if (tab.children   && depth === 1 ) {
         _nav_update_tabs(tab.children, container2,depth+1);
 
-    } else if (tab.setup) {
-        var entity_name = tab.name;
+    } else if (tab.entity) {
+        var entity_name = tab.entity;
 
         var nested_entity = nav_get_state(entity_name+'-entity');
 
diff --git a/install/static/policy.js b/install/static/policy.js
index df3970738115b1de13967f9c05132f2df17f02a1..5425ae3d1a05c7264f9b2ad516c35aefa2854685 100644
--- a/install/static/policy.js
+++ b/install/static/policy.js
@@ -594,7 +594,5 @@ ipa_entity_set_details_definition('krbtpolicy', [
         input({name:'krbmaxticketlife'})
 ]);
 
-IPA.get_entity('krbtpolicy').default_facet = 'details';
-
 ipa_entity_set_association_definition('krbtpolicy', {
 });
diff --git a/install/static/serverconfig.js b/install/static/serverconfig.js
index eef51ac35bd1b38773fee0be1c025dbfd8f71ca7..c7dbf41498fd84967d3463148f5242adab44d11b 100644
--- a/install/static/serverconfig.js
+++ b/install/static/serverconfig.js
@@ -50,19 +50,17 @@ ipa_entity_set_details_definition('aci', [
 /* Configuration */
 ipa_entity_set_details_definition('config',[
 
-    ipa_stanza({name:'ipaserver', lable:'Configuration'}).
+    ipa_stanza({name:'ipaserver', label:'Configuration'}).
         input({name:'cn', label:'Name'}).
         input({name:'description', label:'Description'}).
-        input({name:'ipacertificatesubjectbase', label:'Certificat Subject Base'}).
-        input({name: 'ipadefaultloginshell', label:'Default Login Shell'}).
-        input({name:'ipadefaultprimarygroup', label:'Default Primary Group'}).
-        input({name:'ipagroupsearchfields', label:'Group Search Fields'}).
-        input({name:'ipahomesrootdir', label:'Home Root Dir'}).
-        input({name:'ipamaxusernamelength', label:'Max Username Length'}).
-        input({name:'ipamigrationenabled', label:'Migration enabled?'}).
-        input({name:'ipasearchrecordslimit', label:'Search Record Limit'}).
-        input({name:'ipasearchtimelimit', label:'Search Time Limit'}).
-        input({name:'ipausersearchfields', label:'User Search Fields'})
+        input({name:'ipacertificatesubjectbase'}).
+        input({name:'ipadefaultloginshell'}).
+        input({name:'ipadefaultprimarygroup'}).
+        input({name:'ipagroupsearchfields'}).
+        input({name:'ipahomesrootdir'}).
+        input({name:'ipamaxusernamelength'}).
+        input({name:'ipamigrationenabled'}).
+        input({name:'ipasearchrecordslimit'}).
+        input({name:'ipasearchtimelimit'}).
+        input({name:'ipausersearchfields'})
 ]);
-
-IPA.get_entity('config').default_facet = 'details';
diff --git a/install/static/test/details_tests.js b/install/static/test/details_tests.js
index baa884e28e420b88d88fbbba439e682068fdc7c9..3dee5357f7e48a77bd1ed065a48fece33ff7ea11 100644
--- a/install/static/test/details_tests.js
+++ b/install/static/test/details_tests.js
@@ -35,9 +35,9 @@ test("Testing ipa_details_section.create().", function() {
     );
 
     var section = ipa_details_list_section({name:'IDIDID', label:'NAMENAMENAME'}).
-        input({name:'cn', label:'Entity Name'}).
-        input({name:'description', label:'Description'}).
-        input({name:'number', label:'Entity ID'});
+        input({name:'cn'}).
+        input({name:'description'}).
+        input({name:'number'});
 
 
     var fields = section.fields;
@@ -147,32 +147,32 @@ test("Testing details lifecycle: create, setup, load.", function(){
     var obj_name = 'user';
     ipa_entity_set_details_definition(obj_name, [
         ipa_stanza({name:'identity', label:'Identity Details'}).
-            input({name:'title', label: 'Title'}).
-            input({name:'givenname', label:'First Name'}).
-            input({name:'sn', label:'Last Name'}).
-            input({name:'cn', label:'Full Name'}).
-            input({name:'displayname', label:'Dispaly Name'}).
-            input({name:'initials', label:'Initials'}),
+            input({name:'title'}).
+            input({name:'givenname'}).
+            input({name:'sn'}).
+            input({name:'cn'}).
+            input({name:'displayname'}).
+            input({name:'initials'}),
         ipa_stanza({name:'account', label:'Account Details'}).
-            input({name:'status', label:'Account Status', setup: setup_status}).
-            input({name:'uid', label:'Login'}).
-            input({name:'userpassword', label:'Password', save: save_password}).
-            input({name:'uidnumber', label:'UID'}).
-            input({name:'gidnumber', label:'GID'}).
-            input({name:'homedirectory', label:'homedirectory'}),
+            input({name:'status', setup: setup_status}).
+            input({name:'uid'}).
+            input({name:'userpassword', save: save_password}).
+            input({name:'uidnumber'}).
+            input({name:'gidnumber'}).
+            input({name:'homedirectory'}),
         ipa_stanza({name:'contact', label:'Contact Details'}).
-            input({name:'mail', label:'E-mail Address'}).
-            input({name:'telephonenumber', label:'Numbers'}),
-        ipa_stanza({name:'address', label:'Mailing Address'}).
-            input({name:'street', label:'Address'}).
-            input({name:'location', label:'City'}).
-            input({name:'state', label:'State', setup: setup_st}).
-            input({name:'postalcode', label:'ZIP'}),
+            input({name:'mail'}).
+            input({name:'telephonenumber'}),
+        ipa_stanza({name:'address'}).
+            input({name:'street'}).
+            input({name:'location'}).
+            input({name:'state', setup: setup_st}).
+            input({name:'postalcode'}),
         ipa_stanza({name:'employee', label:'Employee Information'}).
-            input({name:'ou', label:'Org. Unit'}).
-            input({name:'manager', label:'Manager', load: load_manager}),
+            input({name:'ou'}).
+            input({name:'manager', load: load_manager}),
         ipa_stanza({name:'misc', label:'Misc. Information'}).
-            input({name:'carlicense', label:'Car License'})
+            input({name:'carlicense'})
     ]);
 
     var entity = ipa_get_entity(obj_name);
diff --git a/install/static/test/navigation_tests.js b/install/static/test/navigation_tests.js
index 68d4694f65600c31867d3834b517dc41e91b9a73..0d6f322d1d37a767fddac2e9c3da25bd85c8d424 100644
--- a/install/static/test/navigation_tests.js
+++ b/install/static/test/navigation_tests.js
@@ -26,20 +26,26 @@ test("Testing nav_create().", function() {
     var mock_tabs_lists =
         [
             { name:'identity', label:'IDENTITY', children: [
-                {name:'user', label:'Users', setup:mock_setup_user},
-                {name:'group', label:'Users', setup:mock_setup_group}
+                {name:'user', entity:'user'},
+                {name:'group', entity:'group'}
             ]}];
-    function  mock_setup_user (jobj){
+
+    var entity = ipa_entity({name: 'user'});
+    entity.setup = function(container){
         user_mock_called = true;
-        same(jobj[0].id,'user','user id');
-        same(jobj[0].nodeName,'DIV','user div');
-    }
-    function  mock_setup_group (jobj){
+        same(container[0].id,'user','user id');
+        same(container[0].nodeName,'DIV','user div');
+    };
+    IPA.add_entity(entity);
+
+    entity = ipa_entity({name: 'group'});
+    entity.setup = function(container){
         group_mock_called = true;
-        same(jobj[0].id,'group','group id');
-        same(jobj[0].nodeName,'DIV','group Div');
+        same(container[0].id,'group','group id');
+        same(container[0].nodeName,'DIV','group Div');
+    };
+    IPA.add_entity(entity);
 
-    }
     IPA.metadata = {};
     var navigation = $('<div id="navigation"/>').appendTo(document.body);
     var user_mock_called = false;
diff --git a/install/static/webui.js b/install/static/webui.js
index 26f6009814369434001e337f2d25a1eaa795c7f3..1c917d57df94f6eed52f01b3bdc97ad61f1b3996 100644
--- a/install/static/webui.js
+++ b/install/static/webui.js
@@ -25,36 +25,36 @@
 
 var admin_tab_set = [
     {name:'identity', children:[
-        {name:'user', label:'Users', setup: ipa_entity_setup},
-        {name:'group', label:'Groups', setup: ipa_entity_setup},
-        {name:'host', label:'Hosts', setup: ipa_entity_setup},
-        {name:'hostgroup', label:'Hostgroups', setup: ipa_entity_setup},
-        {name:'netgroup', label:'Netgroups', setup: ipa_entity_setup},
-        {name:'service', label:'Services', setup: ipa_entity_setup}
+        {name:'user', entity:'user'},
+        {name:'group', entity:'group'},
+        {name:'host', entity:'host'},
+        {name:'hostgroup', entity:'hostgroup'},
+        {name:'netgroup', entity:'netgroup'},
+        {name:'service', entity:'service'}
     ]},
     {name:'policy', children:[
-        {name:'dnszone', setup: ipa_entity_setup},
-        {name:'hbac', setup: ipa_entity_setup, children:[
-            {name:'hbacsvc', setup: ipa_entity_setup},
-            {name:'hbacsvcgroup', setup: ipa_entity_setup}
+        {name:'dnszone', entity:'dnszone'},
+        {name:'hbac', entity:'hbac', children:[
+            {name:'hbacsvc', entity:'hbacsvc'},
+            {name:'hbacsvcgroup', entity:'hbacsvcgroup'}
         ]},
-        {name:'sudorule', label:'SUDO', setup: ipa_entity_setup,children:[
-            {name:'sudocmd', setup: ipa_entity_setup},
-            {name:'sudocmdgroup', setup: ipa_entity_setup}
+        {name:'sudorule', entity:'sudorule',children:[
+            {name:'sudocmd', entity:'sudocmd'},
+            {name:'sudocmdgroup', entity:'sudocmdgroup'}
         ]},
-        {name:'automountlocation',  setup: ipa_entity_setup},
-        {name:'pwpolicy', setup: ipa_entity_setup},
-        {name:'krbtpolicy', setup:ipa_details_only_setup}
+        {name:'automountlocation', entity:'automountlocation'},
+        {name:'pwpolicy', entity:'pwpolicy'},
+        {name:'krbtpolicy', entity:'krbtpolicy'}
     ]},
     {name:'ipaserver', children: [
-        {name:'config', setup: ipa_details_only_setup}
+        {name:'config', entity:'config'}
     ]}
 ];
 
 var self_serv_tab_set =
     [
-        { name:'identity', label:'IDENTITY', children: [
-            {name:'user', label:'Users', setup:ipa_entity_setup}]}];
+        { name:'identity', children: [
+            {name:'user', entity:'user'}]}];
 
 
 IPA.tab_state = function(entity_name){
-- 
1.6.6.1

_______________________________________________
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel

Reply via email to