1
- function handleRadioButtonClicked ( ) {
2
- selectApplicableTextBox ( $ ( this ) ) ;
3
- clearOtherTextBoxes ( $ ( this ) ) ;
4
- }
5
1
6
- function selectApplicableTextBox ( selectedRadioButton ) {
7
- selectedRadioButton . closest ( '.input-group' ) . find ( 'input[type="text"]' ) . first ( ) . focus ( ) ;
2
+ function setTextboxVisibility ( selectBox , cssSelector , visibility ) {
3
+ var textbox = selectBox . closest ( '.selector' ) . find ( cssSelector ) ;
4
+ textbox . toggle ( visibility ) ;
5
+ if ( visibility ) {
6
+ textbox . prop ( 'disabled' , '' ) ;
7
+ textbox . focus ( ) ;
8
+ } else {
9
+ textbox . prop ( 'disabled' , 'disabled' ) ;
10
+ }
8
11
}
9
12
10
- function handleTextBoxClicked ( ) {
11
- selectApplicableRadioButton ( $ ( this ) ) ;
12
- clearOtherTextBoxes ( $ ( this ) ) ;
13
+ function toggleLatestFlag ( selectBox , enabled ) {
14
+ var flagElement = selectBox . closest ( '.selector' ) . find ( '.latest-flag' ) ;
15
+ if ( enabled ) {
16
+ flagElement . prop ( 'disabled' , '' ) ;
17
+ } else {
18
+ flagElement . prop ( 'disabled' , 'disabled' ) ;
19
+ }
13
20
}
14
21
15
- function selectApplicableRadioButton ( selectedTextBox ) {
16
- selectedTextBox . closest ( '.input-group' ) . find ( '.version-selectorizor' ) . prop ( 'checked' , 'checked' ) ;
22
+ function showApplicableTextBoxes ( selectorizor ) {
23
+ var selectorizorType = selectorizor . val ( ) ;
24
+ if ( selectorizorType === 'specify-version' ) {
25
+ setTextboxVisibility ( selectorizor , '.version' , true ) ;
26
+ setTextboxVisibility ( selectorizor , '.tag' , false ) ;
27
+ }
28
+ else if ( selectorizorType === 'specify-latest-tag' || selectorizorType === 'specify-all-tagged' ) {
29
+ setTextboxVisibility ( selectorizor , '.version' , false ) ;
30
+ setTextboxVisibility ( selectorizor , '.tag' , true ) ;
31
+ }
32
+ else if ( selectorizorType === 'specify-all-versions' || selectorizorType === 'specify-latest' ) {
33
+ setTextboxVisibility ( selectorizor , '.version' , false ) ;
34
+ setTextboxVisibility ( selectorizor , '.tag' , false ) ;
35
+ }
36
+
37
+ if ( selectorizorType === 'specify-latest' || selectorizorType === 'specify-latest-tag' ) {
38
+ toggleLatestFlag ( selectorizor , true ) ;
39
+ } else {
40
+ toggleLatestFlag ( selectorizor , false ) ;
41
+ }
17
42
}
18
43
19
- function clearOtherTextBoxes ( clickedElement ) {
20
- clickedElement . closest ( '.selector' ) . find ( 'input[type="text"]' ) . each ( function ( ) {
21
- if ( ! $ . contains ( clickedElement . closest ( '.input-group' ) [ 0 ] , $ ( this ) [ 0 ] ) ) {
22
- $ ( this ) . prop ( 'value' , '' ) ;
23
- }
24
- } ) ;
44
+ function handleSelectorizorChanged ( ) {
45
+ showApplicableTextBoxes ( $ ( this ) ) ;
25
46
}
26
47
27
48
function onSubmit ( ) {
@@ -30,26 +51,12 @@ function onSubmit() {
30
51
}
31
52
32
53
function disableFieldsThatShouldNotBeSubmitted ( ) {
33
- disableInputsForUncheckedRadioButtons ( ) ;
34
- disableRadioButtons ( ) ;
35
- }
36
-
37
- function disableInputsForUncheckedRadioButtons ( ) {
38
- $ ( '.version-selectorizor' ) . each ( function ( ) {
39
- if ( $ ( this ) . prop ( 'checked' ) === false ) {
40
- $ ( this ) . closest ( '.input-group' ) . find ( 'input' ) . prop ( 'disabled' , 'disabled' ) ;
41
- }
42
- } ) ;
43
- }
44
-
45
- function disableRadioButtons ( ) {
46
54
$ ( '.version-selectorizor' ) . prop ( 'disabled' , 'disabled' ) ;
47
55
}
48
56
49
57
$ ( document ) . ready ( function ( ) {
50
- $ ( '.by-version' ) . click ( handleTextBoxClicked ) ;
51
- $ ( '.by-latest-tag' ) . click ( handleTextBoxClicked ) ;
52
- $ ( '.version-selectorizor' ) . click ( handleRadioButtonClicked ) ;
58
+ $ ( '.version-selectorizor' ) . change ( handleSelectorizorChanged ) ;
59
+ $ ( '.version-selectorizor' ) . each ( function ( ) { showApplicableTextBoxes ( $ ( this ) ) ; } ) ;
53
60
54
61
$ ( "#matrix" ) . tablesorter ( {
55
62
textExtraction : function ( node , table , cellIndex ) {
0 commit comments