diff options
author | Endi S. Dewata <edewata@redhat.com> | 2011-10-25 18:41:45 -0500 |
---|---|---|
committer | Endi S. Dewata <edewata@redhat.com> | 2011-10-27 13:48:51 +0000 |
commit | 7142cee430a194cca1208ce4ebcd70ee892af1b9 (patch) | |
tree | b5850c550433b1105bb9fefcb46bb1d9011c8c6a /install/ui | |
parent | 725e2e46248ee9ab3dae9a523fcd6fda0bd0cff3 (diff) | |
download | freeipa-7142cee430a194cca1208ce4ebcd70ee892af1b9.tar.gz freeipa-7142cee430a194cca1208ce4ebcd70ee892af1b9.tar.xz freeipa-7142cee430a194cca1208ce4ebcd70ee892af1b9.zip |
Refactored validation code.
The validation code in details facet, dialog, and sections have
been modified to work more consistently.
Diffstat (limited to 'install/ui')
-rw-r--r-- | install/ui/add.js | 18 | ||||
-rw-r--r-- | install/ui/details.js | 50 | ||||
-rw-r--r-- | install/ui/dialog.js | 13 | ||||
-rw-r--r-- | install/ui/entitle.js | 2 | ||||
-rw-r--r-- | install/ui/user.js | 2 | ||||
-rw-r--r-- | install/ui/widget.js | 2 |
6 files changed, 37 insertions, 50 deletions
diff --git a/install/ui/add.js b/install/ui/add.js index 65b7711e2..621861fd6 100644 --- a/install/ui/add.js +++ b/install/ui/add.js @@ -124,25 +124,15 @@ IPA.entity_adder_dialog = function(spec) { command.add_args(that.entity.get_primary_key_prefix()); + if (!that.validate()) return; + var record = {}; that.save(record); - var fields = that.get_fields(); - for (var i=0; i<fields.length; i++) { - fields[i].validate(); - } - - var valid = true; - var sections = that.sections.values; - for (i=0; i<sections.length; i++) { + for (var i=0; i<sections.length; i++) { var section = sections[i]; - if (!section.is_valid() || !valid) { - valid = false; - continue; - } - var section_fields = section.fields.values; for (var j=0; j<section_fields.length; j++) { var field = section_fields[j]; @@ -162,8 +152,6 @@ IPA.entity_adder_dialog = function(spec) { } } - if (!valid) return; - //alert(JSON.stringify(command.to_json())); if (that.pre_execute_hook) { diff --git a/install/ui/details.js b/install/ui/details.js index e24234861..022b005bc 100644 --- a/install/ui/details.js +++ b/install/ui/details.js @@ -181,14 +181,12 @@ IPA.details_section = function(spec) { return false; }; - that.is_valid = function() { - var fields = that.fields.values; + that.validate = function() { var valid = true; + var fields = that.fields.values; for (var i=0; i<fields.length; i++) { var field = fields[i]; - if (!field.valid || !field.check_required()) { - valid = false; - } + valid &= field.validate() && field.validate_required(); } return valid; }; @@ -584,6 +582,16 @@ IPA.details_facet = function(spec) { that.enable_update(false); }; + that.validate = function() { + var valid = true; + var sections = that.sections.values; + for (var i=0; i<sections.length; i++) { + var section = sections[i]; + valid &= section.validate(); + } + return valid; + }; + that.update = function(on_win, on_fail) { function on_success(data, text_status, xhr) { @@ -620,25 +628,22 @@ IPA.details_facet = function(spec) { on_error: on_error }); - var record = {}; - that.save(record); - - var fields = that.get_fields(); - for (var i=0; i<fields.length; i++) { - fields[i].validate(); + if (!that.validate()) { + var dialog = IPA.message_dialog({ + title: IPA.messages.dialogs.validation_title, + message: IPA.messages.dialogs.validation_message + }); + dialog.open(); + return; } - var valid = true; + var record = {}; + that.save(record); var sections = that.sections.values; - for (i=0; i<sections.length; i++) { + for (var i=0; i<sections.length; i++) { var section = sections[i]; - if (!section.is_valid() || !valid) { - valid = false; - continue; - } - var section_fields = section.fields.values; for (var j=0; j<section_fields.length; j++) { var field = section_fields[j]; @@ -670,15 +675,6 @@ 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/dialog.js b/install/ui/dialog.js index 41b35fb42..ff64b37cc 100644 --- a/install/ui/dialog.js +++ b/install/ui/dialog.js @@ -66,7 +66,6 @@ IPA.dialog = function(spec) { that.height = spec.height; that.buttons = $.ordered_map(); - that.sections = $.ordered_map(); var init = function() { @@ -129,12 +128,14 @@ IPA.dialog = function(spec) { return that; }; - that.is_valid = function() { - for (var i=0; i<that.sections.length; i++) { - var section = that.sections.values[i]; - if (!section.is_valid()) return false; + that.validate = function() { + var valid = true; + var sections = that.sections.values; + for (var i=0; i<sections.length; i++) { + var section = sections[i]; + valid &= section.validate(); } - return true; + return valid; }; that.add_section = function(section) { diff --git a/install/ui/entitle.js b/install/ui/entitle.js index a44318d04..dcaf5638f 100644 --- a/install/ui/entitle.js +++ b/install/ui/entitle.js @@ -642,7 +642,7 @@ IPA.entitle.consume_dialog = function(spec) { label: IPA.messages.objects.entitle.consume, click: function() { - if (!that.is_valid()) { + if (!that.validate()) { return; } diff --git a/install/ui/user.js b/install/ui/user.js index bfda51d84..3ff56cd9d 100644 --- a/install/ui/user.js +++ b/install/ui/user.js @@ -311,6 +311,8 @@ IPA.user_password_widget = function(spec) { that.create = function(container) { + that.widget_create(container); + $('<a/>', { href: 'jslink', title: 'userpassword', diff --git a/install/ui/widget.js b/install/ui/widget.js index 948e6fd52..7f2260c73 100644 --- a/install/ui/widget.js +++ b/install/ui/widget.js @@ -118,7 +118,7 @@ IPA.widget = function(spec) { } }; - that.check_required = function() { + that.validate_required = function() { var values = that.save(); if (!values || !values.length || values[0] === '') { if (that.is_required()) { |