2013-12-02 20:10:55 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor user interface MWTemplatePlaceholderPage class.
|
|
|
|
*
|
2014-01-05 12:05:05 +00:00
|
|
|
* @copyright 2011-2014 VisualEditor Team and others; see AUTHORS.txt
|
2013-12-02 20:10:55 +00:00
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* MediaWiki transclusion dialog placeholder page.
|
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @extends OO.ui.PageLayout
|
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @param {ve.dm.MWTemplatePlaceholderModel} placeholder Template placeholder
|
|
|
|
* @param {string} name Unique symbolic name of page
|
|
|
|
* @param {Object} [config] Configuration options
|
|
|
|
*/
|
2014-02-28 00:00:10 +00:00
|
|
|
ve.ui.MWTemplatePlaceholderPage = function VeUiMWTemplatePlaceholderPage( placeholder, name, config ) {
|
2014-04-25 23:50:21 +00:00
|
|
|
// Configuration initialization
|
|
|
|
config = ve.extendObject( {
|
|
|
|
'scrollable': false
|
|
|
|
}, config );
|
|
|
|
|
2013-12-02 20:10:55 +00:00
|
|
|
// Parent constructor
|
|
|
|
OO.ui.PageLayout.call( this, name, config );
|
|
|
|
|
|
|
|
// Properties
|
2014-02-12 21:45:37 +00:00
|
|
|
this.placeholder = placeholder;
|
2014-06-26 10:41:18 +00:00
|
|
|
|
2013-12-02 20:10:55 +00:00
|
|
|
this.addTemplateInput = new ve.ui.MWTitleInputWidget( {
|
2014-07-02 19:38:29 +00:00
|
|
|
'$': this.$, '$overlay': this.$overlay, 'namespace': 10, 'prefixColon': true
|
2014-06-26 10:41:18 +00:00
|
|
|
} )
|
2013-12-02 20:10:55 +00:00
|
|
|
.connect( this, {
|
|
|
|
'change': 'onTemplateInputChange',
|
|
|
|
'enter': 'onAddTemplate'
|
|
|
|
} );
|
2014-06-26 10:41:18 +00:00
|
|
|
|
2014-01-17 14:24:12 +00:00
|
|
|
this.addTemplateButton = new OO.ui.ButtonWidget( {
|
2014-06-26 10:41:18 +00:00
|
|
|
'$': this.$,
|
|
|
|
'label': ve.msg( 'visualeditor-dialog-transclusion-add-template' ),
|
|
|
|
'flags': ['constructive'],
|
|
|
|
'disabled': true
|
|
|
|
} )
|
2013-12-02 20:10:55 +00:00
|
|
|
.connect( this, { 'click': 'onAddTemplate' } );
|
2014-06-26 10:41:18 +00:00
|
|
|
|
2014-01-17 14:24:12 +00:00
|
|
|
this.removeButton = new OO.ui.ButtonWidget( {
|
2014-06-26 10:41:18 +00:00
|
|
|
'$': this.$,
|
|
|
|
'frameless': true,
|
|
|
|
'icon': 'remove',
|
|
|
|
'title': ve.msg( 'visualeditor-dialog-transclusion-remove-template' ),
|
|
|
|
'flags': ['destructive'],
|
|
|
|
'classes': [ 've-ui-mwTransclusionDialog-removeButton' ]
|
|
|
|
} )
|
2013-12-02 20:10:55 +00:00
|
|
|
.connect( this, { 'click': 'onRemoveButtonClick' } );
|
2014-06-26 10:41:18 +00:00
|
|
|
|
2013-12-02 20:10:55 +00:00
|
|
|
this.addTemplateFieldset = new OO.ui.FieldsetLayout( {
|
|
|
|
'$': this.$,
|
|
|
|
'label': ve.msg( 'visualeditor-dialog-transclusion-placeholder' ),
|
|
|
|
'icon': 'template',
|
|
|
|
'classes': [ 've-ui-mwTransclusionDialog-addTemplateFieldset' ],
|
|
|
|
'$content': this.addTemplateInput.$element.add( this.addTemplateButton.$element )
|
|
|
|
} );
|
|
|
|
|
|
|
|
// Initialization
|
2014-02-28 01:18:49 +00:00
|
|
|
this.$element
|
|
|
|
.addClass( 've-ui-mwTemplatePlaceholderPage' )
|
|
|
|
.append( this.addTemplateFieldset.$element, this.removeButton.$element );
|
2013-12-02 20:10:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
|
|
|
OO.inheritClass( ve.ui.MWTemplatePlaceholderPage, OO.ui.PageLayout );
|
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
2014-02-15 01:37:32 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWTemplatePlaceholderPage.prototype.setOutlineItem = function ( outlineItem ) {
|
|
|
|
// Parent method
|
|
|
|
OO.ui.PageLayout.prototype.setOutlineItem.call( this, outlineItem );
|
|
|
|
|
|
|
|
if ( this.outlineItem ) {
|
|
|
|
this.outlineItem
|
|
|
|
.setIcon( 'template' )
|
|
|
|
.setMovable( true )
|
2014-03-01 00:39:02 +00:00
|
|
|
.setRemovable( true )
|
2014-02-15 01:37:32 +00:00
|
|
|
.setFlags( [ 'placeholder' ] )
|
|
|
|
.setLabel( ve.msg( 'visualeditor-dialog-transclusion-placeholder' ) );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-12-02 20:10:55 +00:00
|
|
|
ve.ui.MWTemplatePlaceholderPage.prototype.onAddTemplate = function () {
|
2014-04-30 21:32:38 +00:00
|
|
|
var part,
|
|
|
|
transclusion = this.placeholder.getTransclusion(),
|
|
|
|
menu = this.addTemplateInput.getLookupMenu();
|
2013-12-02 20:10:55 +00:00
|
|
|
|
2014-04-30 21:32:38 +00:00
|
|
|
if ( menu.isVisible() ) {
|
|
|
|
menu.chooseItem( menu.getSelectedItem() );
|
|
|
|
}
|
|
|
|
part = ve.dm.MWTemplateModel.newFromName( transclusion, this.addTemplateInput.getValue() );
|
2014-02-05 19:11:41 +00:00
|
|
|
transclusion.replacePart( this.placeholder, part );
|
2013-12-02 20:10:55 +00:00
|
|
|
this.addTemplateInput.pushPending();
|
|
|
|
this.addTemplateButton.setDisabled( true );
|
|
|
|
this.removeButton.setDisabled( true );
|
|
|
|
};
|
|
|
|
|
|
|
|
ve.ui.MWTemplatePlaceholderPage.prototype.onTemplateInputChange = function ( value ) {
|
|
|
|
this.addTemplateButton.setDisabled( value === '' );
|
|
|
|
};
|
|
|
|
|
|
|
|
ve.ui.MWTemplatePlaceholderPage.prototype.onRemoveButtonClick = function () {
|
|
|
|
this.placeholder.remove();
|
|
|
|
};
|