validations.js
2.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
jQuery(function (){
jQuery('#range_submit').live("click", validate_new_range_configuration);
jQuery('#metric_configuration_submit').live("click", validate_metric_configuration);
jQuery('#repository_submit').live("click", validate_new_repository);
});
function validate_code(code){
return true;
}
function validate_new_repository() {
if (allRequiredFieldsAreFilled()))
return addressAndTypeMatch();
return false;
}
function allRequiredFieldsAreFilled() {
var name = jQuery('#repository_name').val();
var address = jQuery('#repository_address').val();
if (is_null(name) || is_null(address)) {
alert("Please fill all fields marked with (*).");
return false;
}
return true;
}
function addressAndTypeMatch() {
var type = jQuery('#repository_type').val();
var address = jQuery('#repository_address').val();
switch (type) {
case "BAZAAR": return matchBAZAAR(address);
case "CVS": return matchCVS(address);
case "GIT": return matchGIT(address);
case "MERCURIAL": return matchMercurial(address);
case "REMOTE_TARBALL": return matchRemoteTarball(address);
case "REMOTE_ZIP": return matchRemoteZIP(address);
case "SUBVERSION": return matchSubversion(address);
}
}
function matchGIT(address) {
if (address.match(/^[ http(s)?:\/\/git(hub)?\. | git:\/\/git(hub.com | orious.org)\/ | git@git(hub.com | orious.org):].+.git$/))
return true;
alert("Adress does not match type GIT chosen.");
return false;
}
function matchSubversion(address) {
if (address.match(/^http(s)?:\/\/.+\/svn.+$/))
return true;
alert("Adress does not match type Subversion chosen.");
return false;
}
function validate_metric_configuration() {
var code = jQuery('#metric_configuration_code').val();
if (is_null(code)) {
alert("Code must be filled out");
return false;
}
return true;
}
function is_null(value) {
if (value == "" || value == null) {
return true;
}
return false;
}
function IsNotNumeric(value) {
if (value.match(/[0-9]*\.?[0-9]+/)) {
return false;
}
return true;
}
function IsNotInfinite(value) {
if (value.match(/INF/)) {
return false;
}
return true;
}
function validate_new_range_configuration(event) {
var beginning = jQuery("#range_beginning").val();
var end = jQuery("#range_end").val();
if (is_null(beginning) || is_null(end)) {
alert("Please fill all fields marked with (*).");
return false;
}
if ( (IsNotNumeric(beginning) && IsNotInfinite(beginning)) || (IsNotNumeric(end) && IsNotInfinite(end))) {
alert("Beginning, End and Grade must be numeric values.");
return false;
}
if (parseInt(beginning) > parseInt(end)) {
if (IsNotInfinite(beginning) && IsNotInfinite(end)) {
alert("End must be greater than Beginning.");
return false;
}
}
return true;
}