MediaWiki:Gadget-DraftReview-MenuDialog.js

Da Wikipedia, l'enciclopedia libera.
Vai alla navigazione Vai alla ricerca

Questa pagina definisce alcuni parametri di aspetto e comportamento generale di tutte le pagine. Per personalizzarli vedi Aiuto:Stile utente.


Nota: dopo aver salvato è necessario pulire la cache del proprio browser per vedere i cambiamenti (per le pagine globali è comunque necessario attendere qualche minuto). Per Mozilla / Firefox / Safari: fare clic su Ricarica tenendo premuto il tasto delle maiuscole, oppure premere Ctrl-F5 o Ctrl-R (Command-R su Mac); per Chrome: premere Ctrl-Shift-R (Command-Shift-R su un Mac); per Konqueror: premere il pulsante Ricarica o il tasto F5; per Opera può essere necessario svuotare completamente la cache dal menù Strumenti → Preferenze; per Internet Explorer: mantenere premuto il tasto Ctrl mentre si preme il pulsante Aggiorna o premere Ctrl-F5.

var optionname = 'userjs-gadget-review-draft';
var defaultComments = require( './DraftReview-DefaultComments.json' );
var conf = mw.config.get( [ 'wgPageName', 'wgRevisionId', 'wgTitle', 'wgUserName' ] );

function MenuDialog( config ) {
	MenuDialog.super.call( this, config );
}

OO.inheritClass( MenuDialog, OO.ui.ProcessDialog );
MenuDialog.static.name = 'menuDialog';
MenuDialog.static.title = 'Revisione bozza';
MenuDialog.static.actions = [
	{
		action: 'edit',
		modes: 'default',
		label: 'Conferma',
		flags: [ 'primary', 'progressive' ],
		disabled: true
	},
	{
		action: 'settings',
		modes: 'default',
		label: 'Impostazioni',
		invisibleLabel: true,
		icon: 'settings',
		framed: false
	},
	{
		action: 'cancel',
		modes: 'default',
		label: 'Annulla',
		flags: [ 'safe', 'close' ],
		invisibleLabel: true,
	},
	{
		action: 'save',
		modes: 'settings',
		label: 'Salva modifiche',
		flags: [ 'primary', 'progressive' ],
		disabled: true
	},
	{
		action: 'back',
		modes: 'settings',
		label: 'Indietro',
		flags: [ 'safe', 'back' ],
		invisibleLabel: true
	}
];

MenuDialog.prototype.getBodyHeight = function () {
	return 440;
};

