2013-12-02 20:10:55 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor user interface MWTemplatePlaceholderPage class.
|
|
|
|
*
|
2018-01-03 00:54:47 +00:00
|
|
|
* @copyright 2011-2018 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-10-28 00:36:19 +00:00
|
|
|
* @cfg {jQuery} [$overlay] Overlay for dropdowns
|
2013-12-02 20:10:55 +00:00
|
|
|
*/
|
2014-02-28 00:00:10 +00:00
|
|
|
ve.ui.MWTemplatePlaceholderPage = function VeUiMWTemplatePlaceholderPage( placeholder, name, config ) {
|
2015-01-27 00:47:59 +00:00
|
|
|
var addTemplateActionFieldLayout;
|
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 );
|
|
|
|
|
2013-12-02 20:10:55 +00:00
|
|
|
// Parent constructor
|
2016-08-22 21:44:59 +00:00
|
|
|
ve.ui.MWTemplatePlaceholderPage.super.call( this, name, config );
|
2013-12-02 20:10:55 +00:00
|
|
|
|
|
|
|
// Properties
|
2014-02-12 21:45:37 +00:00
|
|
|
this.placeholder = placeholder;
|
2014-06-26 10:41:18 +00:00
|
|
|
|
2015-04-10 20:28:38 +00:00
|
|
|
this.addTemplateInput = new ve.ui.MWTemplateTitleInputWidget( {
|
2015-06-15 10:25:44 +00:00
|
|
|
$overlay: config.$overlay,
|
|
|
|
showDescriptions: true
|
2014-06-26 10:41:18 +00:00
|
|
|
} )
|
2013-12-02 20:10:55 +00:00
|
|
|
.connect( this, {
|
2014-08-22 20:50:48 +00:00
|
|
|
change: 'onTemplateInputChange',
|
|
|
|
enter: 'onAddTemplate'
|
2013-12-02 20:10:55 +00:00
|
|
|
} );
|
2014-06-26 10:41:18 +00:00
|
|
|
|
2014-01-17 14:24:12 +00:00
|
|
|
this.addTemplateButton = new OO.ui.ButtonWidget( {
|
2014-08-22 20:50:48 +00:00
|
|
|
label: ve.msg( 'visualeditor-dialog-transclusion-add-template' ),
|
2017-09-26 18:59:38 +00:00
|
|
|
flags: [ 'progressive' ],
|
2015-01-27 00:47:59 +00:00
|
|
|
classes: [ 've-ui-mwTransclusionDialog-addButton' ],
|
2014-08-22 20:50:48 +00:00
|
|
|
disabled: true
|
2014-06-26 10:41:18 +00:00
|
|
|
} )
|
2014-08-22 20:50:48 +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-08-22 20:50:48 +00:00
|
|
|
framed: false,
|
2017-05-31 23:30:17 +00:00
|
|
|
icon: 'trash',
|
2014-08-22 20:50:48 +00:00
|
|
|
title: ve.msg( 'visualeditor-dialog-transclusion-remove-template' ),
|
2015-07-22 22:13:09 +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
|
|
|
|
2015-08-11 17:25:16 +00:00
|
|
|
if ( this.placeholder.getTransclusion().parts.length === 1 ) {
|
|
|
|
this.removeButton.toggle( false );
|
|
|
|
}
|
|
|
|
|
2015-01-27 00:47:59 +00:00
|
|
|
addTemplateActionFieldLayout = new OO.ui.ActionFieldLayout(
|
|
|
|
this.addTemplateInput,
|
2015-04-09 23:47:15 +00:00
|
|
|
this.addTemplateButton
|
2015-01-27 00:47:59 +00:00
|
|
|
);
|
|
|
|
|
2013-12-02 20:10:55 +00:00
|
|
|
this.addTemplateFieldset = new OO.ui.FieldsetLayout( {
|
2014-08-22 20:50:48 +00:00
|
|
|
label: ve.msg( 'visualeditor-dialog-transclusion-placeholder' ),
|
2017-07-06 16:52:56 +00:00
|
|
|
icon: 'puzzle',
|
2014-08-22 20:50:48 +00:00
|
|
|
classes: [ 've-ui-mwTransclusionDialog-addTemplateFieldset' ],
|
2015-01-27 00:47:59 +00:00
|
|
|
items: [ addTemplateActionFieldLayout ]
|
2013-12-02 20:10:55 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
// 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
|
|
|
|
*/
|
2016-08-22 21:44:59 +00:00
|
|
|
ve.ui.MWTemplatePlaceholderPage.prototype.setOutlineItem = function () {
|
2014-02-15 01:37:32 +00:00
|
|
|
// Parent method
|
2016-08-22 21:44:59 +00:00
|
|
|
ve.ui.MWTemplatePlaceholderPage.super.prototype.setOutlineItem.apply( this, arguments );
|
2014-02-15 01:37:32 +00:00
|
|
|
|
|
|
|
if ( this.outlineItem ) {
|
|
|
|
this.outlineItem
|
2017-07-06 16:52:56 +00:00
|
|
|
.setIcon( 'puzzle' )
|
2014-02-15 01:37:32 +00:00
|
|
|
.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 () {
|
2017-03-29 15:53:17 +00:00
|
|
|
var part, name,
|
2014-04-30 21:32:38 +00:00
|
|
|
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() ) {
|
2018-01-17 13:38:10 +00:00
|
|
|
menu.chooseItem( menu.findSelectedItem() );
|
2014-04-30 21:32:38 +00:00
|
|
|
}
|
2018-01-18 17:39:23 +00:00
|
|
|
name = this.addTemplateInput.getMWTitle();
|
2017-03-29 15:53:17 +00:00
|
|
|
if ( !name ) {
|
|
|
|
// Invalid titles return null, so abort here.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
part = ve.dm.MWTemplateModel.newFromName( transclusion, name );
|
2014-02-05 19:11:41 +00:00
|
|
|
transclusion.replacePart( this.placeholder, part );
|
2013-12-02 20:10:55 +00:00
|
|
|
this.addTemplateInput.pushPending();
|
2017-04-12 16:34:42 +00:00
|
|
|
// abort pending lookups, also, so the menu can't appear after we've left the page
|
|
|
|
this.addTemplateInput.closeLookupMenu();
|
2013-12-02 20:10:55 +00:00
|
|
|
this.addTemplateButton.setDisabled( true );
|
|
|
|
this.removeButton.setDisabled( true );
|
|
|
|
};
|
|
|
|
|
2014-10-30 16:24:04 +00:00
|
|
|
ve.ui.MWTemplatePlaceholderPage.prototype.onTemplateInputChange = function () {
|
2018-01-18 17:39:23 +00:00
|
|
|
this.addTemplateButton.setDisabled( this.addTemplateInput.getMWTitle() === null );
|
2013-12-02 20:10:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
ve.ui.MWTemplatePlaceholderPage.prototype.onRemoveButtonClick = function () {
|
|
|
|
this.placeholder.remove();
|
|
|
|
};
|