Skip to content

Commit

Permalink
Simplify if statements.
Browse files Browse the repository at this point in the history
Signed-off-by: Hugues Peccatte <hugues.peccatte@gmail.com>
  • Loading branch information
Tithugues committed Jul 21, 2015
1 parent 71aea4c commit 527b64e
Showing 1 changed file with 13 additions and 29 deletions.
42 changes: 13 additions & 29 deletions js/tbl_change.js
Expand Up @@ -341,38 +341,28 @@ AJAX.registerOnload('tbl_change.js', function () {
// validate the comment form when it is submitted
$("#insertForm").validate();
jQuery.validator.addMethod("validationFunctionForHex", function(value, element) {
if (value.match(/^[a-f0-9]*$/i) === null) {
return false;
} else {
return true;
}
return value.match(/^[a-f0-9]*$/i) !== null;
});

jQuery.validator.addMethod("validationFunctionForFuns", function(value, element, options) {
if (value.substring(0, 3) === "AES" && options.data('type') !== 'HEX') {
return false;
} else if (value.substring(0, 3) === "MD5"
&& typeof options.data('maxlength') !== 'undefined'
&& options.data('maxlength') < 32) {
return false;
} else {
return true;
}

return !(value.substring(0, 3) === "MD5"
&& typeof options.data('maxlength') !== 'undefined'
&& options.data('maxlength') < 32);
});

jQuery.validator.addMethod("validationFunctionForDateTime", function(value, element, options) {
var dt_value = value;
var theType = options;
if (theType == "date") {
if (! isDate(dt_value)) {
return false;
}
return true;
return isDate(dt_value);

} else if (theType == "time") {
if (! isTime(dt_value)) {
return false;
}
return true;
return isTime(dt_value);

} else if (theType == "datetime" || theType == "timestamp") {
var tmstmp = false;
dt_value = dt_value.trim();
Expand All @@ -387,17 +377,11 @@ AJAX.registerOnload('tbl_change.js', function () {
}
var dv = dt_value.indexOf(" ");
if (dv == -1) { // Only the date component, which is valid
if (! isDate(dt_value, tmstmp)) {
return false;
}
return true;
} else {
if (! (isDate(dt_value.substring(0, dv), tmstmp)
&& isTime(dt_value.substring(dv + 1)))) {
return false;
}
return true;
return isDate(dt_value, tmstmp);
}

return isDate(dt_value.substring(0, dv), tmstmp)
&& isTime(dt_value.substring(dv + 1));
}
});
/*
Expand Down

0 comments on commit 527b64e

Please sign in to comment.