MenuDialog.prototype.initialize = function () {
	var menuDialog = this;

	MenuDialog.super.prototype.initialize.apply( this, arguments );

	this.comments = this.getComments();
	this.touchscreenMode = this.isTouchscreen();

	// Finestra principale
	this.mainFieldsetLayout = new OO.ui.FieldsetLayout();
	this.dropdown = new OO.ui.DropdownWidget( {
		label: '',
		menu: {
			items: [
				new OO.ui.MenuOptionWidget( {
					data: 'R',
					label: 'Respinta'
				} ),
				new OO.ui.MenuOptionWidget( {
					data: 'A',
					label: 'Approvata'
				} )
			]
		}
	} );
	this.titleInput = new OO.ui.TextInputWidget( {
		value: conf.wgTitle
	} );
	this.titleInputFieldLayout = new OO.ui.FieldLayout( this.titleInput, {
		label: 'Nuovo titolo',
		align: 'top'
	} );
	this.comboBoxInput = new OO.ui.ComboBoxInputWidget( {
		$overlay: this.mainFieldsetLayout.$element,
		options: [ { data: '', label: ' ' } ].concat( this.comments )
	} );
	this.comboBoxFieldLayout = new OO.ui.FieldLayout( this.comboBoxInput, {
		align: 'top'
	} );
	this.addUserInputFieldLayout( 'richiedente' );
	this.addUserInputFieldLayout( 'autore' );
	this.mainFieldsetLayout.addItems( [
		new OO.ui.FieldLayout( this.dropdown, {
			label: 'Seleziona esito',
			align: 'top'
		} ),
		new OO.ui.FieldLayout(
			new OO.ui.Widget( {
				content: [
					this.titleInputFieldLayout,
					this.comboBoxFieldLayout,
					this.richiedenteInputFieldLayout,
					this.autoreInputFieldLayout
				]
			} ),
			{
				align: 'top'
			}
		)
	] );
	this.layoutGroup = this.mainFieldsetLayout.items[ 1 ].$element;
	this.mainPanel = new OO.ui.PanelLayout( {
		data: 'main',
		padded: true,
		expanded: false
	} );
	this.mainPanel.$element.append( this.mainFieldsetLayout.$element );

	// Finestra di configurazione
	this.subtractButton = new OO.ui.ButtonWidget( {
		label: this.touchscreenMode ? 'Rimuovi' : 'Trascina qui per rimuovere',
		icon: 'trash',
		flags: [ 'destructive' ],
		framed: false
	} );
	if ( this.touchscreenMode ) {
		this.configList = new OO.ui.CheckboxMultiselectWidget();
	} else {
		var draggableGroupWidget = require( './DraftReview-Draggable.js' );
		this.configList = new draggableGroupWidget();
	}
	this.loadConfigListItems( this.comments );
	this.newCommentInput = new OO.ui.TextInputWidget( {
		invisibleLabel: true
	} );
	this.addButton = new OO.ui.ButtonWidget( {
		label: 'Aggiungi commento',
		icon: 'speechBubbleAdd',
		flags: [ 'progressive' ],
		disabled: true,
		framed: false
	} );
	this.resetButton = new OO.ui.ButtonWidget( {
		label: 'Ricarica predefiniti',
		icon: 'reload',
		flags: [ 'safe' ],
		disabled: this.arraysEqual( defaultComments, this.getConfigListItems() )
	} );
	this.undoButton = new OO.ui.ButtonWidget( {
		label: 'Annulla modifiche',
		icon: 'undo',
		flags: [ 'safe' ],
		disabled: true
	} );
	this.settingsFieldLayout = new OO.ui.FieldsetLayout( {
		items: [
			new OO.ui.FieldLayout(
				new OO.ui.Widget( {
					content: [
						this.configList,
						this.subtractButton
					]
				} ),
				{
					align: 'top'
				}
			),
			new OO.ui.FieldLayout(
				new OO.ui.Widget( {
					content: [
						this.newCommentInput,
						this.addButton
					]
				} ),
				{
					align: 'top'
				}
			),
			new OO.ui.FieldLayout(
				new OO.ui.Widget( {
					content: [
						new OO.ui.HorizontalLayout( {
							items: [
								this.resetButton,
								this.undoButton
							]
						} )
					]
				} ),
				{
					align: 'top'
				}
			)
		]
	} );
	this.settingsPanel = new OO.ui.PanelLayout( {
		data: 'settings',
		padded: true,
		expanded: false
	} );
	this.settingsPanel.$element.append( this.settingsFieldLayout.$element );

	// CSS
	this.layoutGroup.css( { 'margin-top': 0, 'max-height': 0, overflow: 'hidden' } );
	this.layoutGroup.find( '.oo-ui-fieldLayout' ).css( 'margin-top', '2em' );
	this.subtractButton.$element.css( 'margin-top', '.5em' );
	this.configList.$element.css( { 'max-height': '170px', overflow: 'auto' } );
	this.addButton.$element.css( { 'margin-top': '.5em', 'margin-bottom': '.5em' } );

	// Eventi
	this.dropdown.connect( this, { labelChange: 'onDropdownLabelChange' } );
	this.titleInput.connect( this, { change: 'updateDisabled' } );
	this.comboBoxInput.connect( this, { change: 'updateDisabled' } );
	this.configList.connect( this, { change: 'onConfigListChange' } );
	this.newCommentInput.connect( this, { change: 'onNewCommentInputChange' } );
	this.addButton.connect( this, { click: 'onAddButtonClick' } );
	this.resetButton.connect( this, { click: 'onResetButtonClick' } );
	this.undoButton.connect( this, { click: 'onUndoButtonClick' } );
	if ( this.touchscreenMode ) {
		this.subtractButton.connect( this, { click: 'onSubtractButtonClick' }  );
	} else {
		this.subtractButton.$element.on( {
			dragover: this.onSubtractButtonDragover.bind( this ),
			drop: this.onSubtractButtonDrop.bind( this )
		} );
	}

	this.stackLayout = new OO.ui.StackLayout( {
		items: [
			this.mainPanel,
			this.settingsPanel
		]
	} );
	this.$body.append( this.stackLayout.$element );
};

