The metadata and param_info attributes in widget have been merged
because they are redundant.

Ticket #1436

--
Endi S. Dewata
From fa90f18dba1f4e3d7cbdffb37449689f79e0bfc0 Mon Sep 17 00:00:00 2001
From: Endi S. Dewata <edew...@redhat.com>
Date: Wed, 26 Oct 2011 01:20:35 -0500
Subject: [PATCH] Merged widget's metadata and param_info.

The metadata and param_info attributes in widget have been merged
because they are redundant.

Ticket #1436
---
 install/ui/details.js           |    6 +-
 install/ui/dns.js               |   52 +++++++++---------
 install/ui/hbac.js              |    6 +-
 install/ui/host.js              |   10 ++--
 install/ui/rule.js              |   10 ++--
 install/ui/search.js            |    4 +-
 install/ui/service.js           |    2 +-
 install/ui/sudo.js              |   52 +++++++++---------
 install/ui/test/ipa_tests.js    |   20 ++++----
 install/ui/test/widget_tests.js |    6 +-
 install/ui/widget.js            |  115 +++++++++++++++++----------------------
 11 files changed, 135 insertions(+), 148 deletions(-)

diff --git a/install/ui/details.js b/install/ui/details.js
index 3debf75d281dd93fafa4ee9a3ba06941170b6ce6..022b005bc42a6fad744eecddbf92439a99da7785 100644
--- a/install/ui/details.js
+++ b/install/ui/details.js
@@ -652,9 +652,9 @@ IPA.details_facet = function(spec) {
                 var values = record[field.name];
                 if (!values) continue;
 
-                var param_info = field.param_info;
-                if (param_info) {
-                    if (param_info.primary_key) continue;
+                var metadata = field.metadata;
+                if (metadata) {
+                    if (metadata.primary_key) continue;
                     if (values.length === 1) {
                         command.set_option(field.name, values[0]);
                     } else if (field.join) {
diff --git a/install/ui/dns.js b/install/ui/dns.js
index a1c4bbf68c294aae2563845b65ac952ff7e32d33..e917f8e46508ea09b2c8ee361229743380f090ba 100644
--- a/install/ui/dns.js
+++ b/install/ui/dns.js
@@ -129,7 +129,7 @@ IPA.entity_factories.dnszone = function() {
                         {
                             factory: IPA.force_dnszone_add_checkbox_widget,
                             name: 'force',
-                            param_info: IPA.get_method_option('dnszone_add', 'force')
+                            metadata: IPA.get_method_option('dnszone_add', 'force')
                         }
                     ]
                 }
@@ -180,10 +180,10 @@ IPA.dnszone_details_facet = function(spec) {
                 var values = field.save();
                 if (!values) continue;
 
-                var param_info = field.param_info;
+                var metadata = field.metadata;
 
                 // skip primary key
-                if (param_info && param_info.primary_key) continue;
+                if (metadata && metadata.primary_key) continue;
 
                 // check enable/disable
                 if (field.name == 'idnszoneactive') {
@@ -192,7 +192,7 @@ IPA.dnszone_details_facet = function(spec) {
                     continue;
                 }
 
-                if (param_info) {
+                if (metadata) {
                     if (values.length == 1) {
                         modify_operation.command.set_option(field.name, values[0]);
                     } else if (field.join) {
@@ -464,42 +464,42 @@ IPA.entity_factories.dnsrecord = function() {
                     fields:[
                         { factory: IPA.multivalued_text_widget,
                           name: 'arecord',
-                          param_info: {primary_key: false},
+                          metadata: {primary_key: false},
                           label:'A'
                         },
                         { factory: IPA.multivalued_text_widget,
                           name: 'aaaarecord',
-                          param_info: {primary_key: false},
+                          metadata: {primary_key: false},
                           label:'AAAA'
                         },
                         { factory: IPA.multivalued_text_widget,
                           name: 'ptrrecord',
-                          param_info: {primary_key: false},
+                          metadata: {primary_key: false},
                           label:'PTR'
                         },
                         { factory: IPA.multivalued_text_widget,
                           name: 'srvrecord',
-                          param_info: {primary_key: false},
+                          metadata: {primary_key: false},
                           label:'SRV'
                         },
                         { factory: IPA.multivalued_text_widget,
                           name: 'txtrecord',
-                          param_info: {primary_key: false},
+                          metadata: {primary_key: false},
                           label:'TXT'
                         },
                         { factory: IPA.multivalued_text_widget,
                           name: 'cnamerecord',
-                          param_info: {primary_key: false},
+                          metadata: {primary_key: false},
                           label:'CNAME'
                         },
                         { factory: IPA.multivalued_text_widget,
                           label:'MX',
-                          param_info: {primary_key: false},
+                          metadata: {primary_key: false},
                           name:"mxrecord"
                         },
                         { factory: IPA.multivalued_text_widget,
                           label:'NS',
-                          param_info: {primary_key: false},
+                          metadata: {primary_key: false},
                           name:"nsrecord"
                         }
 
@@ -511,37 +511,37 @@ IPA.entity_factories.dnsrecord = function() {
                     fields:[
                         { factory: IPA.multivalued_text_widget,
                           label:'AFSDB',
-                          param_info: {primary_key: false},
+                          metadata: {primary_key: false},
                           name: "afsdbrecord"
                         },
                         { factory: IPA.multivalued_text_widget,
                           label:'CERT',
-                          param_info: {primary_key: false},
+                          metadata: {primary_key: false},
                           name:"certrecord"
                         },
                         { factory: IPA.multivalued_text_widget,
                           label:'DNAME',
-                          param_info: {primary_key: false},
+                          metadata: {primary_key: false},
                           name:"dnamerecord"
                         },
                         { factory: IPA.multivalued_text_widget,
                           label:'DSRECORD',
-                          param_info: {primary_key: false},
+                          metadata: {primary_key: false},
                           name:"dsrecord"
                         },
                         { factory: IPA.multivalued_text_widget,
                           label:'KEY',
-                          param_info: {primary_key: false},
+                          metadata: {primary_key: false},
                           name:"keyrecord"
                         },
                         { factory: IPA.multivalued_text_widget,
                           label:'KX',
-                          param_info: {primary_key: false},
+                          metadata: {primary_key: false},
                           name:"kxrecord"
                         },
                         { factory: IPA.multivalued_text_widget,
                           label:'LOC',
-                          param_info: {primary_key: false},
+                          metadata: {primary_key: false},
                           name:"locrecord"
                         },
                         { factory: IPA.multivalued_text_widget,
@@ -550,22 +550,22 @@ IPA.entity_factories.dnsrecord = function() {
                         },
                         { factory: IPA.multivalued_text_widget,
                           label:'NSEC',
-                          param_info: {primary_key: false},
+                          metadata: {primary_key: false},
                           name:"nsecrecord"
                         },
                         { factory: IPA.multivalued_text_widget,
                           label:'RRSIG',
-                          param_info: {primary_key: false},
+                          metadata: {primary_key: false},
                           name:"rrsigrecord"
                         },
                         { factory: IPA.multivalued_text_widget,
                           label:'SIG',
-                          param_info: {primary_key: false},
+                          metadata: {primary_key: false},
                           name:"sigrecord"
                         },
                         { factory: IPA.multivalued_text_widget,
                           label:'SSHFP',
-                          param_info: {primary_key: false},
+                          metadata: {primary_key: false},
                           name:"sshfprecord"
                         }
                     ]
@@ -659,9 +659,9 @@ IPA.dnsrecord_type_widget = function(spec) {
 };
 
 IPA.force_dnszone_add_checkbox_widget = function(spec) {
-    var param_info = IPA.get_method_option('dnszone_add', spec.name);
-    spec.label = param_info.label;
-    spec.tooltip = param_info.doc;
+    var metadata = IPA.get_method_option('dnszone_add', spec.name);
+    spec.label = metadata.label;
+    spec.tooltip = metadata.doc;
     return IPA.checkbox_widget(spec);
 };
 
diff --git a/install/ui/hbac.js b/install/ui/hbac.js
index e05e43f6b06651c4fe390526dba2262e1f088922..b5c223614f52c0213d8b15fa05148712e673f7de 100644
--- a/install/ui/hbac.js
+++ b/install/ui/hbac.js
@@ -454,10 +454,10 @@ IPA.hbacrule_details_facet = function(spec) {
                 var values = field.save();
                 if (!values) continue;
 
-                var param_info = field.param_info;
+                var metadata = field.metadata;
 
                 // skip primary key
-                if (param_info && param_info.primary_key) continue;
+                if (metadata && metadata.primary_key) continue;
 
                 var p = field.name.indexOf('_');
                 if (p >= 0) {
@@ -488,7 +488,7 @@ IPA.hbacrule_details_facet = function(spec) {
                     }
                 }
 
-                if (param_info) {
+                if (metadata) {
                     if (values.length == 1) {
                         modify_operation.command.set_option(field.name, values[0]);
                     } else if (field.join) {
diff --git a/install/ui/host.js b/install/ui/host.js
index ea1246d3f07490d6580d9cff350cd92d67f6c2f8..34041762a72565027f6e971fdf687193f3635ce3 100644
--- a/install/ui/host.js
+++ b/install/ui/host.js
@@ -153,12 +153,12 @@ IPA.entity_factories.host = function () {
                         {
                             factory: IPA.text_widget,
                             name: 'ip_address',
-                            param_info: IPA.get_method_option('host_add', 'ip_address')
+                            metadata: IPA.get_method_option('host_add', 'ip_address')
                         },
                         {
                             factory: IPA.force_host_add_checkbox_widget,
                             name: 'force',
-                            param_info: IPA.get_method_option('host_add', 'force')
+                            metadata: IPA.get_method_option('host_add', 'force')
                         }
                     ]
                 }
@@ -411,9 +411,9 @@ IPA.utc_date_column_format = function(value){
 
 
 IPA.force_host_add_checkbox_widget = function(spec) {
-    var param_info = IPA.get_method_option('host_add', spec.name);
-    spec.label = param_info.label;
-    spec.tooltip = param_info.doc;
+    var metadata = IPA.get_method_option('host_add', spec.name);
+    spec.label = metadata.label;
+    spec.tooltip = metadata.doc;
     return IPA.checkbox_widget(spec);
 };
 
diff --git a/install/ui/rule.js b/install/ui/rule.js
index b4d10a1fc344185e773455cac6c073fa59aa7071..9744b0f2bc7b0b498435abf04415c054dcde2813 100644
--- a/install/ui/rule.js
+++ b/install/ui/rule.js
@@ -38,13 +38,13 @@ IPA.rule_details_section = function(spec) {
         that.container = container;
 
         var field = that.get_field(that.field_name);
-        var param_info = IPA.get_entity_param(that.entity.name, that.field_name);
+        var metadata = IPA.get_entity_param(that.entity.name, that.field_name);
 
-        container.append(param_info.doc+':');
+        container.append(metadata.doc+':');
 
         var span = $('<span/>', {
             name: that.field_name,
-            title: param_info.doc,
+            title: metadata.doc,
             'class': 'field'
         }).appendTo(container);
 
@@ -87,11 +87,11 @@ IPA.rule_details_section = function(spec) {
         for (var j=0; j<that.tables.length; j++) {
             var table = that.tables[j];
 
-            param_info = IPA.get_entity_param(that.entity.name, table.field_name);
+            metadata = IPA.get_entity_param(that.entity.name, table.field_name);
 
             var table_span = $('<span/>', {
                 name: table.field_name,
-                title: param_info ? param_info.doc : table.field_name,
+                title: metadata ? metadata.doc : table.field_name,
                 'class': 'field'
             }).appendTo(span);
 
diff --git a/install/ui/search.js b/install/ui/search.js
index 83b91051c2a5e2cb87e83b61a281dd827f7dfe0c..ab3a1cea44fbfbd0aa43fdab22da73003fd7e042 100644
--- a/install/ui/search.js
+++ b/install/ui/search.js
@@ -65,8 +65,8 @@ IPA.search_facet = function(spec) {
         for (var i=0; i<columns.length; i++) {
             var column = columns[i];
             column.entity = entity;
-            var param_info = IPA.get_entity_param(entity.name, column.name);
-            column.primary_key = param_info && param_info['primary_key'];
+            var metadata = IPA.get_entity_param(entity.name, column.name);
+            column.primary_key = metadata && metadata.primary_key;
             column.link = column.primary_key;
 
             if (column.link) {
diff --git a/install/ui/service.js b/install/ui/service.js
index 02b206e19fa5cb03e1cc5eebb5380d279fb8e9b3..43e1516ad59772546417706a48ef4d28c44e4021 100644
--- a/install/ui/service.js
+++ b/install/ui/service.js
@@ -128,7 +128,7 @@ IPA.service_adder_dialog = function(spec) {
         field(IPA.checkbox_widget({
             name: 'force',
             entity: spec.entity,
-            param_info: IPA.get_method_option('service_add', 'force')
+            metadata: IPA.get_method_option('service_add', 'force')
         }));
 
 
diff --git a/install/ui/sudo.js b/install/ui/sudo.js
index 226ea8db42176bf410d8ea9443f96c3d10db10bd..f2dd646edd5f53cce765a46c7dc0ac16ceb7ab17 100644
--- a/install/ui/sudo.js
+++ b/install/ui/sudo.js
@@ -403,10 +403,10 @@ IPA.sudorule_details_facet = function(spec) {
                 var values = field.save();
                 if (!values) continue;
 
-                var param_info = field.param_info;
+                var metadata = field.metadata;
 
                 // skip primary key
-                if (param_info && param_info.primary_key) continue;
+                if (metadata && metadata.primary_key) continue;
 
                 var p = field.name.indexOf('_');
                 if (p >= 0) {
@@ -436,7 +436,7 @@ IPA.sudorule_details_facet = function(spec) {
                     categories[field.name].remove_values = true;
                 }
 
-                if (param_info) {
+                if (metadata) {
                     if (values.length == 1) {
                         modify_operation.command.set_option(field.name, values[0]);
                     } else if (field.join) {
@@ -817,11 +817,11 @@ IPA.sudo.rule_details_command_section = function(spec) {
         that.container = container;
 
         var field = that.get_field('cmdcategory');
-        var param_info = IPA.get_entity_param(that.entity.name, 'cmdcategory');
+        var metadata = IPA.get_entity_param(that.entity.name, 'cmdcategory');
 
         var span = $('<span/>', {
             name: 'cmdcategory',
-            title: param_info.doc,
+            title: metadata.doc,
             'class': 'field'
         }).appendTo(container);
 
@@ -830,28 +830,28 @@ IPA.sudo.rule_details_command_section = function(spec) {
             title: IPA.messages.objects.sudorule.allow
         }).appendTo(span);
 
-        span.append(param_info.doc+": ");
+        span.append(metadata.doc+": ");
 
         that.category.create(span);
 
-        param_info = IPA.get_entity_param(
+        metadata = IPA.get_entity_param(
             that.entity.name, 'memberallowcmd_sudocmd');
 
         var table_span = $('<span/>', {
             name: 'memberallowcmd_sudocmd',
-            title: param_info ? param_info.doc : 'memberallowcmd_sudocmd',
+            title: metadata ? metadata.doc : 'memberallowcmd_sudocmd',
             'class': 'field'
         }).appendTo(span);
 
         field = that.get_field('memberallowcmd_sudocmd');
         field.create(table_span);
 
-        param_info = IPA.get_entity_param(
+        metadata = IPA.get_entity_param(
             that.entity.name, 'memberallowcmd_sudocmdgroup');
 
         table_span = $('<span/>', {
             name: 'memberallowcmd_sudocmdgroup',
-            title: param_info ? param_info.doc : 'memberallowcmd_sudocmdgroup',
+            title: metadata ? metadata.doc : 'memberallowcmd_sudocmdgroup',
             'class': 'field'
         }).appendTo(span);
 
@@ -863,24 +863,24 @@ IPA.sudo.rule_details_command_section = function(spec) {
             title: IPA.messages.objects.sudorule.deny
         }).appendTo(span);
 
-        param_info = IPA.get_entity_param(
+        metadata = IPA.get_entity_param(
             that.entity.name, 'memberdenycmd_sudocmd');
 
         table_span = $('<span/>', {
             name: 'memberdenycmd_sudocmd',
-            title: param_info ? param_info.doc : 'memberdenycmd_sudocmd',
+            title: metadata ? metadata.doc : 'memberdenycmd_sudocmd',
             'class': 'field'
         }).appendTo(span);
 
         field = that.get_field('memberdenycmd_sudocmd');
         field.create(table_span);
 
-        param_info = IPA.get_entity_param(
+        metadata = IPA.get_entity_param(
             that.entity.name, 'memberdenycmd_sudocmdgroup');
 
         table_span = $('<span/>', {
             name: 'memberdenycmd_sudocmdgroup',
-            title: param_info ? param_info.doc : 'memberdenycmd_sudocmdgroup',
+            title: metadata ? metadata.doc : 'memberdenycmd_sudocmdgroup',
             'class': 'field'
         }).appendTo(span);
 
@@ -994,34 +994,34 @@ IPA.sudo.rule_details_runas_section = function(spec) {
         that.container = container;
 
         var field = that.get_field('ipasudorunasusercategory');
-        var param_info = IPA.get_entity_param(
+        var metadata = IPA.get_entity_param(
             that.entity.name, 'ipasudorunasusercategory');
 
         var span = $('<span/>', {
             name: 'ipasudorunasusercategory',
-            title: param_info.doc,
+            title: metadata.doc,
             'class': 'field'
         }).appendTo(container);
-        span.append(param_info.doc+": ");
+        span.append(metadata.doc+": ");
         field.create(span);
         span.append('<br/>');
 
-        param_info = IPA.get_entity_param(that.entity.name, 'ipasudorunas_user');
+        metadata = IPA.get_entity_param(that.entity.name, 'ipasudorunas_user');
 
         var table_span = $('<span/>', {
             name: 'ipasudorunas_user',
-            title: param_info ? param_info.doc : 'ipasudorunas_user',
+            title: metadata ? metadata.doc : 'ipasudorunas_user',
             'class': 'field'
         }).appendTo(span);
 
         field = that.get_field('ipasudorunas_user');
         field.create(table_span);
 
-        param_info = IPA.get_entity_param(that.entity.name, 'ipasudorunas_group');
+        metadata = IPA.get_entity_param(that.entity.name, 'ipasudorunas_group');
 
         table_span = $('<span/>', {
             name: 'ipasudorunas_group',
-            title: param_info ? param_info.doc : 'ipasudorunas_group',
+            title: metadata ? metadata.doc : 'ipasudorunas_group',
             'class': 'field'
         }).appendTo(span);
 
@@ -1029,25 +1029,25 @@ IPA.sudo.rule_details_runas_section = function(spec) {
         field.create(table_span);
 
         field = that.get_field('ipasudorunasgroupcategory');
-        param_info = IPA.get_entity_param(
+        metadata = IPA.get_entity_param(
             that.entity.name, 'ipasudorunasgroupcategory');
 
         span = $('<span/>', {
             name: 'ipasudorunasgroupcategory',
-            title: param_info.doc,
+            title: metadata.doc,
             'class': 'field'
         }).appendTo(container);
 
-        span.append(param_info.doc+": ");
+        span.append(metadata.doc+": ");
         field.create(span);
         span.append('<br/>');
 
-        param_info = IPA.get_entity_param(
+        metadata = IPA.get_entity_param(
             that.entity.name, 'ipasudorunasgroup_group');
 
         table_span = $('<span/>', {
             name: 'ipasudorunasgroup_group',
-            title: param_info ? param_info.doc : 'ipasudorunasgroup_group',
+            title: metadata ? metadata.doc : 'ipasudorunasgroup_group',
             'class': 'field'
         }).appendTo(span);
 
diff --git a/install/ui/test/ipa_tests.js b/install/ui/test/ipa_tests.js
index 0a4d657f8062dcf337eef760608dc8aae0af7f68..8b3efc708b9b130dc813b0adb880e9c071667e49 100644
--- a/install/ui/test/ipa_tests.js
+++ b/install/ui/test/ipa_tests.js
@@ -38,37 +38,37 @@ test("Testing ipa_init().", function() {
     );
 });
 
-test("Testing IPA.get_param_info().", function() {
+test("Testing IPA.get_entity_param().", function() {
 
-    var param_info = IPA.get_entity_param("user", "uid");
+    var metadata = IPA.get_entity_param("user", "uid");
     ok(
-        param_info,
-        "IPA.get_param_info(\"user\", \"uid\") not null"
+        metadata,
+        "IPA.get_entity_param(\"user\", \"uid\") not null"
     );
 
     equals(
-        param_info["label"], "User login",
-        "IPA.get_param_info(\"user\", \"uid\")[\"label\"]"
+        metadata["label"], "User login",
+        "IPA.get_entity_param(\"user\", \"uid\")[\"label\"]"
     );
 
     equals(
         IPA.get_entity_param("user", "wrong_attribute"), null,
-        "IPA.get_param_info(\"user\", \"wrong_attribute\")"
+        "IPA.get_entity_param(\"user\", \"wrong_attribute\")"
     );
 
     equals(
         IPA.get_entity_param("user", null), null,
-        "IPA.get_param_info(\"user\", null)"
+        "IPA.get_entity_param(\"user\", null)"
     );
 
     equals(
         IPA.get_entity_param("wrong_entity", "uid"), null,
-        "IPA.get_param_info(\"wrong_entity\", \"uid\")"
+        "IPA.get_entity_param(\"wrong_entity\", \"uid\")"
     );
 
     equals(
         IPA.get_entity_param(null, "uid"), null,
-        "IPA.get_param_info(null, \"uid\")"
+        "IPA.get_entity_param(null, \"uid\")"
     );
 });
 
diff --git a/install/ui/test/widget_tests.js b/install/ui/test/widget_tests.js
index caf28edcc8d577e38020c7dc3bae8aa7a3a7314b..50a5f7d6f9762388b6d5a10004f72d9a05eb0852 100644
--- a/install/ui/test/widget_tests.js
+++ b/install/ui/test/widget_tests.js
@@ -106,9 +106,9 @@ function text_tests(widget,input){
     same(widget.is_dirty(),false, "Undo Clears is_dirty");
 
 
-    var old_pattern =  widget.param_info.pattern;
+    var old_pattern =  widget.metadata.pattern;
 
-    widget.param_info.pattern ='abc';
+    widget.metadata.pattern ='abc';
     input.val('not right');
     input.keyup();
     same(widget.valid,false, 'Field is not valid');
@@ -122,7 +122,7 @@ function text_tests(widget,input){
     same(widget.valid,true, 'Field is valid');
     same(error_field.css('display'),'none','error field not visible');
 
-    widget.param_info.pattern = old_pattern;
+    widget.metadata.pattern = old_pattern;
 
 }
 
diff --git a/install/ui/widget.js b/install/ui/widget.js
index 85a48c1de6b40863e20ae9f9fc69764d98580734..b4f57d03ca6f5ba6ccf23fa401ac3095c7770e0b 100644
--- a/install/ui/widget.js
+++ b/install/ui/widget.js
@@ -57,7 +57,6 @@ IPA.widget = function(spec) {
     that.undo = spec.undo === undefined ? true : spec.undo;
     that.join = spec.join;
 
-    that.param_info = spec.param_info;
     that.metadata = spec.metadata;
 
     that.values = [];
@@ -66,62 +65,21 @@ IPA.widget = function(spec) {
 
     that.dirty_changed = IPA.observer();
 
-
-    function set_param_info() {
-        if (!that.param_info && that.entity) {
-            that.param_info =
-                IPA.get_entity_param(that.entity.name, that.name);
+    var init = function() {
+        if (!that.metadata && that.entity) {
+            that.metadata = IPA.get_entity_param(that.entity.name, that.name);
         }
-        if (that.param_info) {
+        if (that.metadata) {
             if (that.label === undefined) {
-                that.label = that.param_info.label;
+                that.label = that.metadata.label;
             }
             if (that.tooltip === undefined) {
-                that.tooltip = that.param_info.doc;
+                that.tooltip = that.metadata.doc;
             }
         }
-    }
+    };
 
-
-    function meta_validate(meta, value){
-        var message;
-
-        if (meta.type == 'int') {
-            if (!value.match(/^-?\d+$/)) {
-                that.valid = false;
-                that.show_error(IPA.messages.widget.validation.integer);
-                return that.valid;
-            }
-
-            if (meta.minvalue !== undefined && value < meta.minvalue) {
-                that.valid = false;
-                message = IPA.messages.widget.validation.min_value;
-                message = message.replace('${value}', meta.minvalue);
-                that.show_error(message);
-                return that.valid;
-            }
-
-            if (meta.maxvalue !== undefined && value > meta.maxvalue) {
-                that.valid = false;
-                message = IPA.messages.widget.validation.max_value;
-                message = message.replace('${value}', meta.maxvalue);
-                that.show_error(message);
-                return that.valid;
-            }
-        }
-        if (meta.pattern) {
-            var regex = new RegExp(meta.pattern);
-            if (!value.match(regex)) {
-                that.valid = false;
-                that.show_error(meta.pattern_errmsg);
-                return that.valid;
-            }
-        }
-
-        return that.valid;
-    }
-
-    that.create_error_link = function(container){
+    that.create_error_link = function(container) {
         container.append(' ');
 
         $('<span/>', {
@@ -145,7 +103,7 @@ IPA.widget = function(spec) {
         if (!that.writable) return false;
 
         if (that.required !== undefined) return that.required;
-        return that.param_info && that.param_info.required;
+        return that.metadata && that.metadata.required;
     };
 
     that.set_required = function(required) {
@@ -191,12 +149,43 @@ IPA.widget = function(spec) {
             return that.valid;
         }
 
-        if (that.metadata) {
-            meta_validate(that.metadata, value);
+        if (!that.metadata) {
+            return that.valid;
         }
 
-        if (that.valid && that.param_info) {
-            meta_validate(that.param_info, value);
+        var message;
+
+        if (that.metadata.type == 'int') {
+            if (!value.match(/^-?\d+$/)) {
+                that.valid = false;
+                that.show_error(IPA.messages.widget.validation.integer);
+                return that.valid;
+            }
+
+            if (that.metadata.minvalue !== undefined && value < that.metadata.minvalue) {
+                that.valid = false;
+                message = IPA.messages.widget.validation.min_value;
+                message = message.replace('${value}', that.metadata.minvalue);
+                that.show_error(message);
+                return that.valid;
+            }
+
+            if (that.metadata.maxvalue !== undefined && value > that.metadata.maxvalue) {
+                that.valid = false;
+                message = IPA.messages.widget.validation.max_value;
+                message = message.replace('${value}', that.metadata.maxvalue);
+                that.show_error(message);
+                return that.valid;
+            }
+        }
+
+        if (that.metadata.pattern) {
+            var regex = new RegExp(that.metadata.pattern);
+            if (!value.match(regex)) {
+                that.valid = false;
+                that.show_error(that.metadata.pattern_errmsg);
+                return that.valid;
+            }
         }
 
         return that.valid;
@@ -271,12 +260,12 @@ IPA.widget = function(spec) {
 
         that.writable = true;
 
-        if (that.param_info) {
-            if (that.param_info.primary_key) {
+        if (that.metadata) {
+            if (that.metadata.primary_key) {
                 that.writable = false;
             }
 
-            if (that.param_info.flags && 'no_update' in that.param_info.flags) {
+            if (that.metadata.flags && 'no_update' in that.metadata.flags) {
                 that.writable = false;
             }
         }
@@ -396,9 +385,7 @@ IPA.widget = function(spec) {
     that.refresh = function() {
     };
 
-
-    /*widget initialization*/
-    set_param_info();
+    init();
 
     // methods that should be invoked by subclasses
     that.widget_create = that.create;
@@ -1237,9 +1224,9 @@ IPA.column = function (spec) {
 
     /*column initialization*/
     if (that.entity_name && !that.label) {
-        var param_info = IPA.get_entity_param(that.entity_name, that.name);
-        if (param_info) {
-            that.label = param_info.label;
+        var metadata = IPA.get_entity_param(that.entity_name, that.name);
+        if (metadata) {
+            that.label = metadata.label;
         }
     }
 
-- 
1.7.5.1

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

Reply via email to