On 12/05/2011 06:27 PM, Endi Sukma Dewata wrote:
On 12/5/2011 9:37 AM, Petr Vobornik wrote:
Created format method for getting translated messages for boolean values
- IPA.boolean_column_format.

Used in hosts, sudo rules, hbac rules.

https://fedorahosted.org/freeipa/ticket/2027

The patch works, so it's ACKed.

New version attached.

There are a few suggestions but they can
be done later:

1. It might be better to name the function IPA.boolean_format because we
can use it for other things too, not just inside a column.

Renamed

2. The value can be normalized using toLowerCase() before comparison.

Done, but using normalized value only for comparison because of #3.

3. If the value doesn't match true/false it can return the original
value instead of empty string

Done. Returning empty string if null or undefined.

Newly used in HBAC test page.

--
Petr Vobornik
From 663e2d4ec6f951a8fde29d9fb17b5f7521fe51a8 Mon Sep 17 00:00:00 2001
From: Petr Vobornik <pvobo...@redhat.com>
Date: Mon, 5 Dec 2011 16:23:38 +0100
Subject: [PATCH] Search facets show translated boolean values

Created format method for getting translated messages for boolean values - IPA.boolean_format.

Used in hosts, sudo rules, hbac rules and hbac test.

https://fedorahosted.org/freeipa/ticket/2027
---
 install/ui/hbac.js     |    5 ++++-
 install/ui/hbactest.js |   19 ++++++++++++++-----
 install/ui/host.js     |    3 ++-
 install/ui/sudo.js     |    5 ++++-
 install/ui/widget.js   |   21 +++++++++++++++++++++
 5 files changed, 45 insertions(+), 8 deletions(-)

diff --git a/install/ui/hbac.js b/install/ui/hbac.js
index 21333fa7b9a7ceb9f21857d52a44494c66da89af..3d2124e40647d9146e1a328afaf7c58fd59bb6e2 100644
--- a/install/ui/hbac.js
+++ b/install/ui/hbac.js
@@ -40,7 +40,10 @@ IPA.hbac.rule_entity = function(spec) {
             search_all: true,
             columns: [
                 'cn',
-                'ipaenabledflag',
+                {
+                    name: 'ipaenabledflag',
+                    format: IPA.boolean_format
+                },
                 'description'
             ]
         }).
diff --git a/install/ui/hbactest.js b/install/ui/hbactest.js
index 57ded45bab74185fe8bb097956cc62a951e5586a..d9a854f11f3e7d7e92d305589e28142aadf0df99 100644
--- a/install/ui/hbactest.js
+++ b/install/ui/hbactest.js
@@ -61,7 +61,8 @@ IPA.hbac.test_entity = function(spec) {
                 'description',
                 {
                     name: 'has_keytab',
-                    label: IPA.messages.objects.host.enrolled
+                    label: IPA.messages.objects.host.enrolled,
+                    format: IPA.boolean_format
                 }
             ]
         }).
@@ -89,7 +90,8 @@ IPA.hbac.test_entity = function(spec) {
                 'description',
                 {
                     name: 'has_keytab',
-                    label: IPA.messages.objects.host.enrolled
+                    label: IPA.messages.objects.host.enrolled,
+                    format: IPA.boolean_format
                 }
             ]
         }).
@@ -102,7 +104,10 @@ IPA.hbac.test_entity = function(spec) {
             facet_group: 'default',
             columns: [
                 'cn',
-                'ipaenabledflag',
+                {
+                    name: 'ipaenabledflag',
+                    format: IPA.boolean_format
+                },
                 'description'
             ]
         }).
@@ -118,9 +123,13 @@ IPA.hbac.test_entity = function(spec) {
                 'cn',
                 {
                     name: 'matched',
-                    label: IPA.messages.objects.hbactest.matched
+                    label: IPA.messages.objects.hbactest.matched,
+                    format: IPA.boolean_format
+                },
+                {
+                    name: 'ipaenabledflag',
+                    format: IPA.boolean_format
                 },
-                'ipaenabledflag',
                 'description'
             ]
         });
diff --git a/install/ui/host.js b/install/ui/host.js
index 94dd6465f6c9e4c432328d1cb32fa58fbfc38b87..7427a9b1673a323fa3127105f53ef873ad1e6146 100644
--- a/install/ui/host.js
+++ b/install/ui/host.js
@@ -39,7 +39,8 @@ IPA.host.entity = function(spec) {
                 'description',
                 {
                     name: 'has_keytab',
-                    label: IPA.messages.objects.host.enrolled
+                    label: IPA.messages.objects.host.enrolled,
+                    format: IPA.boolean_format
                 }
             ]
         }).
diff --git a/install/ui/sudo.js b/install/ui/sudo.js
index 2d3baf95ea834a69956216568f63034244d4df9d..5e1dedc7eaafe48c01c8e5b8ad90158cc4d9f976 100644
--- a/install/ui/sudo.js
+++ b/install/ui/sudo.js
@@ -38,7 +38,10 @@ IPA.sudo.rule_entity = function(spec) {
         that.builder.search_facet({
             columns: [
                 'cn',
-                'ipaenabledflag',
+                {
+                    name: 'ipaenabledflag',
+                    format: IPA.boolean_format
+                },
                 'description'
             ]
         }).
diff --git a/install/ui/widget.js b/install/ui/widget.js
index ef2c6eb6e1256f9da8bee9d9f16e1b46f255d28a..a8ad5cd8e822ea7e0857fba423b90cd2f534d165 100644
--- a/install/ui/widget.js
+++ b/install/ui/widget.js
@@ -902,6 +902,27 @@ IPA.textarea_widget = function (spec) {
     return that;
 };
 
+IPA.boolean_format = function(value) {
+
+    if (value === undefined || value === null) return '';
+
+    if (value instanceof Array) {
+        value = value[0];
+    }
+
+    var normalized_value = typeof value === 'string' ? value.toLowerCase() : '';
+
+    if (value === false || normalized_value === 'false') {
+        return IPA.messages['false'];
+    }
+
+    if (value === true || normalized_value === 'true') {
+        return IPA.messages['true'];
+    }
+
+    return value;
+};
+
 /*
   The entity name must be set in the spec either directly or via entity.name
 */
-- 
1.7.6.4

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

Reply via email to