MenuDialog.prototype.addUserInputFieldLayout = function ( userRole ) {
	this[ `${userRole}Input` ] = new mw.widgets.UserInputWidget( {
		validate: 'non-empty',
		$overlay: this.mainFieldsetLayout.$element
	} );
	this[ `${userRole}Input` ].setValidityFlag( false );
	this[ `${userRole}CheckboxInput` ] = new OO.ui.CheckboxInputWidget( {
		selected: true
	} );
	this[ `${userRole}CheckboxLabel` ] = new OO.ui.LabelWidget( {
		label: `Avvisa ${userRole}`
	} );
	this[ `${userRole}InputFieldLayout` ] = new OO.ui.FieldLayout(
		new OO.ui.Widget( {
			content: [
				new OO.ui.HorizontalLayout( {
					items: [
						this[ `${userRole}CheckboxInput` ],
						this[ `${userRole}CheckboxLabel` ]
					]
				} ),
				this[ `${userRole}Input` ]
			]
		} ),
		{
			align: 'top'
		}
	);
	var eventData = { targetUserRole: userRole };
	this[ `${userRole}Input` ].connect( this, { change: [ 'onUserInputChange', eventData ] } );
	this[ `${userRole}CheckboxInput` ].connect( this, { change: [ 'onCheckboxInputChange', eventData ] } );
	this[ `${userRole}CheckboxLabel` ].$element.on( 'click', eventData, this.onCheckboxLabelClick.bind( this ) );
};

MenuDialog.prototype.getSetupProcess = function ( data ) {
	return MenuDialog.super.prototype.getSetupProcess.call( this, data )
		.next( function () {
			var menuDialog = this;
			var $richiedente = $( '#bozza-autore-richiesta-revisione' );
			if ( $richiedente.text () ) {
				this.setUser(
					$richiedente.text(),
					'richiedente',
					$richiedente.data( 'ts-ultima-richiesta-revisione' )
				);
			} else {
				menuDialog.richiedenteInputFieldLayout.toggle( false );
			}
			this.getOldestRevision().done( function ( oldestRev ) {
				if ( !menuDialog.autoreCheckboxInput.selected || menuDialog.autoreInput.value ) {
					return;
				}
				if ( oldestRev.user === $richiedente.text() ) {
					menuDialog.richiedenteInputFieldLayout.toggle( false );
					menuDialog.autoreCheckboxLabel.setLabel( 'Avvisa autore/richiedente' );
				}
				menuDialog.setUser( oldestRev.user, 'autore', oldestRev.timestamp );
			} );
			this.actions.setMode( 'default' );
			this.updateDisabled();
		}, this );
};

MenuDialog.prototype.attachActions = function () {
	var i, len, other, special, others;

	OO.ui.ProcessDialog.super.prototype.attachActions.call( this );

	special = this.actions.getSpecial();
	others = this.actions.getOthers();
	for ( i = 0, len = others.length; i < len; i++ ) {
		other = others[ i ];
		if ( other.action === 'settings' ) {
			var $settings = other.$element;
			var $settingsIcon = $settings.find( '.oo-ui-iconElement-icon' );
			$settings
				.css( 'display', 'inline' )
				.css( 'margin-right', 0 )
				.appendTo( this.$primaryActions )
				.find( '.oo-ui-buttonElement-button' )
					.css( 'vertical-align', 'top' );
			$settingsIcon
				.css( 'left', '50%' )
				.css( 'margin-left', - $settingsIcon.width() / 2 );
		} else {
			this.$otherActions.append( other.$element );
		}
	}
	if ( special.primary ) {
		this.$primaryActions.append( special.primary.$element );
	}
	if ( special.safe ) {
		this.$safeActions.append( special.safe.$element );
	}
};

