mediawiki-extensions-Visual.../modules/ve-mw/ui/pages/ve.ui.MWSettingsPage.js
Trevor Parscal eca0a08ad9 (Stand back again) Even moar label manias! (label refactoring) + VE core update
Update VE core submodule to master (84ced37) and update calling code
for changes in OOUI.

Depends on Ic967b88d55daf48d365487e17f76488b3f02c60f and Ib599b9bd5028e2df084fcc3da657aeb7f1569d2a

New changes:
94f03c3 Undefined variables first in selectNodes
62b5648 Localisation updates from https://translatewiki.net.
10c5a18 Don't descend into handlesOwnChildren nodes in selectNodes
4ed2432 Update jquery.client to MW's master (45192156d7)
d7e24b8 Localisation updates from https://translatewiki.net.
babb9da Localisation updates from https://translatewiki.net.
4639d18 Localisation updates from https://translatewiki.net.
a561537 Localisation updates from https://translatewiki.net.
8f7053a Localisation updates from https://translatewiki.net.
7112cc2 Update OOjs UI to v0.1.0-pre (a290673bbd)

Change-Id: Ie7d58472619509782f23a7dedc1ec27c3dcc7543
2014-02-12 14:05:23 -08:00

169 lines
4.8 KiB
JavaScript

/*!
* VisualEditor user interface MWSettingsPage class.
*
* @copyright 2011-2014 VisualEditor Team and others; see AUTHORS.txt
* @license The MIT License (MIT); see LICENSE.txt
*/
/**
* MediaWiki meta dialog settings page.
*
* @class
* @extends OO.ui.PageLayout
*
* @constructor
* @param {ve.ui.Surface} surface Surface being worked on
* @param {string} name Unique symbolic name of page
* @param {Object} [config] Configuration options
*/
ve.ui.MWSettingsPage = function VeUiMWSettingsPage( surface, name, config ) {
// Configuration initialization
config = ve.extendObject( {
'icon': 'settings',
'label': ve.msg( 'visualeditor-dialog-meta-settings-section' )
}, config );
// Parent constructor
OO.ui.PageLayout.call( this, name, config );
// Properties
this.metaList = surface.getModel().metaList;
this.tocOptionTouched = false;
this.settingsFieldset = new OO.ui.FieldsetLayout( {
'$': this.$,
'label': ve.msg( 'visualeditor-dialog-meta-settings-label' ),
'icon': 'settings'
} );
// Initialization
// Table of Contents items
this.tocOptionSelector = new OO.ui.SelectWidget( { '$': this.$ } );
this.tocOptionWidgets = {
'default': new OO.ui.OptionWidget(
'default',
{ 'label': ve.msg( 'visualeditor-dialog-meta-settings-toc-default' ) }
),
'mwTOCForce': new OO.ui.OptionWidget(
'mwTOCForce',
{ 'label': ve.msg( 'visualeditor-dialog-meta-settings-toc-force' ) }
),
'mwTOCDisable': new OO.ui.OptionWidget(
'mwTOCDisable',
{ 'label': ve.msg( 'visualeditor-dialog-meta-settings-toc-disable' ) }
)
};
this.tocOptionSelector.addItems( ve.getObjectValues( this.tocOptionWidgets ) );
this.settingsFieldset.$element.append(
this.$( '<span>' )
.text( ve.msg( 'visualeditor-dialog-meta-settings-toc-label' ) ),
this.tocOptionSelector.$element
);
this.tocOptionSelector.connect( this, { 'select': 'onTOCOptionChange' } );
// Disable section edit links items
this.disableSectionEditLinksInput = new OO.ui.CheckboxWidget( {
'$': this.$,
'label': ve.msg( 'visualeditor-dialog-meta-settings-noeditsection-label' )
} );
this.settingsFieldset.$element.append( this.disableSectionEditLinksInput.$element );
this.$element.append( this.settingsFieldset.$element );
};
/* Inheritance */
OO.inheritClass( ve.ui.MWSettingsPage, OO.ui.PageLayout );
/* Methods */
/**
* Handle Table Of Contents display change events.
*
* @method
*/
ve.ui.MWSettingsPage.prototype.onTOCOptionChange = function () {
this.tocOptionTouched = true;
};
/**
* Get Table Of Contents option
*
* @returns {ve.dm.MetaItem|null} TOC option, if any
*/
ve.ui.MWSettingsPage.prototype.getTOCOptionItem = function () {
return this.metaList.getItemsInGroup( 'mwTOC' )[0] || null;
};
/**
* Get the section edit link disabling item
*
* @returns {Object|null} Section edit link disabling meta item, if any
*/
ve.ui.MWSettingsPage.prototype.getDisableSectionEditLinksItem = function () {
return this.metaList.getItemsInGroup( 'mwNoEditSection' )[0] || null;
};
/**
* Setup settings page.
*
* @param {Object} [data] Dialog setup data
*/
ve.ui.MWSettingsPage.prototype.setup = function () {
var tocOption = this.getTOCOptionItem(),
tocType = tocOption && tocOption.element.type || 'default';
// Table of Contents items
this.tocOptionSelector.selectItem( this.tocOptionWidgets[tocType] );
this.tocOptionTouched = false;
// Disable section edit links items
this.disableSectionEditLinksInput.setValue( !!this.getDisableSectionEditLinksItem() );
};
/**
* Tear down settings page.
*
* @param {Object} [data] Dialog tear down data
*/
ve.ui.MWSettingsPage.prototype.teardown = function ( data ) {
// Data initialisation
data = data || {};
var // Table of Contents items
currentTOCItem = this.getTOCOptionItem(),
newTOCData = this.tocOptionSelector.getSelectedItem(),
// Disable section edit links items
currentDisableSectionEditLinksItem = this.getDisableSectionEditLinksItem(),
newDisableSectionEditState = this.disableSectionEditLinksInput.getValue();
// Alter the TOC option flag iff it's been touched & is actually different
if ( this.tocOptionTouched ) {
if ( newTOCData.data === 'default' ) {
if ( currentTOCItem ) {
currentTOCItem.remove();
}
} else {
if ( !currentTOCItem ) {
this.metaList.insertMeta( { 'type': newTOCData.data } );
} else if ( currentTOCItem.getType() !== newTOCData.data ) {
currentTOCItem.replaceWith(
ve.extendObject( true, {},
currentTOCItem.getElement(),
{ 'type': newTOCData.data }
)
);
}
}
}
// Disable section edit links items
if ( currentDisableSectionEditLinksItem && !newDisableSectionEditState ) {
currentDisableSectionEditLinksItem.remove();
}
if ( !currentDisableSectionEditLinksItem && newDisableSectionEditState ) {
this.metaList.insertMeta( { 'type': 'mwNoEditSection' } );
}
};