Hi,

Please review the attached patch. Thanks!

The ipa_column has been modified to get the label from metadata
during initialization. The ipa_table_widget has been modified to
initialize the columns. Hard-coded labels have been removed from
column declarations.

The ipa_adder_dialog has been modified to execute a search at the
end of setup.

--
Endi S. Dewata
From ee1025e731f2aa5b49f82aecdbdadffc988ff148 Mon Sep 17 00:00:00 2001
From: Endi S. Dewata <[email protected]>
Date: Mon, 6 Dec 2010 13:51:49 -0600
Subject: [PATCH] Column i18n

The ipa_column has been modified to get the label from metadata
during initialization. The ipa_table_widget has been modified to
initialize the columns. Hard-coded labels have been removed from
column declarations.

The ipa_adder_dialog has been modified to execute a search at the
end of setup.
---
 install/static/associate.js    |   37 +++++++++++++++++++++++-----------
 install/static/group.js        |   13 ++++-------
 install/static/hbac.js         |   16 ++++++++------
 install/static/hbacsvc.js      |    8 +++---
 install/static/hbacsvcgroup.js |   12 +++-------
 install/static/host.js         |    5 +---
 install/static/search.js       |   11 +++------
 install/static/service.js      |    9 +++----
 install/static/sudocmd.js      |    8 +++---
 install/static/sudocmdgroup.js |   12 +++-------
 install/static/sudorule.js     |   12 +++++-----
 install/static/widget.js       |   43 +++++++++++++++++++++++++++------------
 12 files changed, 100 insertions(+), 86 deletions(-)

diff --git a/install/static/associate.js b/install/static/associate.js
index 1a96362f5955ba217a921d43c3711e3266e9bd52..48bb0225f24bed8438db3745d8fafb7a36922e2a 100644
--- a/install/static/associate.js
+++ b/install/static/associate.js
@@ -153,15 +153,9 @@ function ipa_association_adder_dialog(spec) {
         }
 
         that.adder_dialog_init();
-        execute_search('');
-
     };
 
     that.search = function() {
-        execute_search(that.get_filter());
-    };
-
-    function execute_search(filter){
         function on_success(data, text_status, xhr) {
             var results = data.result;
             that.clear_available_values();
@@ -172,8 +166,8 @@ function ipa_association_adder_dialog(spec) {
             }
         }
 
-        ipa_cmd('find', [filter], {'all': true}, on_success, null, that.other_entity);
-    }
+        ipa_cmd('find', [that.get_filter()], {'all': true}, on_success, null, that.other_entity);
+    };
 
     return that;
 }
@@ -250,7 +244,6 @@ function ipa_association_table_widget(spec) {
     };
 
     that.add_adder_column = function(column) {
-        column.entity_name = that.entity_name;
         that.adder_columns.push(column);
         that.adder_columns_by_name[column.name] = column;
     };
@@ -284,6 +277,16 @@ function ipa_association_table_widget(spec) {
             });
         }
 
+        for (var i=0; i<that.columns.length; i++) {
+            var column = that.columns[i];
+            column.entity_name = that.other_entity;
+        }
+
+        for (var i=0; i<that.adder_columns.length; i++) {
+            var column = that.adder_columns[i];
+            column.entity_name = that.other_entity;
+        }
+
         that.table_init();
     };
 
@@ -523,7 +526,6 @@ function ipa_association_facet(spec) {
     };
 
     that.add_column = function(column) {
-        column.entity_name = that.entity_name;
         that.columns.push(column);
         that.columns_by_name[column.name] = column;
     };
@@ -539,7 +541,6 @@ function ipa_association_facet(spec) {
     };
 
     that.add_adder_column = function(column) {
-        column.entity_name = that.entity_name;
         that.adder_columns.push(column);
         that.adder_columns_by_name[column.name] = column;
     };