// Gestisci azioni
MenuDialog.prototype.getActionProcess = function ( action ) {
	var menuDialog = this;

	switch ( action ) {
		case 'settings':
			this.actions.setMode( 'settings' );
			this.title.$label.text( 'Configurazione commenti' );
			this.stackLayout.setItem( this.settingsPanel );
			return new OO.ui.Process();
		case 'back':
			this.actions.setMode( 'default' );
			this.title.$label.text( 'Revisione bozza' );
			this.stackLayout.setItem( this.mainPanel );
			return new OO.ui.Process();
		case 'save':
		case 'edit':
			this.actions.getSpecial().primary.setDisabled( true );
	}

	return MenuDialog.super.prototype.getActionProcess.call( this, action )
		.next( function () {
			switch ( action ) {
				case 'cancel': // Chiudi
					return this.close( { action: action } ).closed;
				case 'save':
					var comments = [];
					this.newComments.forEach( function ( item ) {
						comments.push( {
							data: item.data,
							label: item.label
						} );
					} );
					this.newComments = undefined;
					return this.saveCustomComments( comments ).done( function () {
						menuDialog.comments = comments;
						menuDialog.comboBoxInput.setOptions(
							[ { data: '', label: ' ' } ].concat( comments )
						);
						menuDialog.updateDisabled();
					} );
				case 'edit':
					break;
				default:
					return;
			}

			var request, title;
			var promise = $.Deferred();

			switch ( this.dropdown.label ) {
				case 'Respinta':
					title = conf.wgTitle;
					request = this.declineSubmission( this.comboBoxInput.value );
					break;
				case 'Approvata':
					title = this.titleInput.value;
					request = this.moveDraft( title, this.comboBoxInput.value );
					break;
			}

			request.then( function ( data ) {
				var p1, p2;
				if (
					menuDialog.richiedenteCheckboxInput.selected &&
					menuDialog.richiedenteInputFieldLayout.isVisible()
				) {
					p1 = menuDialog.notifyUser( menuDialog.richiedenteInput.value, title );
				}
				if ( menuDialog.autoreCheckboxInput.selected ) {
					p2 = menuDialog.notifyUser( menuDialog.autoreInput.value, title );
				}
				if ( p1 || p2 ) {
					return $.when( p1, p2 );
				} else {
					return $.Deferred().resolve( data );
				}
			} ).done( function ( data ) {
				menuDialog.completed = true;
				menuDialog.showSuccessMessage();
				promise.resolve( data );
			} ).fail( function ( error ) {
				var errorMsg = 'Codice dell\'errore: ' + error;
				if ( error === 'editconflict' ) {
					errorMsg = 'Conflitto di modifiche: ricaricare la pagina.';
				} else if ( error === 'articleexists' ) {
					errorMsg = 'Esiste già una pagina al titolo indicato.';
				}
				promise.reject( new OO.ui.Error( errorMsg ) );
			} );

			return promise;
		}, this );
};

MenuDialog.prototype.setUser = function ( username, userRole, submissionTimestamp ) {
	if (
		mw.util.isIPAddress( username ) &&
		new Date() - new Date( submissionTimestamp ) > 86400000
	) {
		this[`${userRole}CheckboxInput`].setSelected( false );
	}
	this[`${userRole}Input`].setValue( username );
};

MenuDialog.prototype.onDropdownLabelChange = function () {
	var declined = this.dropdown.label === 'Respinta';
	var value = this.comboBoxInput.value.trim();
	this.titleInputFieldLayout.toggle( !declined );
	this.comboBoxFieldLayout.setLabel(
		declined ? 'Commento (obbligatorio)' : 'Oggetto'
	);
	if ( declined && value === 'Pubblicazione bozza' ) {
		this.comboBoxInput.setValue( '' );
	} else if ( !declined && !value ) {
		this.comboBoxInput.setValue( 'Pubblicazione bozza' );
	}
	if ( this.layoutGroup.css( 'max-height' ) === '0px' ) {
		this.layoutGroup
			.css( 'max-height', '500px' )
			.css( 'transition', 'max-height 0.15s ease-in' );
	}
	this.updateDisabled();
};

