On 1/13/2011 9:11 AM, Endi Sukma Dewata wrote:
The attached patch should address issue #1 and #2 in this bug:
https://fedorahosted.org/freeipa/ticket/670

The labels for the following fields in Host details page have been
changed:
- fqdn: Fully Qualified Host Name
- serverhostname: Host Name

The ipa_details_field_create_input() and _ipa_create_text_input()
has been converted into methods in ipa_details_field class. The code
has been modified to display read-only fields as labels instead
of disabled text fields.

Rebased against the latest.

--
Endi S. Dewata
From 16711de51d9b66115e1bd0ec19a6323b9ff286c4 Mon Sep 17 00:00:00 2001
From: Endi S. Dewata <edew...@redhat.com>
Date: Thu, 13 Jan 2011 10:00:38 +0700
Subject: [PATCH] Host details adjustments.

The labels for the following fields in Host details page have been
changed:
 - fqdn: Fully Qualified Host Name
 - serverhostname: Host Name

The ipa_details_field_create_input() and _ipa_create_text_input()
has been converted into methods in ipa_details_field class. The code
has been modified to display read-only fields as labels instead
of disabled text fields.

The attributelevelrights in host test data files have been updated.
---
 install/static/details.js                          |  260 ++++++++++----------
 install/static/host.js                             |   13 +-
 install/static/test/data/host_show.json            |   31 ++-
 .../test/data/host_show_dev.example.com.json       |   30 ++--
 .../test/data/host_show_test.example.com.json      |   31 ++-
 install/static/test/details_tests.js               |    8 +-
 install/static/widget.js                           |   23 +-
 7 files changed, 206 insertions(+), 190 deletions(-)

diff --git a/install/static/details.js b/install/static/details.js
index f0756321d8021dc654e6544e35bfa3369adef3ff..d5d04e6ea4ddd0908f091013ea499329879c1546 100644
--- a/install/static/details.js
+++ b/install/static/details.js
@@ -89,12 +89,12 @@ function ipa_details_field(spec) {
 
 
             dd = ipa_create_first_dd(that.name);
-            dd.append(ipa_details_field_create_input.call(that, that.values[0], hint_span, rights, 0));
+            dd.append(that.create_value(that.values[0], hint_span, rights, 0));
             dd.appendTo(that.container);
 
             for (var i = 1; i < that.values.length; ++i) {
                 dd = ipa_create_other_dd(that.name);
-                dd.append(ipa_details_field_create_input.call(that, that.values[i], hint_span, rights, i));
+                dd.append(that.create_value(that.values[i], hint_span, rights, i));
                 dd.appendTo(that.container);
             }
 
@@ -112,12 +112,113 @@ function ipa_details_field(spec) {
 
             } else {
                 dd = ipa_create_first_dd(that.name);
-                dd.append(ipa_details_field_create_input.call(that, '', hint_span, rights, 0));
+                dd.append(that.create_value('', hint_span, rights, 0));
                 dd.appendTo(that.container);
             }
         }
     };
 
