Validation of details facet before update
https://fedorahosted.org/freeipa/ticket/1676 The ticket is a duplicate of server error, but it revealed few UI errors.

Newly performs validation of details facet before update. If validation fails, notification dialog is shown and command isn't executed.
Fixed integer minimum and maximum value checking.
Read-only and non-writeable fields are no longer considered required.
--
Petr Vobornik
From 8ccfd1ac82eaa2cb322a23166be54836f907c644 Mon Sep 17 00:00:00 2001
From: Petr Vobornik <pvobo...@redhat.com>
Date: Wed, 24 Aug 2011 15:36:48 +0200
Subject: [PATCH] Validation of details facet before update
 https://fedorahosted.org/freeipa/ticket/1676 The ticket is
 a duplicate of server error, but it revealed few UI errors.

Newly performs validation of details facet before update. If validation fails, notification dialog is shown and command isn't executed.
Fixed integer minimum and maximum value checking.
Read-only and non-writable fields are no longer considered required.
---
 install/ui/details.js              |   31 +++++++++++++++++++++++++++++--
 install/ui/test/data/ipa_init.json |    4 +++-
 install/ui/widget.js               |   12 +++++++-----
 ipalib/plugins/internal.py         |    6 ++++--
 4 files changed, 43 insertions(+), 10 deletions(-)

diff --git a/install/ui/details.js b/install/ui/details.js
index 564d848d491083ca896eb295129e65b07b64010e..4550c1abfb9d408d332b858638ad28a9811cb0e9 100644
--- a/install/ui/details.js
+++ b/install/ui/details.js
@@ -128,6 +128,18 @@ IPA.details_section = function(spec) {
         return false;
     };
 
+    that.is_valid = function() {
+        var fields = that.fields.values;
+        var valid = true;
+        for (var i=0; i<fields.length; i++) {
+            var field = fields[i];
+            if (!field.valid || !field.check_required()) {
+                valid = false;
+            }
+        }
+        return valid;
+    };
+
     // methods that should be invoked by subclasses
     that.section_create = that.create;
     that.section_setup = that.setup;
@@ -458,12 +470,12 @@ IPA.details_facet = function(spec) {
                 on_win(data, text_status, xhr);
             if (data.error)
                 return;
-            
+
             if (that.post_update_hook) {
                 that.post_update_hook(data, text_status);
                 return;
             }
-            
+
             var result = data.result.result;
             that.load(result);
         }
@@ -488,11 +500,17 @@ IPA.details_facet = function(spec) {
         });
 
         var values;
+        var valid = true;
 
         var sections = that.sections.values;
         for (var i=0; i<sections.length; i++) {
             var section = sections[i];
 
+            if(!section.is_valid() || !valid) {
+                valid = false;
+                continue;
+            }
+
             if (section.save) {
                 section.save(command.options);
                 continue;
@@ -528,6 +546,15 @@ IPA.details_facet = function(spec) {
             }
         }
 
+        if(!valid) {
+            var dialog = IPA.message_dialog({
+                title: IPA.messages.dialogs.validation_title,
+                message: IPA.messages.dialogs.validation_message
+            });
+            dialog.open();
+            return;
+        }
+
         //alert(JSON.stringify(command.to_json()));
 
         if (that.pre_execute_hook){
diff --git a/install/ui/test/data/ipa_init.json b/install/ui/test/data/ipa_init.json
index 0738df061b50e07847164dd3d049e8615b95f184..9f31a72680852a4586d9637834c04ffbee038b25 100644
--- a/install/ui/test/data/ipa_init.json
+++ b/install/ui/test/data/ipa_init.json
@@ -15907,7 +15907,9 @@
                         "prospective": "Prospective",
                         "remove_empty": "Select entries to be removed.",
                         "remove_title": "Remove ${entity}",
-                        "show_details": "Show details"
+                        "show_details": "Show details",
+                        "validation_title": "Validation error",
+                        "validation_message": "Input form contains invalid or missing values."
                     },
                     "facet_groups": {
                         "managedby": "${primary_key} is managed by:",
diff --git a/install/ui/widget.js b/install/ui/widget.js
index f88bba5c2ae2991c0a2d06d571e6b1c9ebc03ab2..6ae6f5dfbb549eab24738740625b25c9055e461c 100644
--- a/install/ui/widget.js
+++ b/install/ui/widget.js
@@ -89,7 +89,7 @@ IPA.widget = function(spec) {
                 return;
             }
 
-            if (meta.minvalue && value < meta.minvalue) {
+            if (meta.minvalue !== undefined && value < meta.minvalue) {
                 that.valid = false;
                 message = IPA.messages.widget.validation.min_value;
                 message = message.replace('${value}', meta.minvalue);
@@ -97,7 +97,7 @@ IPA.widget = function(spec) {
                 return;
             }
 
-            if (meta.maxvalue && value > meta.maxvalue) {
+            if (meta.maxvalue !== undefined && value > meta.maxvalue) {
                 that.valid = false;
                 message = IPA.messages.widget.validation.max_value;
                 message = message.replace('${value}', meta.maxvalue);
@@ -131,7 +131,9 @@ IPA.widget = function(spec) {
         if (!values || !values.length || values[0] === '' ) {
             if (that.param_info &&
                 that.param_info.required &&
-                !that.optional) {
+                !that.optional &&
+                !that.read_only &&
+                that.writable) {
                 that.valid = false;
                 that.show_error(IPA.messages.widget.validation.required);
                 return false;
@@ -148,10 +150,10 @@ IPA.widget = function(spec) {
         that.valid = true;
 
         var values = that.save();
-        if (!values){
+        if (!values) {
             return;
         }
-        if (values.length ===0 ){
+        if (values.length === 0) {
             return;
         }
         var value = values[0];
diff --git a/ipalib/plugins/internal.py b/ipalib/plugins/internal.py
index 785dc1680c2d02446e946fc3410deaaff7edc2cb..0964d106ce295c91881fd71666a977c115bf34bc 100644
--- a/ipalib/plugins/internal.py
+++ b/ipalib/plugins/internal.py
@@ -355,12 +355,14 @@ class i18n_messages(Command):
             "confirmation":_("Confirmation"),
             "dirty_message":_("This page has unsaved changes. Please save or revert."),
             "dirty_title":_("Unsaved Changes"),
-            "hide_details":_("Hide details"),\
+            "hide_details":_("Hide details"),
             "redirection":_("Redirection"),
             "remove_empty":_("Select entries to be removed."),
             "remove_title":_("Remove ${entity}"),
             "prospective":_("Prospective"),
-            "show_details":_("Show details"),\
+            "show_details":_("Show details"),
+            "validation_title":_("Validation error"),
+            "validation_message":_("Input form contains invalid or missing values."),
             },
         "facet_groups": {
             "managedby":_("${primary_key} is managed by:"),
-- 
1.7.6

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

Reply via email to