MenuDialog.prototype.onUserInputChange = function ( eventData ) {
	var menuDialog = this;
	var userInput = this[ `${eventData.targetUserRole}Input` ];
	var IsUserValidPropName = `${eventData.targetUserRole}IsValid`;
	this.actions.getSpecial().primary.setDisabled( true );
	if ( !userInput.getValue().trim() ) {
		this[ IsUserValidPropName ] = false;
		return;
	}
	// Impedisce di procedere se viene indicato un utente inesistente
	this.getUserInfo( userInput.getValue() ).done( function ( userInfo ) {
		menuDialog[ IsUserValidPropName ] = userInfo.missing !== '';
		userInput.setValidityFlag( menuDialog[ IsUserValidPropName ] );
		menuDialog.updateDisabled();
	} );
};

MenuDialog.prototype.onCheckboxInputChange = function ( eventData, state ) {
	var userInput = this[ `${eventData.targetUserRole}Input` ];
	this.updateDisabled();
	userInput.setDisabled( !userInput.isDisabled() );
};

MenuDialog.prototype.onCheckboxLabelClick = function ( event ) {
	var checkboxInput = this[ `${event.data.targetUserRole}CheckboxInput` ];
	checkboxInput.setSelected( !checkboxInput.selected );
};

MenuDialog.prototype.onSubtractButtonClick = function () {
	this.configList.removeItems(
		this.configList.items.filter( function ( item ) {
			return item.isSelected();
		} )
	);
};

MenuDialog.prototype.onSubtractButtonDragover = function ( e ) {
	e.preventDefault();
};

MenuDialog.prototype.onSubtractButtonDrop = function ( e ) {
	e.preventDefault();
	var index = e.originalEvent.dataTransfer.getData(
		'application-x/OOUI-draggable'
	);
	if ( index !== null ) {
		this.configList.removeItems( [ this.configList.items[ index ] ] );
	}
};

MenuDialog.prototype.onConfigListChange = function () {
	var items = this.getConfigListItems();
	if ( !this.arraysEqual( this.comments, items ) ) {
		this.newComments = items;
	} else {
		this.newComments = undefined;
	}
	this.updateDisabled();
};

MenuDialog.prototype.onNewCommentInputChange = function ( v ) {
	this.addButton.setDisabled( !v.trim() );
};

MenuDialog.prototype.onAddButtonClick = function () {
	var value = this.newCommentInput.value.trim();
	var invalid = false;
	this.configList.items.forEach( function ( comment ) {
		if ( comment.data === value ) {
			invalid = true;
		}
	} );
	if ( !invalid ) {
		var newComment = { data: value, label: value };
		if ( this.touchscreenMode ) {
			this.configList.addItems( [
				new OO.ui.CheckboxMultioptionWidget( newComment )
			] );
		} else {
			this.configList.addItem( newComment );
			this.configList.updateIndexesAfterNewItemsAdded();
		}
	}
	this.newCommentInput.setValue( '' );
};

MenuDialog.prototype.onResetButtonClick = function () {
	this.loadConfigListItems( defaultComments );
};

MenuDialog.prototype.onUndoButtonClick = function () {
	this.loadConfigListItems( this.comments );
};

MenuDialog.prototype.isTouchscreen = function () {
	return 'ontouchstart' in window ||
		navigator.maxTouchPoints > 0 ||
		navigator.msMaxTouchPoints > 0;
};

MenuDialog.prototype.arraysEqual = function ( array1, array2 ) {
	return JSON.stringify( array1 ) === JSON.stringify( array2 );
};

MenuDialog.prototype.getComments = function () {
	if ( mw.user.options.exists( optionname ) ) {
		return JSON.parse( mw.user.options.get( optionname ) );
	} else {
		return defaultComments;
	}
};