+    /* create an HTML element for displaying/editing an attribute
+     * arguments:
+     *   attr - LDAP attribute name
+     *   value - the attributes value */
+    that.create_value = function(value, hint, rights, index) {
+
+        // if field is primary key or non-writable, return a label
+
+        var label = $('<label/>', { html:value.toString() });
+
+        if (!IPA.is_field_writable(rights)) return label;
+
+        var param_info = ipa_get_param_info(that.entity_name, that.name);
+        if (param_info) {
+            if (param_info['primary_key']) return label;
+            if ('no_update' in param_info['flags']) return label;
+        }
+
+        // otherwise, create input field
+        
+        var input = that.create_input(value, param_info, rights, index);
+        if (param_info) {
+            if (param_info['multivalue'] || param_info['class'] == 'List') {
+                input.append(_ipa_create_remove_link(that.name, param_info));
+            }
+        }
+
+        if (hint) input.after(hint);
+
+        return input;
+    };
+
+    /* creates a input box for editing a string attribute */
+    that.create_input = function(value, param_info, rights, index) {
+
+        index = index || 0;
+
+        function validate_input(text, param_info, error_link) {
+            if (param_info && param_info.pattern) {
+                var regex = new RegExp( param_info.pattern );
+                if (!text.match(regex)) {
+                    error_link.style.display = "block";
+                    if (param_info.pattern_errmsg) {
+                        error_link.innerHTML =  param_info.pattern_errmsg;
+                    }
+                } else {
+                    error_link.style.display = "none";
+                }
+            }
+        }
+
+        var doc = that.name;
+        if (param_info && param_info.doc) {
+            doc = param_info.doc;
+        }
+        var span = $("<Span />");
+        var input = $("<input/>", {
+            type: "text",
+            name: that.name,
+            value: value.toString(),
+            title: doc,
+            keyup: function(){
+                var undo_link = this.nextElementSibling;
+                undo_link.style.display = "inline";
+                var error_link = undo_link.nextElementSibling;
+
+                var text = $(this).val();
+                validate_input(text, param_info,error_link);
+            }
+        }).appendTo(span) ;
+
+        if (!IPA.is_field_writable(rights)) {
+            input.attr('disabled', 'disabled');
+        }
+
+        span.append($("<a/>", {
+            html:"undo",
+            "class":"ui-state-highlight ui-corner-all undo",
+            style:"display:none",
+            click: function(){
+                var previous_value = that.values || '';
+                if (index >= previous_value.length){
+                    previous_value = '';
+                }else{
+                    previous_value= previous_value[index];
+                }
+
+                this.previousElementSibling.value =  previous_value;
+                this.style.display = "none";
+                var error_link = this.nextElementSibling;
+                validate_input(previous_value, param_info,error_link);
+            }
+        }));
+        span.append($("<span/>", {
+            html:"Does not match pattern",
+            "class":"ui-state-error ui-corner-all",
+            style:"display:none"
+        }));
+        return span;
+    };
+
     function save() {
         var values = [];
 
@@ -178,7 +279,28 @@ function ipa_details_section(spec){
     };
 
     that.create_field = function(spec) {
-        var field = ipa_details_field(spec);
+
+        var field;
+
+        /* mapping of parameter types to handlers used to create inputs */
+        var param_info = ipa_get_param_info(that.entity_name, spec.name);
+        var class_name = param_info ? param_info['class'] : null;
+
+        //TODO: replace ipa_details_field with class-specific implementation
+        if (class_name == 'Str') {
+            field = ipa_details_field(spec);
+        } else if (class_name == 'IA5Str') {
+            field = ipa_details_field(spec);
+        } else if (class_name == 'Int') {
+            field = ipa_details_field(spec);
+        } else if (class_name == 'Bool') {
+            field = ipa_details_field(spec);
+        } else if (class_name == 'List') {
+            field = ipa_details_field(spec);
+        } else {
+            field = ipa_details_field(spec);
+        }
+
         that.add_field(field);
         return field;
     };
@@ -332,11 +454,13 @@ function ipa_details_list_section(spec){
             var field = fields[i];
 
             var label = field.label;
-            if (label !== ''){
+
+            // no need to get i18n label from metadata
+            // because it's already done by field.init()
+
+            if (label !== '') {
                 label += ':';
             }
-            var param_info = ipa_get_param_info(that.entity_name, field.name);
-            if (param_info && param_info['label']) label = param_info['label'];
 
             $('<dt/>', {
                 html: label
@@ -727,56 +851,6 @@ function ipa_insert_dd(jobj, content, dd_class){
 
 
 
-/* mapping of parameter types to handlers used to create inputs */
-var _ipa_param_type_2_handler_map = {
-    'Str': _ipa_create_text_input,
-    'IA5Str': _ipa_create_text_input,
-    'Int': _ipa_create_text_input,
-    'Bool': _ipa_create_text_input,
-    'List': _ipa_create_text_input
-};
-
-/* create an HTML element for displaying/editing an attribute
- * arguments:
- *   attr - LDAP attribute name
- *   value - the attributes value */
-function ipa_details_field_create_input(value,hint,rights, index)
-{
-    var that = this;
-
-    var input = $("<label>",{html:value.toString()});
-    var param_info = ipa_get_param_info(that.entity_name, that.name);
-    if (!param_info) {
-        /* no information about the param is available, default to text input */
-        input = _ipa_create_text_input.call(that, value, null, rights, index);
-        if (hint){
-            input.after(hint);
-        }
-    }else if (param_info['primary_key'] ||
-              ('no_update' in param_info['flags'])){
-        /* check if the param value can be modified */
-        /*  This is currently a no-op, as we use this logic for the
-            default case as well */
-        return input;
-    }else{
-        /* call handler by param class */
-        var handler = _ipa_param_type_2_handler_map[param_info['class']];
-        if (handler) {
-            input = handler.call(that, value, param_info, rights, index);
-            if ((param_info['multivalue'] ||
-                 param_info['class'] == 'List') &&
-                IPA.is_field_writable(rights)){
-                input.append( _ipa_create_remove_link(that.name, param_info));
-            }
-            if (hint){
-                input.after(hint);
-            }
-        }
-    }
-    return input;
-}
-
-
 /* creates a Remove link for deleting attribute values */
 function _ipa_create_remove_link(attr, param_info)
 {
@@ -797,76 +871,6 @@ function _ipa_create_remove_link(attr, param_info)
 }
 
 
-/* creates a input box for editing a string attribute */
-function _ipa_create_text_input(value, param_info, rights, index)
-{
-    var that = this;
-    index = index || 0;
-
-    function validate_input(text, param_info,error_link){
-        if(param_info && param_info.pattern){
-            var regex = new RegExp( param_info.pattern );
-            if (!text.match(regex)) {
-                error_link.style.display ="block";
-                if ( param_info.pattern_errmsg){
-                    error_link.innerHTML =  param_info.pattern_errmsg;
-                }
-            }else{
-                error_link.style.display ="none";
-            }
-        }
-    }
-
-    var doc = that.name;
-    if (param_info && param_info.doc){
-        doc =  param_info.doc;
-    }
-    var span = $("<Span />");
-    var input = $("<input/>",{
-        type: "text",
-        name: that.name,
-        value: value.toString(),
-        title: doc,
-        keyup: function(){
-            var undo_link=this.nextElementSibling;
-            undo_link.style.display ="inline";
-            var error_link = undo_link.nextElementSibling;
-
-            var text = $(this).val();
-            validate_input(text, param_info,error_link);
-        }
-    }).appendTo(span) ;
-
-    if (!IPA.is_field_writable(rights)){
-        input.attr('disabled', 'disabled');
-    }
-
-    span.append($("<a/>",{
-        html:"undo",
-        "class":"ui-state-highlight ui-corner-all undo",
-        style:"display:none",
-        click: function(){
-            var previous_value = that.values || '';
-            if (index >= previous_value.length){
-                previous_value = '';
-            }else{
-                previous_value= previous_value[index];
-            }
-
-            this.previousElementSibling.value =  previous_value;
-            this.style.display = "none";
-            var error_link = this.nextElementSibling;
-            validate_input(previous_value, param_info,error_link);
-        }
-    }));
-    span.append($("<span/>",{
-        html:"Does not match pattern",
-        "class":"ui-state-error ui-corner-all",
-        style:"display:none"
-    }));
-    return span;
-}
-
 function ipa_details_field_create_add_link(title, rights, index) {
 
     var that = this;
@@ -878,7 +882,7 @@ function ipa_details_field_create_add_link(title, rights, index) {
         'click': function () {
 
             var param_info = ipa_get_param_info(that.entity_name, '');
-            var input = _ipa_create_text_input.call(that, '', param_info, rights, index);
+            var input = that.create_input('', param_info, rights, index);
 
             link.replaceWith(input);
             input.focus();
diff --git a/install/static/host.js b/install/static/host.js
index b6ca404af65618cec06abc8d03344b2faf2ee992..708da86868367237c2de0c7027ebae9bba1ad1c8 100644
--- a/install/static/host.js
+++ b/install/static/host.js
@@ -129,17 +129,24 @@ function ipa_host_details_facet(spec) {
         });
         that.add_section(section);
 
-        section.create_field({'name': 'fqdn'});
+        //TODO: use i18n labels
+        section.create_field({
+            name: 'fqdn',
+            label: 'Fully Qualified Host Name'
+        });
+
         section.create_field({'name': 'krbprincipalname'});
 
-        //TODO add this to the host plugin
+        //TODO: add this to the host plugin
+        //TODO: use i18n labels
         section.create_field({
             'name': 'serverhostname',
-            'label': 'Server Host Name'
+            'label': 'Host Name'
         });
 
         section.create_field({'name': 'description'});
 
+        //TODO: use i18n labels
         section = ipa_details_list_section({
             'name': 'enrollment',
             'label': 'Enrollment'
diff --git a/install/static/test/data/host_show.json b/install/static/test/data/host_show.json
index b858970e4063afac0a870d67e01ae33d7e1e15af..b87802310c15fea376ed7db31d586d9eb82fb1e7 100644
--- a/install/static/test/data/host_show.json
+++ b/install/static/test/data/host_show.json
@@ -11,23 +11,26 @@
                 "fqdn": "rscwo",
                 "ipaclientversion": "rscwo",
                 "ipauniqueid": "rsc",
-                "krbcanonicalname": "rscwo",
-                "krbextradata": "rscwo",
-                "krblastfailedauth": "rscwo",
+                "krbcanonicalname": "rsc",
+                "krbextradata": "rsc",
+                "krblastfailedauth": "rsc",
                 "krblastpwdchange": "rscwo",
-                "krblastsuccessfulauth": "rscwo",
-                "krbloginfailedcount": "rscwo",
+                "krblastsuccessfulauth": "rsc",
+                "krbloginfailedcount": "rsc",
+                "krbmaxrenewableage": "rscwo",
+                "krbmaxticketlife": "rscwo",
                 "krbobjectreferences": "rscwo",
-                "krbpasswordexpiration": "rscwo",
-                "krbprincipalaliases": "rscwo",
-                "krbprincipalexpiration": "rscwo",
+                "krbpasswordexpiration": "rsc",
+                "krbprincipalaliases": "rsc",
+                "krbprincipalexpiration": "rsc",
                 "krbprincipalkey": "wo",
-                "krbprincipalname": "rscwo",
-                "krbprincipaltype": "rscwo",
-                "krbpwdhistory": "rscwo",
-                "krbpwdpolicyreference": "rscwo",
-                "krbticketpolicyreference": "rscwo",
-                "krbupenabled": "rscwo",
+                "krbprincipalname": "rsc",
+                "krbprincipaltype": "rsc",
+                "krbpwdhistory": "rsc",
+                "krbpwdpolicyreference": "rsc",
+                "krbticketflags": "rsc",
+                "krbticketpolicyreference": "rsc",
+                "krbupenabled": "rsc",
                 "l": "rscwo",
                 "managedby": "rscwo",
                 "memberof": "rsc",
diff --git a/install/static/test/data/host_show_dev.example.com.json b/install/static/test/data/host_show_dev.example.com.json
index d3e54fc84db464c6675503d578a99be792c578ea..1ee9f445f27e02cc1e007380463d8ae7bb4ebef3 100644
--- a/install/static/test/data/host_show_dev.example.com.json
+++ b/install/static/test/data/host_show_dev.example.com.json
@@ -11,26 +11,26 @@
                 "fqdn": "rscwo",
                 "ipaclientversion": "rscwo",
                 "ipauniqueid": "rsc",
-                "krbcanonicalname": "rscwo",
-                "krbextradata": "rscwo",
-                "krblastfailedauth": "rscwo",
+                "krbcanonicalname": "rsc",
+                "krbextradata": "rsc",
+                "krblastfailedauth": "rsc",
                 "krblastpwdchange": "rscwo",
-                "krblastsuccessfulauth": "rscwo",
-                "krbloginfailedcount": "rscwo",
+                "krblastsuccessfulauth": "rsc",
+                "krbloginfailedcount": "rsc",
                 "krbmaxrenewableage": "rscwo",
                 "krbmaxticketlife": "rscwo",
                 "krbobjectreferences": "rscwo",
-                "krbpasswordexpiration": "rscwo",
-                "krbprincipalaliases": "rscwo",
-                "krbprincipalexpiration": "rscwo",
+                "krbpasswordexpiration": "rsc",
+                "krbprincipalaliases": "rsc",
+                "krbprincipalexpiration": "rsc",
                 "krbprincipalkey": "wo",
-                "krbprincipalname": "rscwo",
-                "krbprincipaltype": "rscwo",
-                "krbpwdhistory": "rscwo",
-                "krbpwdpolicyreference": "rscwo",
-                "krbticketflags": "rscwo",
-                "krbticketpolicyreference": "rscwo",
-                "krbupenabled": "rscwo",
+                "krbprincipalname": "rsc",
+                "krbprincipaltype": "rsc",
+                "krbpwdhistory": "rsc",
+                "krbpwdpolicyreference": "rsc",
+                "krbticketflags": "rsc",
+                "krbticketpolicyreference": "rsc",
+                "krbupenabled": "rsc",
                 "l": "rscwo",
                 "managedby": "rscwo",
                 "memberof": "rsc",
diff --git a/install/static/test/data/host_show_test.example.com.json b/install/static/test/data/host_show_test.example.com.json
index b858970e4063afac0a870d67e01ae33d7e1e15af..b87802310c15fea376ed7db31d586d9eb82fb1e7 100644
--- a/install/static/test/data/host_show_test.example.com.json
+++ b/install/static/test/data/host_show_test.example.com.json
@@ -11,23 +11,26 @@
                 "fqdn": "rscwo",
                 "ipaclientversion": "rscwo",
                 "ipauniqueid": "rsc",
-                "krbcanonicalname": "rscwo",
-                "krbextradata": "rscwo",
-                "krblastfailedauth": "rscwo",
+                "krbcanonicalname": "rsc",
+                "krbextradata": "rsc",
+                "krblastfailedauth": "rsc",
                 "krblastpwdchange": "rscwo",
-                "krblastsuccessfulauth": "rscwo",
-                "krbloginfailedcount": "rscwo",
+                "krblastsuccessfulauth": "rsc",
+                "krbloginfailedcount": "rsc",
+                "krbmaxrenewableage": "rscwo",
+                "krbmaxticketlife": "rscwo",
                 "krbobjectreferences": "rscwo",
-                "krbpasswordexpiration": "rscwo",
-                "krbprincipalaliases": "rscwo",
-                "krbprincipalexpiration": "rscwo",
+                "krbpasswordexpiration": "rsc",
+                "krbprincipalaliases": "rsc",
+                "krbprincipalexpiration": "rsc",
                 "krbprincipalkey": "wo",
-                "krbprincipalname": "rscwo",
-                "krbprincipaltype": "rscwo",
-                "krbpwdhistory": "rscwo",
-                "krbpwdpolicyreference": "rscwo",
-                "krbticketpolicyreference": "rscwo",
-                "krbupenabled": "rscwo",
+                "krbprincipalname": "rsc",
+                "krbprincipaltype": "rsc",
+                "krbpwdhistory": "rsc",
+                "krbpwdpolicyreference": "rsc",
+                "krbticketflags": "rsc",
+                "krbticketpolicyreference": "rsc",
+                "krbupenabled": "rsc",
                 "l": "rscwo",
                 "managedby": "rscwo",
                 "memberof": "rsc",
diff --git a/install/static/test/details_tests.js b/install/static/test/details_tests.js
index baed80ce52c746ae1a357988c956240222d37088..1cb2036fdd9abddf3cb5d084a5c0f7a39ab6f4e1 100644
--- a/install/static/test/details_tests.js
+++ b/install/static/test/details_tests.js
@@ -225,7 +225,7 @@ test("Testing details lifecycle: create, setup, load.", function(){
 });
 
 
-test("Testing  _ipa_create_text_input().", function(){
+test("Testing create_input().", function() {
 
     var field = ipa_details_field({
         'name': "name"
@@ -234,7 +234,7 @@ test("Testing  _ipa_create_text_input().", function(){
     var name = "name";
     var value="value";
     var rights = 'rscwo'
-    var input = _ipa_create_text_input.call(field, value, null,rights);
+    var input = field.create_input(value, null, rights);
     ok(input,"input not null");
 
     var text = input.find('input');
@@ -245,7 +245,7 @@ test("Testing  _ipa_create_text_input().", function(){
     same(text[0].type,"text" );
 });
 
-test("Testing  _ipa_create_text_input() read only .", function(){
+test("Testing create_input() read only .", function() {
 
     var field = ipa_details_field({
         'name': "name"
@@ -254,7 +254,7 @@ test("Testing  _ipa_create_text_input() read only .", function(){
     var name = "name";
     var value="value";
     var rights = 'rsc'
-    var input = _ipa_create_text_input.call(field, value, null,rights);
+    var input = field.create_input(value, null, rights);
     ok(input,"input not null");
 
     var text = input.find('input');
diff --git a/install/static/widget.js b/install/static/widget.js
index 795cc42a204879553fe275ffc5db1d774008ee28..d9661c3e86374c164ab405806c8335e46b238992 100755
--- a/install/static/widget.js
+++ b/install/static/widget.js
@@ -44,6 +44,7 @@ function ipa_widget(spec) {
     that.save = spec.save || save;
     that.update = spec.update || update;
     that.validate_input = spec.validate_input || validate_input;
+    that.param_info = spec.param_info;
 
     that.__defineGetter__("entity_name", function(){
         return that._entity_name;
@@ -53,28 +54,26 @@ function ipa_widget(spec) {
         that._entity_name = entity_name;
     });
 
-    var param_info;
-
     /*returns true and clears the error message if the field value  passes
       the validation pattern.  If the field value does not pass validation, 
       displays the error message and returns false. */
-    function validate_input(text){
-        if(!(param_info && param_info.pattern)){
+    function validate_input(text) {
+        if (!(that.param_info && that.param_info.pattern)) {
             return true;
         }
         var error_link = that.get_error_link();
-        if (!error_link){
+        if (!error_link) {
             return true;
         }
-        var regex = new RegExp( param_info.pattern );
+        var regex = new RegExp( that.param_info.pattern );
         //If the field is empty, don't validate
-        if (!text || text.match(regex) ) {
+        if ( !text || text.match(regex) ) {
             error_link.css('display', 'none');
             return true;
         }else{
             error_link.css('display', 'block');
-            if ( param_info.pattern_errmsg){
-                error_link.html(param_info.pattern_errmsg);
+            if (that.param_info.pattern_errmsg) {
+                error_link.html(that.param_info.pattern_errmsg);
             }
             return false;
         }
@@ -82,9 +81,9 @@ function ipa_widget(spec) {
 
     function init() {
         if (that.entity_name && !that.label){
-            param_info = ipa_get_param_info(that.entity_name, spec.name);
-            if ((param_info) && (that.label === undefined)){
-                that.label = param_info.label;
+            that.param_info = ipa_get_param_info(that.entity_name, that.name);
+            if ((that.param_info) && (that.label === undefined)){
+                that.label = that.param_info.label;
             }
         }
     }
-- 
1.6.6.1

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

Reply via email to