mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
Refactored validation code.
The validation code in details facet, dialog, and sections have been modified to work more consistently.
This commit is contained in:
parent
725e2e4624
commit
7142cee430
@ -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) {
|
||||
|
@ -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
|
||||
});
|
||||
|
||||
if (!that.validate()) {
|
||||
var dialog = IPA.message_dialog({
|
||||
title: IPA.messages.dialogs.validation_title,
|
||||
message: IPA.messages.dialogs.validation_message
|
||||
});
|
||||
dialog.open();
|
||||
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];
|
||||
@ -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){
|
||||
|
@ -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) {
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -311,6 +311,8 @@ IPA.user_password_widget = function(spec) {
|
||||
|
||||
that.create = function(container) {
|
||||
|
||||
that.widget_create(container);
|
||||
|
||||
$('<a/>', {
|
||||
href: 'jslink',
|
||||
title: 'userpassword',
|
||||
|
@ -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()) {
|
||||
|
Loading…
Reference in New Issue
Block a user