MenuDialog.prototype.saveCustomComments = function ( comments ) {
	return new mw.Api().postWithToken( 'csrf', {
		action: 'options',
		optionname: optionname,
		optionvalue: !this.arraysEqual( defaultComments, comments ) ?
			JSON.stringify( comments ) :
			undefined
	} );
};

MenuDialog.prototype.getOldestRevision = function () {
	return new mw.Api().get( {
		action: 'query',
		format: 'json',
		prop: 'revisions',
		titles: conf.wgPageName,
		formatversion: 2,
		rvprop: [ 'timestamp', 'user' ],
		rvslots: 'main',
		rvlimit: 1,
		rvdir: 'newer'
	} ).then( function ( data ) {
		return data.query.pages[ 0 ].revisions[ 0 ];
	} );
};

MenuDialog.prototype.getUserInfo = function ( username ) {
	return new mw.Api().get( {
		action: 'query',
		format: 'json',
		list: 'users',
		ususers: username
	} ).then( function ( data ) {
		return data.query.users[ 0 ];
	} );
};

MenuDialog.prototype.declineSubmission = function ( comment ) {
	// Ottiene contenuto e timestamp per identificare conflitti di modifiche
	return new mw.Api().get( {
		action: 'query',
		format: 'json',
		prop: 'revisions',
		revids: conf.wgRevisionId,
		formatversion: 2,
		rvprop: [ 'content', 'timestamp' ],
		rvslots: 'main'
	} ).then( function ( data ) {
		var page = data.query.pages[ 0 ];
		if ( page.missing ) {
			return $.Deferred().reject( 'missingtitle' );
		}
		var revision = page.revisions[ 0 ];
		var wikitext = revision.slots.main.content;
		var submissions = wikitext.match(
			/\{\{ *[Rr]ichiesta *revisione *bozza *\|[^\}]+\}\}/g
		) || [];
		submissions.some( function ( oldString ) {
			if ( /\| *(esito|utente|revisore) *= *[^\|\}]/.test( oldString ) ) {
				return false;
			}
			var newString = oldString
				.replace(
					/\| *(esito|utente|revisore) *= *(?=[\|\}])/g,
					''
				)
				.replace(
					/(?=\})/,
					'|esito=' + comment + '|revisore=' + conf.wgUserName
				);
			// Modifica contenuto
			wikitext = wikitext.replace( oldString, newString );
			return true;
		} );
		if ( revision.slots.main.content === wikitext ) {
			return $.Deferred().reject( 'templatemissing' );
		}
		// Pubblica esito
		return new mw.Api().postWithToken( 'csrf', {
			action: 'edit',
			format: 'json',
			title: conf.wgPageName,
			text: wikitext,
			summary: 'Esito revisione bozza',
			nocreate: 1,
			watchlist: 'nochange',
			starttimestamp: revision.timestamp,
			baserevid: conf.wgRevisionId
		} );
	} );
};

MenuDialog.prototype.moveDraft = function ( newTitle, editSummary ) {
	// Sposta bozza
	return new mw.Api().postWithToken( 'csrf', {
		action: 'move',
		from: conf.wgPageName,
		to: newTitle,
		reason: editSummary,
		movetalk: 1,
		noredirect: 1,
		watchlist: 'nochange',
		format: 'json'
	} );
};

/**
 * Invia, se non deciso diversamente, un avviso all'utente selezionato
 * 
 * @param {String} Nome dell'utente a cui inviare l'avviso
 * @param {String} Titolo della bozza senza indicazioni sul namespace
 */
MenuDialog.prototype.notifyUser = function ( username, title ) {
	var esito = this.dropdown.label.charAt(0);
	var text = `\n\n== Esito revisione bozza ${title} ==\n\n` +
		'{{Erb' +
		`|${esito}` +
		`|${title}` +
		`|Commento=${esito === 'R' ? this.comboBoxInput.value : ''}` +
		'}}--~~' + '~~';

	return new mw.Api().postWithToken( 'csrf', {
		action: 'edit',
		format: 'json',
		title: 'Discussioni utente:' + username,
		appendtext: text,
		summary: 'Avviso esito revisione bozza',
		watchlist: 'nochange'
	} );
};

