forked from MatmaRex/patchdemo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
96 lines (82 loc) · 2.76 KB
/
index.js
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
/* global OO, $ */
( function () {
var myWikis, closedWikis, branchSelect, form, submit, showClosed,
presetInput, reposField, reposInput, reposFieldLabel,
$wikisTable = $( '.wikis' );
function updateTableClasses() {
$wikisTable.toggleClass( 'hideOthers', !!myWikis.isSelected() );
$wikisTable.toggleClass( 'hideOpen', !!closedWikis.isSelected() );
}
form = document.getElementById( 'new-form' );
if ( form ) {
submit = OO.ui.infuse( $( '.form-submit' ) );
form.addEventListener( 'submit', function () {
submit.setDisabled( true );
return false;
} );
if ( $( '.myWikis' ).length ) {
myWikis = OO.ui.infuse( $( '.myWikis' ) );
myWikis.on( 'change', updateTableClasses );
closedWikis = OO.ui.infuse( $( '.closedWikis' ) );
closedWikis.on( 'change', updateTableClasses );
if ( $( '.showClosed' ).length ) {
showClosed = OO.ui.infuse( $( '.showClosed' ) );
showClosed.on( 'click', function () {
myWikis.setSelected( true );
closedWikis.setSelected( true );
updateTableClasses();
} );
}
}
branchSelect = OO.ui.infuse( $( '.form-branch' ) );
branchSelect.on( 'change', function () {
var branch, repo, validBranch;
branch = branchSelect.value;
for ( repo in window.repoBranches ) {
validBranch = window.repoBranches[ repo ].indexOf( branch ) !== -1;
reposInput.checkboxMultiselectWidget
.findItemFromData( repo )
.setDisabled( !validBranch || repo === 'mediawiki/core' );
}
reposInput.emit( 'change' );
} );
presetInput = OO.ui.infuse( $( '.form-preset' ) );
reposInput = OO.ui.infuse( $( '.form-repos' ) );
reposField = OO.ui.infuse( $( '.form-repos-field' ) );
reposFieldLabel = reposField.getLabel();
presetInput.on( 'change', OO.ui.debounce( function () {
var val = presetInput.getValue();
if ( val === 'custom' ) {
reposField.$body[ 0 ].open = true;
}
if ( val !== 'custom' ) {
reposInput.setValue( window.presets[ val ] );
}
} ) );
reposInput.on( 'change', OO.ui.debounce( function () {
var selected = 0, enabled = 0,
val, presetName, matchingPresetName;
val = reposInput.getValue();
matchingPresetName = 'custom';
for ( presetName in window.presets ) {
if ( window.presets[ presetName ].sort().join( '|' ) === val.sort().join( '|' ) ) {
matchingPresetName = presetName;
break;
}
}
if ( presetInput.getValue() !== matchingPresetName ) {
presetInput.setValue( matchingPresetName );
}
reposInput.checkboxMultiselectWidget.items.forEach( function ( option ) {
if ( !option.isDisabled() ) {
enabled++;
if ( option.isSelected() ) {
selected++;
}
}
} );
reposField.setLabel( reposFieldLabel + ' (' + selected + '/' + enabled + ')' );
} ) );
reposInput.emit( 'change' );
}
}() );