2013-12-02 20:10:55 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor user interface MWTemplatePlaceholderPage class.
|
|
|
|
*
|
2020-01-08 17:13:04 +00:00
|
|
|
* @copyright 2011-2020 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
|
2018-04-04 20:37:32 +00:00
|
|
|
* @cfg {jQuery} [$overlay] Overlay to render dropdowns in
|
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,
|
2018-05-04 13:30:10 +00:00
|
|
|
showDescriptions: true,
|
|
|
|
api: ve.init.target.getContentApi()
|
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
|
|
|
|
2019-05-17 11:15:07 +00:00
|
|
|
this.addTemplateInput.getLookupMenu().connect( this, {
|
|
|
|
choose: 'onAddTemplate'
|
|
|
|
} );
|
|
|
|
|
2020-04-03 04:02:55 +00:00
|
|
|
this.addTemplateInput.$input.attr( 'aria-label', ve.msg( 'visualeditor-dialog-transclusion-add-template' ) );
|
|
|
|
|
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,
|
2018-07-03 18:13:28 +00:00
|
|
|
this.addTemplateButton,
|
|
|
|
{ align: 'top' }
|
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' ) );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-08-24 13:22:00 +00:00
|
|
|
ve.ui.MWTemplatePlaceholderPage.prototype.focus = function () {
|
|
|
|
// Parent method
|
|
|
|
ve.ui.MWTemplatePlaceholderPage.super.prototype.focus.apply( this, arguments );
|
|
|
|
|
|
|
|
// HACK: Set the width of the lookupMenu to the width of the input
|
|
|
|
// TODO: This should be handled upstream in OOUI
|
|
|
|
this.addTemplateInput.lookupMenu.width = this.addTemplateInput.$input[ 0 ].clientWidth;
|
|
|
|
};
|
|
|
|
|
2013-12-02 20:10:55 +00:00
|
|
|
ve.ui.MWTemplatePlaceholderPage.prototype.onAddTemplate = function () {
|
2021-01-21 12:17:03 +00:00
|
|
|
var part, name, event, editCountBucket,
|
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;
|
|
|
|
}
|
2020-12-11 15:09:45 +00:00
|
|
|
|
|
|
|
// TODO tracking will only be implemented temporarily to answer questions on
|
|
|
|
// template usage for the Technical Wishes topic area see T258917
|
2021-01-21 12:17:03 +00:00
|
|
|
event = {
|
2020-12-11 15:09:45 +00:00
|
|
|
action: 'add-template',
|
|
|
|
// eslint-disable-next-line camelcase
|
|
|
|
template_names: [ name.getPrefixedText() ]
|
2021-01-21 12:17:03 +00:00
|
|
|
};
|
|
|
|
editCountBucket = mw.config.get( 'wgUserEditCountBucket' );
|
|
|
|
if ( editCountBucket !== null ) {
|
|
|
|
// eslint-disable-next-line camelcase
|
|
|
|
event.user_edit_count_bucket = editCountBucket;
|
|
|
|
}
|
|
|
|
mw.track( 'event.VisualEditorTemplateDialogUse', event );
|
2020-12-11 15:09:45 +00:00
|
|
|
|
2017-03-29 15:53:17 +00:00
|
|
|
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();
|
|
|
|
};
|