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