MenuDialog.prototype.loadConfigListItems = function ( comments ) {
	var menuDialog = this;
	this.configList.clearItems();
	if ( this.touchscreenMode ) {
		comments.forEach( function ( comment ) {
			menuDialog.configList.addItems( [
				new OO.ui.CheckboxMultioptionWidget( comment )
			] );
		} );
	} else {
		comments.forEach( function ( comment ) {
			menuDialog.configList.addItem( comment );
		} );
		this.configList.updateIndexesAfterNewItemsAdded();
	}
};

MenuDialog.prototype.getConfigListItems = function () {
	var items = [];
	this.configList.items.forEach( function ( item ) {
		items.push( {
			data: item.data,
			label: item.label
		} );
	} );
	return items;
};

MenuDialog.prototype.isFormFilled = function () {
	for ( var userRole of [ 'richiedente', 'autore' ] ) {
		if (
			this[ `${userRole}CheckboxInput` ].selected &&
			this[ `${userRole}InputFieldLayout` ].isVisible() &&
			!this[ `${userRole}IsValid` ]
		) {
			return false;
		}
	}

	switch ( this.dropdown.label ) {
		case 'Respinta':
			return !!this.comboBoxInput.value.trim();
		case 'Approvata':
			return !!this.titleInput.value.trim();
		default:
			return false;
	}
};

MenuDialog.prototype.updateDisabled = function () {
	var editDisabled;
	if ( this.stackLayout.getCurrentItem().getData() === 'settings' ) {
		editDisabled = !this.newComments;
		this.undoButton.setDisabled( editDisabled );
		this.resetButton.setDisabled(
			this.arraysEqual( defaultComments, this.getConfigListItems() )
		);
	} else {
		editDisabled = !!this.completed || !this.isFormFilled();
	}
	this.actions.getSpecial().primary.setDisabled( editDisabled );
};

MenuDialog.prototype.showSuccessMessage = function () {
	var $ul = $( '<ul>' ).css( 'margin-top', '1em' );
	var links = [
		{
			condition: () => true,
			pagename: 'Wikipedia:Bozze da revisionare',
			pre: 'Vai a',
			linktext: 'Wikipedia:Bozze da revisionare'
		},
		{
			condition: () => this.dropdown.label === 'Approvata',
			pagename: this.titleInput.value,
			pre: 'Vai a',
			linktext: this.titleInput.value
		},
		{
			condition: () => this.richiedenteCheckboxInput.selected && this.richiedenteInputFieldLayout.isVisible(),
			pagename: `Discussioni utente:${this.richiedenteInput.value}`,
			pre: 'Vai alla',
			linktext: `pagina di discussione di ${this.richiedenteInput.value}`
		},
		{
			condition: () => this.autoreCheckboxInput.selected,
			pagename: `Discussioni utente:${this.autoreInput.value}`,
			pre: 'Vai alla',
			linktext: `pagina di discussione di ${this.autoreInput.value}`
		}
	];

	for ( let { condition, pagename, pre, linktext } of links ) {
		if ( condition() ) {
			$( '<li>' )
				.appendTo( $ul )
				.text( `${pre} ` )
				.append(
					$( '<a>' )
						.attr( 'href', `/wiki/${pagename}` )
						.text( linktext )
				);
		}
	}

	// Mostra esito
	var messageWidget = new OO.ui.MessageWidget( {
		type: 'success',
		label: new OO.ui.HtmlSnippet(
			'<b>Azione eseguita con successo</b>' + $ul.prop( 'outerHTML' )
		)
	} );
	messageWidget.$element
		.css( 'background-color', 'inherit' )
		.css( 'border', 0 )
		.css( 'margin-top', '2em' );
	this.mainFieldsetLayout.$element.replaceWith( messageWidget.$element );
};

module.exports = MenuDialog;