@@ -552,6 +553,8 @@ function ipa_association_facet(spec) {
 
     that.init = function() {
 
+        that.facet_init();
+
         var entity = IPA.get_entity(that.entity_name);
         var association = entity.get_association(that.other_entity);
 
@@ -608,7 +611,17 @@ function ipa_association_facet(spec) {
             };
         }
 
-        that.facet_init();
+        for (var i=0; i<that.columns.length; i++) {
+            var column = that.columns[i];
+            column.entity_name = that.other_entity;
+        }
+
+        for (var i=0; i<that.adder_columns.length; i++) {
+            var column = that.adder_columns[i];
+            column.entity_name = that.other_entity;
+        }
+
+        that.table.init();
     };
 
     that.is_dirty = function() {
diff --git a/install/static/group.js b/install/static/group.js
index 8c2087f66f3ca4a9feac2001aba18ec0d446eb7b..f3dba7b03169273fd68c9d97c0f3ff0470270a73 100644
--- a/install/static/group.js
+++ b/install/static/group.js
@@ -150,11 +150,10 @@ function ipa_group_member_user_facet(spec) {
 
     that.init = function() {
 
-        that.create_column({name: 'cn', label: 'Name'});
+        that.create_column({name: 'cn'});
 
         var column = that.create_column({
             name: 'uid',
-            label: 'Login',
             primary_key: true
         });
 
@@ -179,20 +178,18 @@ function ipa_group_member_user_facet(spec) {
             }).appendTo(container);
         };
 
-        that.create_column({name: 'uidnumber', label: 'UID'});
-        that.create_column({name: 'mail', label: 'EMAIL'});
-        that.create_column({name: 'telephonenumber', label: 'Phone'});
-        that.create_column({name: 'title', label: 'Job Title'});
+        that.create_column({name: 'uidnumber'});
+        that.create_column({name: 'mail'});
+        that.create_column({name: 'telephonenumber'});
+        that.create_column({name: 'title'});
 
         that.create_adder_column({
             name: 'cn',
-            label: 'Name',
             width: '100px'
         });
 
         that.create_adder_column({
             name: 'uid',
-            label: 'Login',
             primary_key: true,
             width: '100px'
         });
diff --git a/install/static/hbac.js b/install/static/hbac.js
index f0f2f96d780e1ec4970fca8855d6678983a1f812..d5105bace846887f64b1c0afb549b2dacd9bd311 100755
--- a/install/static/hbac.js
+++ b/install/static/hbac.js
@@ -93,12 +93,12 @@ function ipa_hbac_search_facet(spec) {
 
     that.init = function() {
 
-        that.create_column({name:'cn', label:'Rule Name'});
-        that.create_column({name:'usercategory', label:'Who'});
-        that.create_column({name:'hostcategory', label:'Accessing'});
-        that.create_column({name:'ipaenabledflag', label:'Active'});
-        that.create_column({name:'servicecategory', label:'Via Service'});
-        that.create_column({name:'sourcehostcategory', label:'From'});
+        that.create_column({name:'cn'});
+        that.create_column({name:'usercategory'});
+        that.create_column({name:'hostcategory'});
+        that.create_column({name:'ipaenabledflag'});
+        that.create_column({name:'servicecategory'});
+        that.create_column({name:'sourcehostcategory'});
 
         that.search_facet_init();
     };
@@ -750,6 +750,8 @@ function ipa_hbac_accesstime_widget(spec) {
 
     that.init = function() {
 
+        that.widget_init();
+
         that.table = ipa_table_widget({
             'id': 'accesstime-table',
             'name': 'table', 'label': that.label
@@ -761,7 +763,7 @@ function ipa_hbac_accesstime_widget(spec) {
             'primary_key': true
         });
 
-        that.widget_init();
+        that.table.init();
     };
 
     that.create = function(container) {
diff --git a/install/static/hbacsvc.js b/install/static/hbacsvc.js
index a0ef75d144e82c0b262c6f4e47a7eb25fa256835..bf3c2ad71c0719c86c357a591052d44bc483b82b 100755
--- a/install/static/hbacsvc.js
+++ b/install/static/hbacsvc.js
@@ -82,8 +82,8 @@ function ipa_hbacsvc_search_facet(spec) {
 
     that.init = function() {
 
-        that.create_column({name:'cn', label:'Service', primary_key: true});
-        that.create_column({name:'description', label:'Description'});
+        that.create_column({name:'cn', primary_key: true});
+        that.create_column({name:'description'});
 
         that.search_facet_init();
     };
@@ -140,8 +140,8 @@ function ipa_hbacsvc_details_facet(spec) {
         });
         that.add_section(section);
 
-        section.create_field({ 'name': 'cn', 'label': 'Name' });
-        section.create_field({ 'name': 'description', 'label': 'Description' });
+        section.create_field({'name': 'cn'});
+        section.create_field({'name': 'description'});
 
         that.superior_init();
     };
diff --git a/install/static/hbacsvcgroup.js b/install/static/hbacsvcgroup.js
index 1972e6c56b1a34e7ca4eeedb52fb34309af2bdb7..792bd44e6c230ef7227e5b6ad61de1201a9830b5 100755
--- a/install/static/hbacsvcgroup.js
+++ b/install/static/hbacsvcgroup.js
@@ -88,8 +88,8 @@ function ipa_hbacsvcgroup_search_facet(spec) {
 
     that.init = function() {
 
-        that.create_column({name:'cn', label:'Group', primary_key: true});
-        that.create_column({name:'description', label:'Description'});
+        that.create_column({name:'cn', primary_key: true});
+        that.create_column({name:'description'});
 
         that.search_facet_init();
     };
@@ -142,8 +142,8 @@ function ipa_hbacsvcgroup_details_facet(spec) {
         });
         that.add_section(section);
 
-        section.create_field({ 'name': 'cn', 'label': 'Name' });
-        section.create_field({ 'name': 'description', 'label': 'Description' });
+        section.create_field({'name': 'cn'});
+        section.create_field({'name': 'description'});
 
         section = ipa_details_section({
             'name': 'services',
@@ -174,7 +174,6 @@ function ipa_hbacsvcgroup_member_hbacsvc_table_widget(spec) {
 
         var column = that.create_column({
             name: 'cn',
-            label: 'Service',
             primary_key: true,
             width: '150px'
         });
@@ -202,20 +201,17 @@ function ipa_hbacsvcgroup_member_hbacsvc_table_widget(spec) {
 
         that.create_column({
             name: 'description',
-            label: 'Description',
             width: '350px'
         });
 
         that.create_adder_column({
             name: 'cn',
-            label: 'Service',
             primary_key: true,
             width: '100px'
         });
 
         that.create_adder_column({
             name: 'description',
-            label: 'Description',
             width: '100px'
         });
 
diff --git a/install/static/host.js b/install/static/host.js
index d9a2dfe03c3116db2c6000ee22d11137c899b7fa..56e3eb30ad95422016afdadbdba0e41a0d32822a 100644
--- a/install/static/host.js
+++ b/install/static/host.js
@@ -426,7 +426,6 @@ function ipa_host_managedby_host_facet(spec) {
 
         var column = that.create_column({
             name: 'fqdn',
-            label: 'Name',
             primary_key: true
         });
 
@@ -451,18 +450,16 @@ function ipa_host_managedby_host_facet(spec) {
             }).appendTo(container);
         };
 
-        that.create_column({name: 'description', label: 'Description'});
+        that.create_column({name: 'description'});
 
         that.create_adder_column({
             name: 'fqdn',
-            label: 'Name',
             primary_key: true,
             width: '100px'
         });
 
         that.create_adder_column({
             name: 'description',
-            label: 'Description',
             width: '100px'
         });
 
diff --git a/install/static/search.js b/install/static/search.js
index a9f71b9ac19738ec0fd1d9b15792ac356040cc46..a53a9efbb1af41f906b804fa804b23f9f641e2ae 100644
--- a/install/static/search.js
+++ b/install/static/search.js
@@ -285,13 +285,6 @@ function ipa_search_facet(spec) {
     };
 
     that.create_column = function(spec) {
-        if (!spec.label){
-            var param_info = ipa_get_param_info(this.entity_name, spec.name);
-            if (param_info){
-                spec.label = param_info.label;
-            }
-        }
-
         var column = ipa_column(spec);
         that.add_column(column);
         return column;
@@ -322,6 +315,8 @@ function ipa_search_facet(spec) {
 
     function init() {
 
+        that.facet_init();
+
         that.table = ipa_search_widget({
             'id': that.entity_name+'-search',
             'name': 'search', 'label': IPA.metadata[that.entity_name].label,
@@ -341,6 +336,8 @@ function ipa_search_facet(spec) {
 
             that.table.add_column(column);
         }
+
+        that.table.init();
     }
 
     that.is_dirty = function() {
diff --git a/install/static/service.js b/install/static/service.js
index 3deea19b7d24e0e10dbad0b6fe835ac6daf3a040..c028eb6ada38d9ffc93bfc1ef8ffd2e151f2178c 100644
--- a/install/static/service.js
+++ b/install/static/service.js
@@ -79,7 +79,7 @@ function ipa_service_add_dialog(spec) {
         that.add_dialog_init();
 
         that.add_field(ipa_widget({
-            name: 'krbprincipalname',
+            name: 'krbprincipalname'
         }));
 
         that.add_field(ipa_text_widget({
@@ -183,12 +183,14 @@ function ipa_service_details_facet(spec) {
             name: 'krbprincipalname'
         });
 
+        // TODO: Replace with i18n label
         section.create_field({
             name: 'service',
             label: 'Service',
             load: service_service_load
         });
 
+        // TODO: Replace with i18n label
         section.create_field({
             name: 'host',
             label: 'Host Name',
@@ -403,7 +405,6 @@ function ipa_service_managedby_host_facet(spec) {
 
         var column = that.create_column({
             name: 'fqdn',
-            label: 'Name',
             primary_key: true
         });
 
@@ -428,18 +429,16 @@ function ipa_service_managedby_host_facet(spec) {
             }).appendTo(container);
         };
 
-        that.create_column({name: 'description', label: 'Description'});
+        that.create_column({name: 'description'});
 
         that.create_adder_column({
             name: 'fqdn',
-            label: 'Name',
             primary_key: true,
             width: '100px'
         });
 
         that.create_adder_column({
             name: 'description',
-            label: 'Description',
             width: '100px'
         });
 
diff --git a/install/static/sudocmd.js b/install/static/sudocmd.js
index 3ad71eb526164711ce1f3e40327f3afebf3f6ded..733344a2b457e67e6977d63053e253a690b24049 100755
--- a/install/static/sudocmd.js
+++ b/install/static/sudocmd.js
@@ -82,8 +82,8 @@ function ipa_sudocmd_search_facet(spec) {
 
     that.init = function() {
 
-        that.create_column({name:'sudocmd', label:'Command', primary_key: true});
-        that.create_column({name:'description', label:'Description'});
+        that.create_column({name:'sudocmd', primary_key: true});
+        that.create_column({name:'description'});
 
         that.search_facet_init();
     };
@@ -142,8 +142,8 @@ function ipa_sudocmd_details_facet(spec) {
         });
         that.add_section(section);
 
-        section.create_field({ 'name': 'sudocmd', 'label': 'Command' });
-        section.create_field({ 'name': 'description', 'label': 'Description' });
+        section.create_field({'name': 'sudocmd'});
+        section.create_field({'name': 'description'});
 
         that.superior_init();
     };
diff --git a/install/static/sudocmdgroup.js b/install/static/sudocmdgroup.js
index 01e8007bbe84ee588fb12fd8793a4b1a0ef55185..c3daf9fb7f32e7f1912b4f7e48377e8922f41042 100755
--- a/install/static/sudocmdgroup.js
+++ b/install/static/sudocmdgroup.js
@@ -95,8 +95,8 @@ function ipa_sudocmdgroup_search_facet(spec) {
 
     that.init = function() {
 
-        that.create_column({name:'cn', label:'Group', primary_key: true});
-        that.create_column({name:'description', label:'Description'});
+        that.create_column({name:'cn', primary_key: true});
+        that.create_column({name:'description'});
 
         that.search_facet_init();
     };
@@ -152,8 +152,8 @@ function ipa_sudocmdgroup_details_facet(spec) {
         });
         that.add_section(section);
 
-        section.create_field({ 'name': 'cn', 'label': 'Name' });
-        section.create_field({ 'name': 'description', 'label': 'Description' });
+        section.create_field({'name': 'cn'});
+        section.create_field({'name': 'description'});
 
         that.details_facet_init();
     };
@@ -171,7 +171,6 @@ function ipa_sudocmdgroup_member_sudocmd_facet(spec) {
 
         var column = that.create_column({
             name: 'sudocmd',
-            label: 'Command',
             primary_key: true,
             width: '150px'
         });
@@ -198,21 +197,18 @@ function ipa_sudocmdgroup_member_sudocmd_facet(spec) {
         };
 
         that.create_column({
-            name: 'description',
             label: 'Description',
             width: '150px'
         });
 
         that.create_adder_column({
             name: 'sudocmd',
-            label: 'Command',
             primary_key: true,
             width: '100px'
         });
 
         that.create_adder_column({
             name: 'description',
-            label: 'Description',
             width: '100px'
         });
 
diff --git a/install/static/sudorule.js b/install/static/sudorule.js
index 7c290ac19dc2a3c53083f9ced251c59dcd9b4786..17c0267685338c2ed8bfd1dc123e78d90bc90c05 100755
--- a/install/static/sudorule.js
+++ b/install/static/sudorule.js
@@ -83,9 +83,9 @@ function ipa_sudorule_search_facet(spec) {
 
     that.init = function() {
 
-        that.create_column({name:'cn', label:'Rule Name'});
-        that.create_column({name:'description', label:'Description'});
-        that.create_column({name:'cmdcategory', label:'Command category'});
+        that.create_column({name:'cn'});
+        that.create_column({name:'description'});
+        that.create_column({name:'cmdcategory'});
 
         that.search_facet_init();
     };
@@ -120,9 +120,9 @@ function ipa_sudorule_details_facet(spec) {
         });
         that.add_section(section);
 
-        section.create_field({ 'name': 'cn', 'label': 'Name', 'read_only': true });
-        section.create_field({ 'name': 'description', 'label': 'Description' });
-        section.create_field({ 'name': 'cmdcategory', 'label': 'Command Category' });
+        section.create_field({'name': 'cn', 'read_only': true});
+        section.create_field({'name': 'description'});
+        section.create_field({'name': 'cmdcategory'});
 
         section = ipa_rule_details_section({
             'name': 'user',
diff --git a/install/static/widget.js b/install/static/widget.js
index 97cd70024726baaef65d9bfba940b6ada6c62432..e864e8b505fc67ce54be9732384c5930e5615775 100755
--- a/install/static/widget.js
+++ b/install/static/widget.js
@@ -28,18 +28,10 @@ function ipa_widget(spec) {
 
     that.id = spec.id;
     that.name = spec.name;
-    that.label = spec.label ;
+    that.label = spec.label;
     that.read_only = spec.read_only;
     that._entity_name = spec.entity_name;
 
-    if (spec.entity_name && ! spec.label){
-        var param_info = ipa_get_param_info(spec.entity_name, spec.name);
-        if (param_info){
-            that.label = param_info.label;
-        }
-    }
-
-
     that.width = spec.width;
     that.height = spec.height;
 
@@ -68,6 +60,10 @@ function ipa_widget(spec) {
     });
 
     function init() {
+        if (that.entity_name && !that.label){
+            var param_info = ipa_get_param_info(that.entity_name, spec.name);
+            if (param_info) that.label = param_info.label;
+        }
     }
 
     function create(container) {
@@ -444,9 +440,17 @@ function ipa_column(spec) {
     that.name = spec.name;
     that.label = spec.label;
     that.primary_key = spec.primary_key;
-    that.setup = spec.setup || setup;
-
     that.width = spec.width;
+    that.entity_name = spec.entity_name;
+
+    that.setup = spec.setup || setup;
+
+    that.init = function() {
+        if (that.entity_name && !that.label) {
+            var param_info = ipa_get_param_info(that.entity_name, that.name);
+            if (param_info) that.label = param_info.label;
+        }
+    };
 
     function setup(container, record) {
 
@@ -481,7 +485,6 @@ function ipa_table_widget(spec) {
     };
 
     that.add_column = function(column) {
-        column.entity_name = that.entity_name;
         that.columns.push(column);
         that.columns_by_name[column.name] = column;
     };
@@ -504,6 +507,15 @@ function ipa_table_widget(spec) {
         return column;
     };
 
+    that.init = function() {
+        that.widget_init();
+
+        for (var i=0; i<that.columns.length; i++) {
+            var column = that.columns[i];
+            column.init();
+        }
+    };
+
     that.create = function(container) {
 
         var table = $('<table/>', {
@@ -927,7 +939,6 @@ function ipa_adder_dialog(spec) {
     };
 
     that.add_column = function(column) {
-        column.entity_name = that.entity_name;
         that.columns.push(column);
         that.columns_by_name[column.name] = column;
     };
@@ -959,6 +970,8 @@ function ipa_adder_dialog(spec) {
 
         that.available_table.set_columns(that.columns);
 
+        that.available_table.init();
+
         that.selected_table = ipa_table_widget({
             name: 'selected',
             scrollable: true,
@@ -966,6 +979,8 @@ function ipa_adder_dialog(spec) {
         });
 
         that.selected_table.set_columns(that.columns);
+
+        that.selected_table.init();
     };
 
     that.create = function() {
@@ -1081,6 +1096,8 @@ function ipa_adder_dialog(spec) {
             }
         });
         button.replaceWith(that.add_button);
+
+        that.search();
     };
 
     that.open = function(container) {
-- 
1.6.6.1

_______________________________________________
Freeipa-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/freeipa-devel

Reply via email to