summaryrefslogtreecommitdiff
blob: 76783576559b108a0274ffb8306d7515ace475b0 (plain)
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
module.exports = function addBlockForm() {
	// Attributes used for pinnable highlighting
	var blockButton = OO.ui.infuse( $( '.ext-checkuser-investigate-subtitle-block-button' ) ),
		$placeholderWidget = $( '.ext-checkuser-investigate-subtitle-placeholder-widget' ),
		targets = mw.config.get( 'wgCheckUserInvestigateTargets' ),
		excludeTargets = mw.config.get( 'wgCheckUserInvestigateExcludeTargets' ),
		targetsWidget = new OO.ui.MenuTagMultiselectWidget( {
			options: excludeTargets.map( function ( target ) {
				return {
					data: target,
					label: target
				};
			} ),
			selected: targets.filter( function ( target ) {
				return excludeTargets.indexOf( target ) === -1;
			} )
		} ),
		continueButton = new OO.ui.ButtonWidget( {
			label: mw.msg( 'checkuser-investigate-subtitle-continue-button-label' ),
			flags: [ 'primary', 'progressive' ],
			classes: [
				'ext-checkuser-investigate-subtitle-continue-button'
			]
		} ),
		cancelButton = new OO.ui.ButtonWidget( {
			label: mw.msg( 'checkuser-investigate-subtitle-cancel-button-label' ),
			flags: [ 'progressive' ],
			framed: false,
			classes: [
				'ext-checkuser-investigate-subtitle-cancel-button'
			]
		} );

	function toggleBlockFromButtons( showBlockForm ) {
		blockButton.toggle( !showBlockForm );
		continueButton.toggle( showBlockForm );
		cancelButton.toggle( showBlockForm );
		targetsWidget.toggle( showBlockForm );
	}

	$placeholderWidget.replaceWith( targetsWidget.$element );
	blockButton.$element.parent().prepend(
		continueButton.$element,
		cancelButton.$element
	);

	toggleBlockFromButtons( false );
	blockButton.on( 'click', toggleBlockFromButtons.bind( null, true ) );
	cancelButton.on( 'click', toggleBlockFromButtons.bind( null, false ) );

	continueButton.on( 'click', function () {
		var $form, params, key;

		$form = $( '<form>' ).attr( {
			action: new mw.Title( 'Special:InvestigateBlock' ).getUrl(),
			method: 'post',
			target: '_blank'
		} ).addClass( 'oo-ui-element-hidden' );

		params = {
			wpTargets: targetsWidget.getValue().join( '\n' ),
			allowedTargets: targets
		};
		for ( key in params ) {
			$form.append( $( '<input>' ).attr( {
				type: 'hidden',
				name: key,
				value: params[ key ]
			} ) );
		}

		$form.appendTo( 'body' ).trigger( 'submit' );
	} );
};