summaryrefslogtreecommitdiffstats
path: root/install/ui/details.js
diff options
context:
space:
mode:
authorEndi S. Dewata <edewata@redhat.com>2011-10-25 18:41:45 -0500
committerEndi S. Dewata <edewata@redhat.com>2011-10-27 13:48:51 +0000
commit7142cee430a194cca1208ce4ebcd70ee892af1b9 (patch)
treeb5850c550433b1105bb9fefcb46bb1d9011c8c6a /install/ui/details.js
parent725e2e46248ee9ab3dae9a523fcd6fda0bd0cff3 (diff)
downloadfreeipa-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/details.js')
-rw-r--r--install/ui/details.js50
1 files changed, 23 insertions, 27 deletions
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){