2014-02-27 23:58:37 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor user interface MWParameterPlaceholderPage class.
|
|
|
|
*
|
2015-01-08 23:54:03 +00:00
|
|
|
* @copyright 2011-2015 VisualEditor Team and others; see AUTHORS.txt
|
2014-02-27 23:58:37 +00:00
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* MediaWiki transclusion dialog parameter placeholder page.
|
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @extends OO.ui.PageLayout
|
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @param {ve.dm.MWTemplateModel} parameter Template
|
|
|
|
* @param {string} name Unique symbolic name of page
|
|
|
|
* @param {Object} [config] Configuration options
|
|
|
|
*/
|
|
|
|
ve.ui.MWParameterPlaceholderPage = function VeUiMWParameterPlaceholderPage( parameter, name, config ) {
|
2014-04-25 23:50:21 +00:00
|
|
|
// Configuration initialization
|
|
|
|
config = ve.extendObject( {
|
2014-08-22 20:50:48 +00:00
|
|
|
scrollable: false
|
2014-04-25 23:50:21 +00:00
|
|
|
}, config );
|
|
|
|
|
2014-02-27 23:58:37 +00:00
|
|
|
// Parent constructor
|
|
|
|
OO.ui.PageLayout.call( this, name, config );
|
|
|
|
|
|
|
|
// Properties
|
2015-04-13 21:30:41 +00:00
|
|
|
this.name = name;
|
2014-02-27 23:58:37 +00:00
|
|
|
this.parameter = parameter;
|
|
|
|
this.template = this.parameter.getTemplate();
|
2015-04-13 21:30:41 +00:00
|
|
|
this.addParameterSearch = new ve.ui.MWParameterSearchWidget( this.template, {
|
|
|
|
$: this.$,
|
|
|
|
showAll: !!config.expandedParamList
|
|
|
|
} )
|
|
|
|
.connect( this, {
|
|
|
|
select: 'onParameterSelect',
|
|
|
|
showAll: 'onParameterShowAll'
|
|
|
|
} );
|
2014-06-26 10:41:18 +00:00
|
|
|
|
2014-02-27 23:58:37 +00:00
|
|
|
this.removeButton = new OO.ui.ButtonWidget( {
|
2014-08-22 20:50:48 +00:00
|
|
|
framed: false,
|
|
|
|
icon: 'remove',
|
|
|
|
title: ve.msg( 'visualeditor-dialog-transclusion-remove-param' ),
|
2014-12-09 22:28:40 +00:00
|
|
|
flags: [ 'destructive' ],
|
2014-08-22 20:50:48 +00:00
|
|
|
classes: [ 've-ui-mwTransclusionDialog-removeButton' ]
|
2014-06-26 10:41:18 +00:00
|
|
|
} )
|
2014-08-22 20:50:48 +00:00
|
|
|
.connect( this, { click: 'onRemoveButtonClick' } );
|
2014-06-26 10:41:18 +00:00
|
|
|
|
2014-02-27 23:58:37 +00:00
|
|
|
this.addParameterFieldset = new OO.ui.FieldsetLayout( {
|
2014-08-22 20:50:48 +00:00
|
|
|
label: ve.msg( 'visualeditor-dialog-transclusion-add-param' ),
|
|
|
|
icon: 'parameter',
|
|
|
|
classes: [ 've-ui-mwTransclusionDialog-addParameterFieldset' ],
|
|
|
|
$content: this.addParameterSearch.$element
|
2014-02-27 23:58:37 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
// Initialization
|
2014-02-28 01:18:49 +00:00
|
|
|
this.$element
|
|
|
|
.addClass( 've-ui-mwParameterPlaceholderPage' )
|
|
|
|
.append( this.addParameterFieldset.$element, this.removeButton.$element );
|
2014-02-27 23:58:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
|
|
|
OO.inheritClass( ve.ui.MWParameterPlaceholderPage, OO.ui.PageLayout );
|
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
2015-04-13 21:30:41 +00:00
|
|
|
/**
|
|
|
|
* Respond to the parameter search widget showAll event
|
|
|
|
* @fires showAll
|
|
|
|
*/
|
|
|
|
ve.ui.MWParameterPlaceholderPage.prototype.onParameterShowAll = function () {
|
|
|
|
this.emit( 'showAll', this.name );
|
|
|
|
};
|
|
|
|
|
2014-02-27 23:58:37 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWParameterPlaceholderPage.prototype.setOutlineItem = function ( outlineItem ) {
|
|
|
|
// Parent method
|
|
|
|
OO.ui.PageLayout.prototype.setOutlineItem.call( this, outlineItem );
|
|
|
|
|
|
|
|
if ( this.outlineItem ) {
|
|
|
|
this.outlineItem
|
|
|
|
.setIcon( 'parameter' )
|
|
|
|
.setMovable( false )
|
|
|
|
.setRemovable( true )
|
|
|
|
.setLevel( 1 )
|
|
|
|
.setFlags( [ 'placeholder' ] )
|
|
|
|
.setLabel( ve.msg( 'visualeditor-dialog-transclusion-add-param' ) );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
ve.ui.MWParameterPlaceholderPage.prototype.onParameterSelect = function ( name ) {
|
|
|
|
var param;
|
|
|
|
|
|
|
|
if ( name ) {
|
|
|
|
param = new ve.dm.MWParameterModel( this.template, name );
|
|
|
|
this.addParameterSearch.query.setValue( '' );
|
|
|
|
this.template.addParameter( param );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
ve.ui.MWParameterPlaceholderPage.prototype.onRemoveButtonClick = function () {
|
|
|
|
this.parameter.remove();
|
|
|
|
};
|