Check field's validity before executing add.

This commit is contained in:
Endi S. Dewata 2011-01-23 07:41:10 +07:00 committed by Adam Young
parent 5ca58d58b3
commit add7d701c6
5 changed files with 22 additions and 18 deletions

View File

@ -101,6 +101,7 @@ IPA.add_dialog = function (spec) {
for (var i=0; i<that.fields.length; i++) {
var field = that.fields[i];
if (!field.valid) return;
var value = record[field.name];
if (!value) continue;

View File

@ -536,9 +536,9 @@ function certificate_status_widget(spec) {
that.widget_setup(container);
that.valid = $('div[name=certificate-valid]', that.container);
that.revoked = $('div[name=certificate-revoked]', that.container);
that.missing = $('div[name=certificate-missing]', that.container);
that.status_valid = $('div[name=certificate-valid]', that.container);
that.status_revoked = $('div[name=certificate-revoked]', that.container);
that.status_missing = $('div[name=certificate-missing]', that.container);
var button = $('input[name=get]', that.container);
that.get_button = IPA.button({
@ -620,11 +620,11 @@ function certificate_status_widget(spec) {
};
function set_status(status, revocation_reason) {
that.valid.css('display', status == CERTIFICATE_STATUS_VALID ? 'inline' : 'none');
that.missing.css('display', status == CERTIFICATE_STATUS_MISSING ? 'inline' : 'none');
that.status_valid.css('display', status == CERTIFICATE_STATUS_VALID ? 'inline' : 'none');
that.status_missing.css('display', status == CERTIFICATE_STATUS_MISSING ? 'inline' : 'none');
if (!that.is_selfsign()) {
that.revoked.css('display', status == CERTIFICATE_STATUS_REVOKED ? 'inline' : 'none');
that.status_revoked.css('display', status == CERTIFICATE_STATUS_REVOKED ? 'inline' : 'none');
that.revoke_button.css('visibility', status == CERTIFICATE_STATUS_VALID ? 'visible' : 'hidden');
that.revocation_reason.html(revocation_reason == undefined ? '' : CRL_REASON[revocation_reason]);
that.restore_button.css('visibility', revocation_reason == 6 ? 'visible' : 'hidden');

View File

@ -299,8 +299,8 @@ function host_provisioning_status_widget(spec) {
that.widget_setup(container);
that.valid = $('div[name=kerberos-key-valid]', that.container);
that.missing = $('div[name=kerberos-key-missing]', that.container);
that.status_valid = $('div[name=kerberos-key-valid]', that.container);
that.status_missing = $('div[name=kerberos-key-missing]', that.container);
var button = $('input[name=unprovision]', that.container);
that.unprovision_button = IPA.button({
@ -397,8 +397,8 @@ function host_provisioning_status_widget(spec) {
};
function set_status(status) {
that.valid.css('display', status == 'valid' ? 'inline' : 'none');
that.missing.css('display', status == 'missing' ? 'inline' : 'none');
that.status_valid.css('display', status == 'valid' ? 'inline' : 'none');
that.status_missing.css('display', status == 'missing' ? 'inline' : 'none');
}
return that;

View File

@ -355,8 +355,8 @@ function service_provisioning_status_widget(spec) {
that.widget_setup(container);
that.valid = $('div[name=kerberos-key-valid]', that.container);
that.missing = $('div[name=kerberos-key-missing]', that.container);
that.status_valid = $('div[name=kerberos-key-valid]', that.container);
that.status_missing = $('div[name=kerberos-key-missing]', that.container);
var button = $('input[name=unprovision]', that.container);
that.unprovision_button = IPA.button({
@ -405,8 +405,8 @@ function service_provisioning_status_widget(spec) {
};
function set_status(status) {
that.valid.css('display', status == 'valid' ? 'inline' : 'none');
that.missing.css('display', status == 'missing' ? 'inline' : 'none');
that.status_valid.css('display', status == 'valid' ? 'inline' : 'none');
that.status_missing.css('display', status == 'missing' ? 'inline' : 'none');
}
return that;

View File

@ -46,6 +46,7 @@ IPA.widget = function(spec) {
that.save = spec.save || save;
that.update = spec.update || update;
that.validate_input = spec.validate_input || validate_input;
that.valid = true;
that.param_info = spec.param_info;
that.__defineGetter__("entity_name", function(){
@ -61,23 +62,25 @@ IPA.widget = function(spec) {
displays the error message and returns false. */
function validate_input(text) {
if (!(that.param_info && that.param_info.pattern)) {
return true;
that.valid = true;
return;
}
var error_link = that.get_error_link();
if (!error_link) {
return true;
that.valid = true;
return;
}
var regex = new RegExp( that.param_info.pattern );
//If the field is empty, don't validate
if ( !text || text.match(regex) ) {
error_link.css('display', 'none');
return true;
that.valid = true;
}else{
error_link.css('display', 'block');
if (that.param_info.pattern_errmsg) {
error_link.html(that.param_info.pattern_errmsg);
}
return false;
that.valid = false;
}
}