summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/UploadWizard/resources/ui/steps/uw.ui.Tutorial.js
blob: e9df37b39bd8e82ce98de49b3462acf56150cfbd (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
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
/*
 * This file is part of the MediaWiki extension UploadWizard.
 *
 * UploadWizard is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.
 *
 * UploadWizard is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with UploadWizard.  If not, see <http://www.gnu.org/licenses/>.
 */

( function ( mw, $, uw, OO ) {
	/**
	 * Checkbox with popup information.
	 *
	 * @param {Object} config
	 */
	function PopupCheckboxInputWidget( config ) {
		// Parent constructor
		PopupCheckboxInputWidget.parent.call( this, config );

		// Mixin constructors
		OO.ui.mixin.PopupElement.call( this, config );

		// Events
		this.connect( this, { change: 'onChange' } );

		// Initialization
		this.$element
			.addClass( 'oo-ui-popupCheckboxInputWidget' )
			.attr( 'aria-haspopup', 'true' )
			.append( this.popup.$element );
	}
	OO.inheritClass( PopupCheckboxInputWidget, OO.ui.CheckboxInputWidget );
	OO.mixinClass( PopupCheckboxInputWidget, OO.ui.mixin.PopupElement );
	PopupCheckboxInputWidget.prototype.onChange = function () {
		this.popup.toggle( this.isSelected() );
	};

	/**
	 * Represents the UI for the wizard's Tutorial step.
	 *
	 * @class uw.ui.Tutorial
	 * @extends uw.ui.Step
	 * @constructor
	 */
	uw.ui.Tutorial = function UWUITutorial() {
		var ui = this;

		uw.ui.Step.call(
			this,
			'tutorial'
		);

		// 'Skip tutorial' checkbox
		this.skipCheckbox = new PopupCheckboxInputWidget( {
			id: 'mwe-upwiz-skip',
			// Add a friendly "Here's how to get it back" tooltip for users who check the "Skip next time" checkbox
			popup: {
				$content: $( '<p>' ).msg(
					'mwe-upwiz-tooltip-skiptutorial',
					mw.config.get( 'wgServer' ) + mw.util.getUrl( 'Special:Preferences' ) + '#mw-prefsection-uploads',
					mw.message( 'prefs-uploads' ).text(),
					mw.message( 'prefs-upwiz-interface' ).text()
				),
				autoClose: false,
				padded: true
			}
		} );
		this.skipCheckboxLabel = new OO.ui.LabelWidget( {
			input: this.skipCheckbox,
			label: mw.message( 'mwe-upwiz-skip-tutorial-future' ).text()
		} );

		this.skipCheckbox.on( 'change', function () {
			ui.emit( 'skip-tutorial-click', ui.skipCheckbox.isSelected() );
		} );

		// grab the tutorial HTML that was injected into this document
		this.tutorialHtml = $( '#mwe-upwiz-tutorial-html' );

		// Helpdesk link click
		$( '#mwe-upwiz-tutorial-helpdesk' ).click( function () {
			ui.emit( 'helpdesk-click' );
		} );

		this.addPreviousButton();
		this.addNextButton();
	};

	OO.inheritClass( uw.ui.Tutorial, uw.ui.Step );

	uw.ui.Tutorial.prototype.setSelected = function ( selected ) {
		this.skipCheckbox.setSelected( selected );
	};

	uw.ui.Tutorial.prototype.load = function ( uploads ) {
		uw.ui.Step.prototype.load.call( this, uploads );

		this.$div.prepend(
			$( '<div>' )
				.attr( 'id', 'mwe-upwiz-tutorial' )
				.append(
					// TODO move this to JavaScript, too.
					this.tutorialHtml.show()
				)
		);

		this.skipCheckbox.popup.updateDimensions();
	};

	uw.ui.Tutorial.prototype.addNextButton = function () {
		var ui = this;

		this.nextButton = new OO.ui.ButtonWidget( {
			classes: [ 'mwe-upwiz-button-next' ],
			label: mw.message( 'mwe-upwiz-next' ).text(),
			flags: [ 'progressive', 'primary' ]
		} ).on( 'click', function () {
			ui.emit( 'next-step' );
		} );

		this.nextButtonPromise.done( function () {
			ui.$buttons.append(
				new OO.ui.HorizontalLayout( {
					items: [ ui.skipCheckbox, ui.skipCheckboxLabel, ui.nextButton ]
				} ).$element
			);
		} );
	};
}( mediaWiki, jQuery, mediaWiki.uploadWizard, OO ) );