validations.js
3.63 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
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 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 validate_new_repository() {
if (allRequiredFieldsAreFilled()) {
return addressAndTypeMatch();
}
return false;
}
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 matchBazaar(address) {
if (address.match(/bzr/)) {
return true;
}
alert("Address does not match type BAZAAR chosen.");
return false;
}
function matchCVS(address) {
if (address.match(/cvs/)) {
return true;
}
alert("Address does not match type CVS chosen.");
return false;
}
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("Address does not match type GIT chosen.");
return false;
}
function matchMercurial(address) {
if (address.match(/^(http(s)?|ssh):\/\/.*hg/)) {
return true;
}
alert("Address does not match type MERCURIAL chosen.");
return false;
}
function matchRemoteTarball(address) {
if (address.match(/\.tar(\..+)*$/)) {
return true;
}
alert("Address does not match type REMOTE_TARBALL chosen.");
return false;
}
function matchRemoteZIP(address) {
if (address.match(/\.zip$/)) {
return true;
}
alert("Address does not match type REMOTE_ZIP chosen.");
return false;
}
function matchSubversion(address) {
if (address.match(/^http(s)?:\/\/.+\/svn.+$/)) {
return true;
}
alert("Address 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;
}